@ohhwells/bridge 0.1.89 → 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
@@ -8046,6 +8046,9 @@ var LINK_PICKER_EXCLUDED_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
8046
8046
  function isChromeSection(el) {
8047
8047
  return el.matches("header, nav, footer, aside");
8048
8048
  }
8049
+ function isSchedulingSection(el) {
8050
+ return (el.dataset.ohwSection ?? "").startsWith("scheduling-");
8051
+ }
8049
8052
  function titleCaseSectionId(id) {
8050
8053
  return id.split("-").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8051
8054
  }
@@ -8081,12 +8084,50 @@ function isRemovedSection(el) {
8081
8084
  }
8082
8085
  function topLevelSections() {
8083
8086
  return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8084
- (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)
8085
8088
  );
8086
8089
  }
8087
8090
  function instanceIdOf(el) {
8088
8091
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8089
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
+ }
8090
8131
  function findByInstanceId(instanceId) {
8091
8132
  const escapedId = CSS.escape(instanceId);
8092
8133
  return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
@@ -8292,6 +8333,12 @@ function useLiveSectionRect(sectionId) {
8292
8333
  return rect;
8293
8334
  }
8294
8335
  function computeSectionBoundaryFlags(instanceId) {
8336
+ if (instanceId.startsWith("scheduling-")) {
8337
+ return {
8338
+ isFirst: !canMoveSchedulingSection(instanceId, "up"),
8339
+ isLast: !canMoveSchedulingSection(instanceId, "down")
8340
+ };
8341
+ }
8295
8342
  const topLevel = topLevelSections();
8296
8343
  const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8297
8344
  if (index === -1) return { isFirst: true, isLast: true };
@@ -14887,6 +14934,22 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
14887
14934
  tracker.textContent = JSON.stringify(updated);
14888
14935
  return tracker.textContent ?? "[]";
14889
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
+ }
14890
14953
  function schedulingSectionId(insertAfter) {
14891
14954
  return `scheduling-${insertAfter}`;
14892
14955
  }
@@ -20257,6 +20320,15 @@ function OhhwellsBridge() {
20257
20320
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20258
20321
  const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
20259
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
+ }
20260
20332
  const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
20261
20333
  if (!entries) return;
20262
20334
  const orderJson = JSON.stringify(entries);
@@ -20276,6 +20348,28 @@ function OhhwellsBridge() {
20276
20348
  if (e.data?.type !== "ow:delete-section") return;
20277
20349
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20278
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
+ }
20279
20373
  const currentEntries = getPageSectionOrderEntries(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
20280
20374
  const entries = deleteSectionInstance(instanceId, window.location.pathname, currentEntries);
20281
20375
  if (!entries) return;
@@ -21236,7 +21330,7 @@ function OhhwellsBridge() {
21236
21330
  postToParent2({
21237
21331
  type: "ow:ready",
21238
21332
  version: "1",
21239
- bridgeVersion: "0.1.88",
21333
+ bridgeVersion: "0.1.89",
21240
21334
  path: pathname,
21241
21335
  nodes: collectEditableNodes(editContentRef.current),
21242
21336
  sections