@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.cjs CHANGED
@@ -1949,6 +1949,7 @@ function findTemplateSection(id) {
1949
1949
  return null;
1950
1950
  }
1951
1951
  function findPlacementAnchor(id, exclude) {
1952
+ if (CHROME_SECTION_IDS.has(id)) return null;
1952
1953
  for (const el of document.querySelectorAll(`[data-ohw-section="${CSS.escape(id)}"]`)) {
1953
1954
  if (el === exclude) continue;
1954
1955
  if (el.parentElement?.closest("[data-ohw-section]")) continue;
@@ -8118,6 +8119,9 @@ var LINK_PICKER_EXCLUDED_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
8118
8119
  function isChromeSection(el) {
8119
8120
  return el.matches("header, nav, footer, aside");
8120
8121
  }
8122
+ function isSchedulingSection(el) {
8123
+ return (el.dataset.ohwSection ?? "").startsWith("scheduling-");
8124
+ }
8121
8125
  function titleCaseSectionId(id) {
8122
8126
  return id.split("-").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8123
8127
  }
@@ -8153,12 +8157,50 @@ function isRemovedSection(el) {
8153
8157
  }
8154
8158
  function topLevelSections() {
8155
8159
  return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8156
- (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)
8157
8161
  );
8158
8162
  }
8159
8163
  function instanceIdOf(el) {
8160
8164
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8161
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
+ }
8162
8204
  function findByInstanceId(instanceId) {
8163
8205
  const escapedId = CSS.escape(instanceId);
8164
8206
  return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
@@ -8364,6 +8406,12 @@ function useLiveSectionRect(sectionId) {
8364
8406
  return rect;
8365
8407
  }
8366
8408
  function computeSectionBoundaryFlags(instanceId) {
8409
+ if (instanceId.startsWith("scheduling-")) {
8410
+ return {
8411
+ isFirst: !canMoveSchedulingSection(instanceId, "up"),
8412
+ isLast: !canMoveSchedulingSection(instanceId, "down")
8413
+ };
8414
+ }
8367
8415
  const topLevel = topLevelSections();
8368
8416
  const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8369
8417
  if (index === -1) return { isFirst: true, isLast: true };
@@ -14953,6 +15001,22 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
14953
15001
  tracker.textContent = JSON.stringify(updated);
14954
15002
  return tracker.textContent ?? "[]";
14955
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
+ }
14956
15020
  function schedulingSectionId(insertAfter) {
14957
15021
  return `scheduling-${insertAfter}`;
14958
15022
  }
@@ -20323,6 +20387,15 @@ function OhhwellsBridge() {
20323
20387
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20324
20388
  const direction = e.data.direction === "up" || e.data.direction === "down" ? e.data.direction : null;
20325
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
+ }
20326
20399
  const entries = moveSectionInstance(instanceId, direction, window.location.pathname);
20327
20400
  if (!entries) return;
20328
20401
  const orderJson = JSON.stringify(entries);
@@ -20342,6 +20415,28 @@ function OhhwellsBridge() {
20342
20415
  if (e.data?.type !== "ow:delete-section") return;
20343
20416
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20344
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
+ }
20345
20440
  const currentEntries = getPageSectionOrderEntries(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
20346
20441
  const entries = deleteSectionInstance(instanceId, window.location.pathname, currentEntries);
20347
20442
  if (!entries) return;
@@ -21302,7 +21397,7 @@ function OhhwellsBridge() {
21302
21397
  postToParent2({
21303
21398
  type: "ow:ready",
21304
21399
  version: "1",
21305
- bridgeVersion: "0.1.87",
21400
+ bridgeVersion: "0.1.89",
21306
21401
  path: pathname,
21307
21402
  nodes: collectEditableNodes(editContentRef.current),
21308
21403
  sections