@ohhwells/bridge 0.1.88 → 0.1.90

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
@@ -1876,6 +1876,7 @@ function findTemplateSection(id) {
1876
1876
  return null;
1877
1877
  }
1878
1878
  function findPlacementAnchor(id, exclude) {
1879
+ if (CHROME_SECTION_IDS.has(id)) return null;
1879
1880
  for (const el of document.querySelectorAll(`[data-ohw-section="${CSS.escape(id)}"]`)) {
1880
1881
  if (el === exclude) continue;
1881
1882
  if (el.parentElement?.closest("[data-ohw-section]")) continue;
@@ -8045,6 +8046,9 @@ var LINK_PICKER_EXCLUDED_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
8045
8046
  function isChromeSection(el) {
8046
8047
  return el.matches("header, nav, footer, aside");
8047
8048
  }
8049
+ function isSchedulingSection(el) {
8050
+ return (el.dataset.ohwSection ?? "").startsWith("scheduling-");
8051
+ }
8048
8052
  function titleCaseSectionId(id) {
8049
8053
  return id.split("-").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8050
8054
  }
@@ -8080,12 +8084,50 @@ function isRemovedSection(el) {
8080
8084
  }
8081
8085
  function topLevelSections() {
8082
8086
  return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8083
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isRemovedSection(el)
8087
+ (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isSchedulingSection(el) && !isRemovedSection(el)
8084
8088
  );
8085
8089
  }
8086
8090
  function instanceIdOf(el) {
8087
8091
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8088
8092
  }
8093
+ function moveableSequence() {
8094
+ const scheduling = Array.from(
8095
+ document.querySelectorAll('[data-ohw-section-container="scheduling"]')
8096
+ );
8097
+ return [...topLevelSections(), ...scheduling].sort((a, b) => {
8098
+ const pos = a.compareDocumentPosition(b);
8099
+ if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
8100
+ if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;
8101
+ return 0;
8102
+ });
8103
+ }
8104
+ function planSchedulingMoveTarget(instanceId, direction) {
8105
+ const inner = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
8106
+ const wrapper = inner?.closest('[data-ohw-section-container="scheduling"]');
8107
+ if (!wrapper) return null;
8108
+ const sequence = moveableSequence();
8109
+ const index = sequence.indexOf(wrapper);
8110
+ if (index === -1) return null;
8111
+ const siblingIndex = direction === "up" ? index - 1 : index + 1;
8112
+ if (siblingIndex < 0 || siblingIndex >= sequence.length) return null;
8113
+ const others = sequence.filter((_, i) => i !== index);
8114
+ const clamped = Math.max(0, Math.min(siblingIndex, others.length));
8115
+ if (clamped === 0) return null;
8116
+ const newPrev = others[clamped - 1];
8117
+ if (newPrev.hasAttribute("data-ohw-section-container")) return null;
8118
+ const newAnchorId = instanceIdOf(newPrev);
8119
+ if (!newAnchorId) return null;
8120
+ return { wrapper, others, clamped, newAnchorId };
8121
+ }
8122
+ function canMoveSchedulingSection(instanceId, direction) {
8123
+ return planSchedulingMoveTarget(instanceId, direction) !== null;
8124
+ }
8125
+ function planSchedulingMove(instanceId, direction) {
8126
+ const plan = planSchedulingMoveTarget(instanceId, direction);
8127
+ if (!plan) return null;
8128
+ plan.others[plan.clamped - 1].after(plan.wrapper);
8129
+ return { newAnchorId: plan.newAnchorId };
8130
+ }
8089
8131
  function findByInstanceId(instanceId) {
8090
8132
  const escapedId = CSS.escape(instanceId);
8091
8133
  return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
@@ -8291,6 +8333,12 @@ function useLiveSectionRect(sectionId) {
8291
8333
  return rect;
8292
8334
  }
8293
8335
  function computeSectionBoundaryFlags(instanceId) {
8336
+ if (instanceId.startsWith("scheduling-")) {
8337
+ return {
8338
+ isFirst: !canMoveSchedulingSection(instanceId, "up"),
8339
+ isLast: !canMoveSchedulingSection(instanceId, "down")
8340
+ };
8341
+ }
8294
8342
  const topLevel = topLevelSections();
8295
8343
  const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8296
8344
  if (index === -1) return { isFirst: true, isLast: true };
@@ -14886,6 +14934,22 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
14886
14934
  tracker.textContent = JSON.stringify(updated);
14887
14935
  return tracker.textContent ?? "[]";
14888
14936
  }
14937
+ function updateSchedulingInsertAfter(oldInsertAfter, newInsertAfter) {
14938
+ const tracker = getSectionsTracker();
14939
+ let sections = [];
14940
+ try {
14941
+ sections = JSON.parse(tracker.textContent || "[]");
14942
+ } catch {
14943
+ }
14944
+ const currentPath = window.location.pathname;
14945
+ const updated = sections.map((s) => {
14946
+ if (s.type !== "scheduling" || s.insertAfter !== oldInsertAfter) return s;
14947
+ if (s.pagePath && s.pagePath !== currentPath) return s;
14948
+ return { ...s, insertAfter: newInsertAfter };
14949
+ });
14950
+ tracker.textContent = JSON.stringify(updated);
14951
+ return tracker.textContent ?? "[]";
14952
+ }
14889
14953
  function schedulingSectionId(insertAfter) {
14890
14954
  return `scheduling-${insertAfter}`;
14891
14955
  }
@@ -20256,6 +20320,15 @@ function OhhwellsBridge() {
20256
20320
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20257
20321
  const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
20258
20322
  if (!instanceId || !direction) return;
20323
+ if (instanceId.startsWith("scheduling-")) {
20324
+ const result = planSchedulingMove(instanceId, direction);
20325
+ if (!result) return;
20326
+ const oldInsertAfter = instanceId.slice("scheduling-".length);
20327
+ const sectionsJson = updateSchedulingInsertAfter(oldInsertAfter, result.newAnchorId);
20328
+ postToParentRef.current({ type: "ow:change", nodes: [{ key: "__ohw_sections", text: sectionsJson }] });
20329
+ window.dispatchEvent(new Event("resize"));
20330
+ return;
20331
+ }
20259
20332
  const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
20260
20333
  if (!entries) return;
20261
20334
  const orderJson = JSON.stringify(entries);
@@ -20275,6 +20348,28 @@ function OhhwellsBridge() {
20275
20348
  if (e.data?.type !== "ow:delete-section") return;
20276
20349
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20277
20350
  if (!instanceId) return;
20351
+ if (instanceId.startsWith("scheduling-")) {
20352
+ const insertAfter = instanceId.slice("scheduling-".length);
20353
+ const inner = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
20354
+ inner?.closest('[data-ohw-section-container="scheduling"]')?.remove();
20355
+ const tracker = getSectionsTracker();
20356
+ let sections = [];
20357
+ try {
20358
+ sections = JSON.parse(tracker.textContent || "[]");
20359
+ } catch {
20360
+ }
20361
+ const currentPath = window.location.pathname;
20362
+ const updated = sections.filter(
20363
+ (s) => !(s.type === "scheduling" && s.insertAfter === insertAfter && (!s.pagePath || s.pagePath === currentPath))
20364
+ );
20365
+ tracker.textContent = JSON.stringify(updated);
20366
+ postToParentRef.current({ type: "ow:change", nodes: [{ key: "__ohw_sections", text: tracker.textContent }] });
20367
+ aiSectionApiRef.current?.clear();
20368
+ window.dispatchEvent(new Event("resize"));
20369
+ const height = document.body.scrollHeight;
20370
+ if (height > 50) postToParentRef.current({ type: "ow:height", height });
20371
+ return;
20372
+ }
20278
20373
  const currentEntries = getPageSectionOrderEntries(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
20279
20374
  const entries = deleteSectionInstance(instanceId, window.location.pathname, currentEntries);
20280
20375
  if (!entries) return;
@@ -21235,7 +21330,7 @@ function OhhwellsBridge() {
21235
21330
  postToParent2({
21236
21331
  type: "ow:ready",
21237
21332
  version: "1",
21238
- bridgeVersion: "0.1.87",
21333
+ bridgeVersion: "0.1.89",
21239
21334
  path: pathname,
21240
21335
  nodes: collectEditableNodes(editContentRef.current),
21241
21336
  sections