@ohhwells/bridge 0.1.161 → 0.1.162

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
@@ -17353,7 +17353,7 @@ function apiBase() {
17353
17353
  function bridgeVersion() {
17354
17354
  try {
17355
17355
  if (true) {
17356
- return "0.1.161";
17356
+ return "0.1.162";
17357
17357
  }
17358
17358
  } catch {
17359
17359
  }
@@ -17367,7 +17367,7 @@ function stampBridgeVersionOnDocument() {
17367
17367
  return;
17368
17368
  }
17369
17369
  try {
17370
- const v = true ? "0.1.161" : "";
17370
+ const v = true ? "0.1.162" : "";
17371
17371
  if (v) {
17372
17372
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17373
17373
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -19152,7 +19152,7 @@ function LinkInput({ value, onCommit }) {
19152
19152
  setDraft(value);
19153
19153
  setInvalid(false);
19154
19154
  }, [value]);
19155
- const commit = () => {
19155
+ const commit2 = () => {
19156
19156
  const next = draft.trim();
19157
19157
  if (next === value) return setInvalid(false);
19158
19158
  if (next && !HTTP_URL_RE.test(next)) return setInvalid(true);
@@ -19197,7 +19197,7 @@ function LinkInput({ value, onCommit }) {
19197
19197
  inputMode: "url",
19198
19198
  value: draft,
19199
19199
  onChange: (e) => setDraft(e.target.value),
19200
- onBlur: commit,
19200
+ onBlur: commit2,
19201
19201
  onKeyDown: (e) => {
19202
19202
  if (e.key === "Enter") e.currentTarget.blur();
19203
19203
  if (e.key === "Escape") {
@@ -19247,7 +19247,7 @@ function MediaStripToolbar({
19247
19247
  const items = mediaStripItems(entry.tree);
19248
19248
  const itemCount = items.length;
19249
19249
  const currentAlt = items[index]?.alt ?? "";
19250
- const currentHref = items[index]?.href ?? "";
19250
+ const currentHref2 = items[index]?.href ?? "";
19251
19251
  const currentTarget = items[index]?.linkTarget === "same-tab" ? "same-tab" : "new-tab";
19252
19252
  const slots = findMediaStripSlots(entry.tree);
19253
19253
  const variant = slots?.variant === "reel" ? "reel" : "logos";
@@ -19303,10 +19303,10 @@ function MediaStripToolbar({
19303
19303
  /* @__PURE__ */ jsx20(Pill, { label: "+", onClick: () => onResize(8) })
19304
19304
  ] }),
19305
19305
  /* @__PURE__ */ jsx20("div", { style: { display: "flex", justifyContent: "center", width: "100%" }, children: /* @__PURE__ */ jsx20(AltInput, { value: currentAlt, onCommit: onSetAlt }) }),
19306
- /* @__PURE__ */ jsx20("div", { style: { display: "flex", justifyContent: "center", width: "100%" }, children: /* @__PURE__ */ jsx20(LinkInput, { value: currentHref, onCommit: (href) => onSetLink(href, currentTarget) }) }),
19307
- currentHref && /* @__PURE__ */ jsxs11("div", { style: rowStyle, children: [
19308
- /* @__PURE__ */ jsx20(Pill, { label: "New tab", active: currentTarget === "new-tab", onClick: () => onSetLink(currentHref, "new-tab") }),
19309
- /* @__PURE__ */ jsx20(Pill, { label: "Same tab", active: currentTarget === "same-tab", onClick: () => onSetLink(currentHref, "same-tab") })
19306
+ /* @__PURE__ */ jsx20("div", { style: { display: "flex", justifyContent: "center", width: "100%" }, children: /* @__PURE__ */ jsx20(LinkInput, { value: currentHref2, onCommit: (href) => onSetLink(href, currentTarget) }) }),
19307
+ currentHref2 && /* @__PURE__ */ jsxs11("div", { style: rowStyle, children: [
19308
+ /* @__PURE__ */ jsx20(Pill, { label: "New tab", active: currentTarget === "new-tab", onClick: () => onSetLink(currentHref2, "new-tab") }),
19309
+ /* @__PURE__ */ jsx20(Pill, { label: "Same tab", active: currentTarget === "same-tab", onClick: () => onSetLink(currentHref2, "same-tab") })
19310
19310
  ] }),
19311
19311
  /* @__PURE__ */ jsxs11("div", { style: rowStyle, children: [
19312
19312
  /* @__PURE__ */ jsx20(Pill, { label: "Change Image", onClick: onChangeImage }),
@@ -20221,7 +20221,7 @@ function VideoUrlInput({ value, onCommit }) {
20221
20221
  setDraft(value ? watchUrl(value) : "");
20222
20222
  setInvalid(false);
20223
20223
  }, [value]);
20224
- const commit = () => {
20224
+ const commit2 = () => {
20225
20225
  const next = draft.trim();
20226
20226
  if (!next) {
20227
20227
  setInvalid(false);
@@ -20281,7 +20281,7 @@ function VideoUrlInput({ value, onCommit }) {
20281
20281
  inputMode: "url",
20282
20282
  value: draft,
20283
20283
  onChange: (e) => handleChange(e.target.value),
20284
- onBlur: commit,
20284
+ onBlur: commit2,
20285
20285
  onKeyDown: (e) => {
20286
20286
  if (e.key === "Enter") e.currentTarget.blur();
20287
20287
  if (e.key === "Escape") {
@@ -24093,6 +24093,102 @@ function deleteSelectedNavFooterItem(deps) {
24093
24093
  return false;
24094
24094
  }
24095
24095
 
24096
+ // src/lib/nav-page-sync.ts
24097
+ function labelKeyFor(hrefKey) {
24098
+ return hrefKey.replace(/-href$/, "-label");
24099
+ }
24100
+ function isPageLinkKey(key) {
24101
+ return isNavbarHrefKey(key) || isFooterHrefKey(key);
24102
+ }
24103
+ function currentHref(key, anchor, content) {
24104
+ const stored = content[key];
24105
+ if (typeof stored === "string" && stored.length > 0) return stored;
24106
+ return anchor.getAttribute("href") ?? "";
24107
+ }
24108
+ function normalizePath2(value) {
24109
+ if (value.length > 1 && value.endsWith("/")) return value.slice(0, -1);
24110
+ return value;
24111
+ }
24112
+ function pointsAt(href, path) {
24113
+ const normalized = normalizePath2(href);
24114
+ const target = normalizePath2(path);
24115
+ if (normalized === target) return true;
24116
+ return (normalized.startsWith(`${target}#`) || normalized.startsWith(`${target}?`)) && target !== "/";
24117
+ }
24118
+ function retargetHref(href, oldPath, newPath) {
24119
+ const normalized = normalizePath2(href);
24120
+ const target = normalizePath2(oldPath);
24121
+ if (normalized === target) return newPath;
24122
+ return `${newPath}${normalized.slice(target.length)}`;
24123
+ }
24124
+ function setLabelText(key, text) {
24125
+ document.querySelectorAll(`[data-ohw-key="${CSS.escape(key)}"]`).forEach((el) => {
24126
+ el.textContent = text;
24127
+ });
24128
+ }
24129
+ function commit(delta, deps) {
24130
+ if (Object.keys(delta).length === 0) return;
24131
+ deps.setEditContent({ ...deps.getEditContent(), ...delta });
24132
+ deps.postToParent({
24133
+ type: "ow:change",
24134
+ nodes: Object.entries(delta).map(([key, text]) => ({ key, text }))
24135
+ });
24136
+ }
24137
+ function navLinksTo(path, content) {
24138
+ return Array.from(document.querySelectorAll("[data-ohw-href-key]")).filter((anchor) => {
24139
+ const key = anchor.getAttribute("data-ohw-href-key");
24140
+ return isNavbarHrefKey(key) && pointsAt(currentHref(key, anchor, content), path);
24141
+ }).map((anchor) => anchor.getAttribute("data-ohw-href-key"));
24142
+ }
24143
+ function addNavLinkForPage(page, deps) {
24144
+ const content = deps.getEditContent();
24145
+ if (navLinksTo(page.path, content).length > 0) return false;
24146
+ const roots = listNavbarRootItems();
24147
+ const afterAnchor = roots[roots.length - 1] ?? null;
24148
+ let inserted;
24149
+ try {
24150
+ inserted = insertNavbarItem(page.path, page.title, afterAnchor);
24151
+ } catch {
24152
+ return false;
24153
+ }
24154
+ const { hrefKey, labelKey, index } = inserted;
24155
+ deps.applyLinkByKey(hrefKey, page.path);
24156
+ setLabelText(labelKey, page.title);
24157
+ commit(
24158
+ {
24159
+ [hrefKey]: page.path,
24160
+ [labelKey]: page.title,
24161
+ [NAV_COUNT_KEY]: String(index + 1),
24162
+ [NAV_ORDER_KEY]: getNavbarOrderJson()
24163
+ },
24164
+ deps
24165
+ );
24166
+ return true;
24167
+ }
24168
+ function retargetPageLinks(change, deps) {
24169
+ const { oldPath, newPath, oldTitle, newTitle } = change;
24170
+ if (!oldPath || !newPath || normalizePath2(oldPath) === normalizePath2(newPath)) return 0;
24171
+ const content = deps.getEditContent();
24172
+ const delta = {};
24173
+ for (const anchor of Array.from(document.querySelectorAll("[data-ohw-href-key]"))) {
24174
+ const hrefKey = anchor.getAttribute("data-ohw-href-key");
24175
+ if (!isPageLinkKey(hrefKey)) continue;
24176
+ const href = currentHref(hrefKey, anchor, content);
24177
+ if (!pointsAt(href, oldPath)) continue;
24178
+ const nextHref = retargetHref(href, oldPath, newPath);
24179
+ deps.applyLinkByKey(hrefKey, nextHref);
24180
+ delta[hrefKey] = nextHref;
24181
+ if (!oldTitle || !newTitle) continue;
24182
+ const labelKey = labelKeyFor(hrefKey);
24183
+ const label = content[labelKey] ?? anchor.querySelector('[data-ohw-editable="text"]')?.textContent ?? "";
24184
+ if (label.trim() !== oldTitle) continue;
24185
+ setLabelText(labelKey, newTitle);
24186
+ delta[labelKey] = newTitle;
24187
+ }
24188
+ commit(delta, deps);
24189
+ return Object.keys(delta).filter((key) => key.endsWith("-href")).length;
24190
+ }
24191
+
24096
24192
  // src/ui/navbar-container-chrome.tsx
24097
24193
  import { Plus as Plus4 } from "lucide-react";
24098
24194
  import { jsx as jsx37 } from "react/jsx-runtime";
@@ -26408,6 +26504,43 @@ function OhhwellsBridge() {
26408
26504
  if (!useFixtures) postToParent2({ type: "ow:request-site-pages" });
26409
26505
  return () => window.removeEventListener("message", onSitePages);
26410
26506
  }, [isEditMode, postToParent2]);
26507
+ useEffect19(() => {
26508
+ if (!isEditMode) return;
26509
+ const deps = {
26510
+ getEditContent: () => editContentRef.current,
26511
+ setEditContent: (next) => {
26512
+ editContentRef.current = next;
26513
+ },
26514
+ applyLinkByKey,
26515
+ postToParent: postToParent2
26516
+ };
26517
+ const onPageMessage = (e) => {
26518
+ if (e.data?.type === "ow:page-created") {
26519
+ const { path, title } = e.data;
26520
+ if (typeof path !== "string" || !path) return;
26521
+ if (addNavLinkForPage({ path, title: typeof title === "string" && title ? title : path }, deps)) {
26522
+ enforceLinkHrefs();
26523
+ }
26524
+ return;
26525
+ }
26526
+ if (e.data?.type === "ow:page-renamed") {
26527
+ const { oldPath, newPath, oldTitle, newTitle } = e.data;
26528
+ if (typeof oldPath !== "string" || typeof newPath !== "string") return;
26529
+ const moved = retargetPageLinks(
26530
+ {
26531
+ oldPath,
26532
+ newPath,
26533
+ oldTitle: typeof oldTitle === "string" ? oldTitle : void 0,
26534
+ newTitle: typeof newTitle === "string" ? newTitle : void 0
26535
+ },
26536
+ deps
26537
+ );
26538
+ if (moved > 0) enforceLinkHrefs();
26539
+ }
26540
+ };
26541
+ window.addEventListener("message", onPageMessage);
26542
+ return () => window.removeEventListener("message", onPageMessage);
26543
+ }, [isEditMode, postToParent2]);
26411
26544
  useEffect19(() => {
26412
26545
  if (!isEditMode || shouldUseDevFixtures()) return;
26413
26546
  void loadAllSectionsManifest().then((manifest) => {
@@ -32257,7 +32390,7 @@ function OhhwellsBridge() {
32257
32390
  postToParent2({
32258
32391
  type: "ow:ready",
32259
32392
  version: "1",
32260
- bridgeVersion: "0.1.161",
32393
+ bridgeVersion: "0.1.162",
32261
32394
  path: pathname,
32262
32395
  nodes: collectEditableNodes(editContentRef.current),
32263
32396
  sections