@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.cjs CHANGED
@@ -8119,6 +8119,9 @@ 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
+ }
8122
8125
  function titleCaseSectionId(id) {
8123
8126
  return id.split("-").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8124
8127
  }
@@ -8154,12 +8157,50 @@ function isRemovedSection(el) {
8154
8157
  }
8155
8158
  function topLevelSections() {
8156
8159
  return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8157
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isRemovedSection(el)
8160
+ (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isSchedulingSection(el) && !isRemovedSection(el)
8158
8161
  );
8159
8162
  }
8160
8163
  function instanceIdOf(el) {
8161
8164
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8162
8165
  }
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
+ }
8163
8204
  function findByInstanceId(instanceId) {
8164
8205
  const escapedId = CSS.escape(instanceId);
8165
8206
  return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
@@ -8365,6 +8406,12 @@ function useLiveSectionRect(sectionId) {
8365
8406
  return rect;
8366
8407
  }
8367
8408
  function computeSectionBoundaryFlags(instanceId) {
8409
+ if (instanceId.startsWith("scheduling-")) {
8410
+ return {
8411
+ isFirst: !canMoveSchedulingSection(instanceId, "up"),
8412
+ isLast: !canMoveSchedulingSection(instanceId, "down")
8413
+ };
8414
+ }
8368
8415
  const topLevel = topLevelSections();
8369
8416
  const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8370
8417
  if (index === -1) return { isFirst: true, isLast: true };
@@ -14954,6 +15001,22 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
14954
15001
  tracker.textContent = JSON.stringify(updated);
14955
15002
  return tracker.textContent ?? "[]";
14956
15003
  }
15004
+ function updateSchedulingInsertAfter(oldInsertAfter, newInsertAfter) {
15005
+ const tracker = getSectionsTracker();
15006
+ let sections = [];
15007
+ try {
15008
+ sections = JSON.parse(tracker.textContent || "[]");
15009
+ } catch {
15010
+ }
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 ?? "[]";
15019
+ }
14957
15020
  function schedulingSectionId(insertAfter) {
14958
15021
  return `scheduling-${insertAfter}`;
14959
15022
  }
@@ -20324,6 +20387,15 @@ function OhhwellsBridge() {
20324
20387
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20325
20388
  const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
20326
20389
  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
+ }
20327
20399
  const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
20328
20400
  if (!entries) return;
20329
20401
  const orderJson = JSON.stringify(entries);
@@ -20343,6 +20415,28 @@ function OhhwellsBridge() {
20343
20415
  if (e.data?.type !== "ow:delete-section") return;
20344
20416
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20345
20417
  if (!instanceId) return;
20418
+ if (instanceId.startsWith("scheduling-")) {
20419
+ 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();
20422
+ const tracker = getSectionsTracker();
20423
+ let sections = [];
20424
+ try {
20425
+ sections = JSON.parse(tracker.textContent || "[]");
20426
+ } catch {
20427
+ }
20428
+ const currentPath = window.location.pathname;
20429
+ const updated = sections.filter(
20430
+ (s) => !(s.type === "scheduling" && s.insertAfter === insertAfter && (!s.pagePath || s.pagePath === currentPath))
20431
+ );
20432
+ tracker.textContent = JSON.stringify(updated);
20433
+ postToParentRef.current({ type: "ow:change", nodes: [{ key: "__ohw_sections", text: tracker.textContent }] });
20434
+ aiSectionApiRef.current?.clear();
20435
+ window.dispatchEvent(new Event("resize"));
20436
+ const height = document.body.scrollHeight;
20437
+ if (height > 50) postToParentRef.current({ type: "ow:height", height });
20438
+ return;
20439
+ }
20346
20440
  const currentEntries = getPageSectionOrderEntries(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
20347
20441
  const entries = deleteSectionInstance(instanceId, window.location.pathname, currentEntries);
20348
20442
  if (!entries) return;
@@ -21303,7 +21397,7 @@ function OhhwellsBridge() {
21303
21397
  postToParent2({
21304
21398
  type: "ow:ready",
21305
21399
  version: "1",
21306
- bridgeVersion: "0.1.88",
21400
+ bridgeVersion: "0.1.89",
21307
21401
  path: pathname,
21308
21402
  nodes: collectEditableNodes(editContentRef.current),
21309
21403
  sections