@ohhwells/bridge 0.1.90 → 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
@@ -8119,9 +8119,6 @@ var LINK_PICKER_EXCLUDED_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
8119
8119
  function isChromeSection(el) {
8120
8120
  return el.matches("header, nav, footer, aside");
8121
8121
  }
8122
- function isSchedulingSection(el) {
8123
- return (el.dataset.ohwSection ?? "").startsWith("scheduling-");
8124
- }
8125
8122
  function titleCaseSectionId(id) {
8126
8123
  return id.split("-").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8127
8124
  }
@@ -8157,50 +8154,12 @@ function isRemovedSection(el) {
8157
8154
  }
8158
8155
  function topLevelSections() {
8159
8156
  return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8160
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isSchedulingSection(el) && !isRemovedSection(el)
8157
+ (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isRemovedSection(el)
8161
8158
  );
8162
8159
  }
8163
8160
  function instanceIdOf(el) {
8164
8161
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8165
8162
  }
8166
- function moveableSequence() {
8167
- const scheduling = Array.from(
8168
- document.querySelectorAll('[data-ohw-section-container="scheduling"]')
8169
- );
8170
- return [...topLevelSections(), ...scheduling].sort((a, b) => {
8171
- const pos = a.compareDocumentPosition(b);
8172
- if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
8173
- if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;
8174
- return 0;
8175
- });
8176
- }
8177
- function planSchedulingMoveTarget(instanceId, direction) {
8178
- const inner = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
8179
- const wrapper = inner?.closest('[data-ohw-section-container="scheduling"]');
8180
- if (!wrapper) return null;
8181
- const sequence = moveableSequence();
8182
- const index = sequence.indexOf(wrapper);
8183
- if (index === -1) return null;
8184
- const siblingIndex = direction === "up" ? index - 1 : index + 1;
8185
- if (siblingIndex < 0 || siblingIndex >= sequence.length) return null;
8186
- const others = sequence.filter((_, i) => i !== index);
8187
- const clamped = Math.max(0, Math.min(siblingIndex, others.length));
8188
- if (clamped === 0) return null;
8189
- const newPrev = others[clamped - 1];
8190
- if (newPrev.hasAttribute("data-ohw-section-container")) return null;
8191
- const newAnchorId = instanceIdOf(newPrev);
8192
- if (!newAnchorId) return null;
8193
- return { wrapper, others, clamped, newAnchorId };
8194
- }
8195
- function canMoveSchedulingSection(instanceId, direction) {
8196
- return planSchedulingMoveTarget(instanceId, direction) !== null;
8197
- }
8198
- function planSchedulingMove(instanceId, direction) {
8199
- const plan = planSchedulingMoveTarget(instanceId, direction);
8200
- if (!plan) return null;
8201
- plan.others[plan.clamped - 1].after(plan.wrapper);
8202
- return { newAnchorId: plan.newAnchorId };
8203
- }
8204
8163
  function findByInstanceId(instanceId) {
8205
8164
  const escapedId = CSS.escape(instanceId);
8206
8165
  return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
@@ -8406,12 +8365,6 @@ function useLiveSectionRect(sectionId) {
8406
8365
  return rect;
8407
8366
  }
8408
8367
  function computeSectionBoundaryFlags(instanceId) {
8409
- if (instanceId.startsWith("scheduling-")) {
8410
- return {
8411
- isFirst: !canMoveSchedulingSection(instanceId, "up"),
8412
- isLast: !canMoveSchedulingSection(instanceId, "down")
8413
- };
8414
- }
8415
8368
  const topLevel = topLevelSections();
8416
8369
  const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8417
8370
  if (index === -1) return { isFirst: true, isLast: true };
@@ -15001,21 +14954,14 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
15001
14954
  tracker.textContent = JSON.stringify(updated);
15002
14955
  return tracker.textContent ?? "[]";
15003
14956
  }
15004
- function updateSchedulingInsertAfter(oldInsertAfter, newInsertAfter) {
15005
- const tracker = getSectionsTracker();
15006
- let sections = [];
15007
- try {
15008
- sections = JSON.parse(tracker.textContent || "[]");
15009
- } catch {
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);
15010
14963
  }
15011
- const currentPath = window.location.pathname;
15012
- const updated = sections.map((s) => {
15013
- if (s.type !== "scheduling" || s.insertAfter !== oldInsertAfter) return s;
15014
- if (s.pagePath && s.pagePath !== currentPath) return s;
15015
- return { ...s, insertAfter: newInsertAfter };
15016
- });
15017
- tracker.textContent = JSON.stringify(updated);
15018
- return tracker.textContent ?? "[]";
14964
+ wrapper.remove();
15019
14965
  }
15020
14966
  function schedulingSectionId(insertAfter) {
15021
14967
  return `scheduling-${insertAfter}`;
@@ -15070,12 +15016,12 @@ function retryMissingSchedulingMounts(entries, notifyOnConnect = false) {
15070
15016
  if (!hasMissingSchedulingWidgets(entries)) return;
15071
15017
  mountSchedulingEntries(entries, notifyOnConnect);
15072
15018
  }
15073
- function initSectionsFromContent(content, removeExisting = false) {
15019
+ function initSectionsFromContent(content, removeExisting = false, currentPath = typeof window !== "undefined" ? window.location.pathname : "/") {
15074
15020
  const raw = content["__ohw_sections"];
15075
15021
  if (!raw) return;
15076
15022
  try {
15077
15023
  if (removeExisting) {
15078
- document.querySelectorAll('[data-ohw-section-container="scheduling"]').forEach((el) => el.remove());
15024
+ document.querySelectorAll('[data-ohw-section-container="scheduling"]').forEach((el) => unmountSchedulingWrapper(el));
15079
15025
  }
15080
15026
  const inEditor = typeof window !== "undefined" && window.self !== window.top;
15081
15027
  if (inEditor) getSectionsTracker().textContent = raw;
@@ -15083,8 +15029,16 @@ function initSectionsFromContent(content, removeExisting = false) {
15083
15029
  const preExisting = pageEntries.filter((e) => !isSchedulingWidgetMissing(e));
15084
15030
  const notifyForEntry = inEditor ? (e) => !e.scheduleId : false;
15085
15031
  mountSchedulingEntries(pageEntries, notifyForEntry);
15086
- requestAnimationFrame(() => retryMissingSchedulingMounts(pageEntries, notifyForEntry));
15087
- 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);
15088
15042
  for (const entry of preExisting) {
15089
15043
  window.postMessage({ type: "ow:schedule-config", insertAfter: entry.insertAfter, scheduleId: entry.scheduleId ?? null }, "*");
15090
15044
  }
@@ -15099,6 +15053,8 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15099
15053
  if (!mountPoint) return false;
15100
15054
  const container = document.createElement("div");
15101
15055
  container.dataset.ohwSectionContainer = "scheduling";
15056
+ container.dataset.ohwSection = sectionId;
15057
+ container.dataset.ohwInstance = sectionId;
15102
15058
  if (insertBefore) {
15103
15059
  const beforeAnchor = document.querySelector(`[data-ohw-section="${insertBefore}"]`);
15104
15060
  const beforePoint = beforeAnchor?.closest('[data-ohw-section-container="scheduling"]') ?? beforeAnchor;
@@ -15112,6 +15068,7 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15112
15068
  tail.insertAdjacentElement("afterend", container);
15113
15069
  }
15114
15070
  const root = (0, import_client2.createRoot)(container);
15071
+ schedulingRoots.set(container, root);
15115
15072
  (0, import_react_dom3.flushSync)(() => {
15116
15073
  root.render(
15117
15074
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
@@ -20387,15 +20344,6 @@ function OhhwellsBridge() {
20387
20344
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20388
20345
  const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
20389
20346
  if (!instanceId || !direction) return;
20390
- if (instanceId.startsWith("scheduling-")) {
20391
- const result = planSchedulingMove(instanceId, direction);
20392
- if (!result) return;
20393
- const oldInsertAfter = instanceId.slice("scheduling-".length);
20394
- const sectionsJson = updateSchedulingInsertAfter(oldInsertAfter, result.newAnchorId);
20395
- postToParentRef.current({ type: "ow:change", nodes: [{ key: "__ohw_sections", text: sectionsJson }] });
20396
- window.dispatchEvent(new Event("resize"));
20397
- return;
20398
- }
20399
20347
  const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
20400
20348
  if (!entries) return;
20401
20349
  const orderJson = JSON.stringify(entries);
@@ -20417,8 +20365,13 @@ function OhhwellsBridge() {
20417
20365
  if (!instanceId) return;
20418
20366
  if (instanceId.startsWith("scheduling-")) {
20419
20367
  const insertAfter = instanceId.slice("scheduling-".length);
20420
- const inner = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
20421
- inner?.closest('[data-ohw-section-container="scheduling"]')?.remove();
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
+ }
20422
20375
  const tracker = getSectionsTracker();
20423
20376
  let sections = [];
20424
20377
  try {
@@ -21397,7 +21350,7 @@ function OhhwellsBridge() {
21397
21350
  postToParent2({
21398
21351
  type: "ow:ready",
21399
21352
  version: "1",
21400
- bridgeVersion: "0.1.89",
21353
+ bridgeVersion: "0.1.90",
21401
21354
  path: pathname,
21402
21355
  nodes: collectEditableNodes(editContentRef.current),
21403
21356
  sections