@ohhwells/bridge 0.1.161 → 0.1.163

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ohhwells/bridge
2
2
 
3
- The OhhWells canvas editor bridge — a standalone npm package that enables inline text and image editing for any site deployed on the OhhWells platform.
3
+ The OhhWells canvas editor bridge — a standalone npm package that enables inline text and image editing for any site deployed on the OhhWells platform
4
4
 
5
5
  ## What it does
6
6
 
package/dist/index.cjs CHANGED
@@ -17467,7 +17467,7 @@ function apiBase() {
17467
17467
  function bridgeVersion() {
17468
17468
  try {
17469
17469
  if (true) {
17470
- return "0.1.161";
17470
+ return "0.1.163";
17471
17471
  }
17472
17472
  } catch {
17473
17473
  }
@@ -17481,7 +17481,7 @@ function stampBridgeVersionOnDocument() {
17481
17481
  return;
17482
17482
  }
17483
17483
  try {
17484
- const v = true ? "0.1.161" : "";
17484
+ const v = true ? "0.1.163" : "";
17485
17485
  if (v) {
17486
17486
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17487
17487
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -19266,7 +19266,7 @@ function LinkInput({ value, onCommit }) {
19266
19266
  setDraft(value);
19267
19267
  setInvalid(false);
19268
19268
  }, [value]);
19269
- const commit = () => {
19269
+ const commit2 = () => {
19270
19270
  const next = draft.trim();
19271
19271
  if (next === value) return setInvalid(false);
19272
19272
  if (next && !HTTP_URL_RE.test(next)) return setInvalid(true);
@@ -19311,7 +19311,7 @@ function LinkInput({ value, onCommit }) {
19311
19311
  inputMode: "url",
19312
19312
  value: draft,
19313
19313
  onChange: (e) => setDraft(e.target.value),
19314
- onBlur: commit,
19314
+ onBlur: commit2,
19315
19315
  onKeyDown: (e) => {
19316
19316
  if (e.key === "Enter") e.currentTarget.blur();
19317
19317
  if (e.key === "Escape") {
@@ -19361,7 +19361,7 @@ function MediaStripToolbar({
19361
19361
  const items = mediaStripItems(entry.tree);
19362
19362
  const itemCount = items.length;
19363
19363
  const currentAlt = items[index]?.alt ?? "";
19364
- const currentHref = items[index]?.href ?? "";
19364
+ const currentHref2 = items[index]?.href ?? "";
19365
19365
  const currentTarget = items[index]?.linkTarget === "same-tab" ? "same-tab" : "new-tab";
19366
19366
  const slots = findMediaStripSlots(entry.tree);
19367
19367
  const variant = slots?.variant === "reel" ? "reel" : "logos";
@@ -19417,10 +19417,10 @@ function MediaStripToolbar({
19417
19417
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Pill, { label: "+", onClick: () => onResize(8) })
19418
19418
  ] }),
19419
19419
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { style: { display: "flex", justifyContent: "center", width: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(AltInput, { value: currentAlt, onCommit: onSetAlt }) }),
19420
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { style: { display: "flex", justifyContent: "center", width: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(LinkInput, { value: currentHref, onCommit: (href) => onSetLink(href, currentTarget) }) }),
19421
- currentHref && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { style: rowStyle, children: [
19422
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Pill, { label: "New tab", active: currentTarget === "new-tab", onClick: () => onSetLink(currentHref, "new-tab") }),
19423
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Pill, { label: "Same tab", active: currentTarget === "same-tab", onClick: () => onSetLink(currentHref, "same-tab") })
19420
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { style: { display: "flex", justifyContent: "center", width: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(LinkInput, { value: currentHref2, onCommit: (href) => onSetLink(href, currentTarget) }) }),
19421
+ currentHref2 && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { style: rowStyle, children: [
19422
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Pill, { label: "New tab", active: currentTarget === "new-tab", onClick: () => onSetLink(currentHref2, "new-tab") }),
19423
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Pill, { label: "Same tab", active: currentTarget === "same-tab", onClick: () => onSetLink(currentHref2, "same-tab") })
19424
19424
  ] }),
19425
19425
  /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { style: rowStyle, children: [
19426
19426
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Pill, { label: "Change Image", onClick: onChangeImage }),
@@ -20335,7 +20335,7 @@ function VideoUrlInput({ value, onCommit }) {
20335
20335
  setDraft(value ? watchUrl(value) : "");
20336
20336
  setInvalid(false);
20337
20337
  }, [value]);
20338
- const commit = () => {
20338
+ const commit2 = () => {
20339
20339
  const next = draft.trim();
20340
20340
  if (!next) {
20341
20341
  setInvalid(false);
@@ -20395,7 +20395,7 @@ function VideoUrlInput({ value, onCommit }) {
20395
20395
  inputMode: "url",
20396
20396
  value: draft,
20397
20397
  onChange: (e) => handleChange(e.target.value),
20398
- onBlur: commit,
20398
+ onBlur: commit2,
20399
20399
  onKeyDown: (e) => {
20400
20400
  if (e.key === "Enter") e.currentTarget.blur();
20401
20401
  if (e.key === "Escape") {
@@ -24201,6 +24201,102 @@ function deleteSelectedNavFooterItem(deps) {
24201
24201
  return false;
24202
24202
  }
24203
24203
 
24204
+ // src/lib/nav-page-sync.ts
24205
+ function labelKeyFor(hrefKey) {
24206
+ return hrefKey.replace(/-href$/, "-label");
24207
+ }
24208
+ function isPageLinkKey(key) {
24209
+ return isNavbarHrefKey(key) || isFooterHrefKey(key);
24210
+ }
24211
+ function currentHref(key, anchor, content) {
24212
+ const stored = content[key];
24213
+ if (typeof stored === "string" && stored.length > 0) return stored;
24214
+ return anchor.getAttribute("href") ?? "";
24215
+ }
24216
+ function normalizePath2(value) {
24217
+ if (value.length > 1 && value.endsWith("/")) return value.slice(0, -1);
24218
+ return value;
24219
+ }
24220
+ function pointsAt(href, path) {
24221
+ const normalized = normalizePath2(href);
24222
+ const target = normalizePath2(path);
24223
+ if (normalized === target) return true;
24224
+ return (normalized.startsWith(`${target}#`) || normalized.startsWith(`${target}?`)) && target !== "/";
24225
+ }
24226
+ function retargetHref(href, oldPath, newPath) {
24227
+ const normalized = normalizePath2(href);
24228
+ const target = normalizePath2(oldPath);
24229
+ if (normalized === target) return newPath;
24230
+ return `${newPath}${normalized.slice(target.length)}`;
24231
+ }
24232
+ function setLabelText(key, text) {
24233
+ document.querySelectorAll(`[data-ohw-key="${CSS.escape(key)}"]`).forEach((el) => {
24234
+ el.textContent = text;
24235
+ });
24236
+ }
24237
+ function commit(delta, deps) {
24238
+ if (Object.keys(delta).length === 0) return;
24239
+ deps.setEditContent({ ...deps.getEditContent(), ...delta });
24240
+ deps.postToParent({
24241
+ type: "ow:change",
24242
+ nodes: Object.entries(delta).map(([key, text]) => ({ key, text }))
24243
+ });
24244
+ }
24245
+ function navLinksTo(path, content) {
24246
+ return Array.from(document.querySelectorAll("[data-ohw-href-key]")).filter((anchor) => {
24247
+ const key = anchor.getAttribute("data-ohw-href-key");
24248
+ return isNavbarHrefKey(key) && pointsAt(currentHref(key, anchor, content), path);
24249
+ }).map((anchor) => anchor.getAttribute("data-ohw-href-key"));
24250
+ }
24251
+ function addNavLinkForPage(page, deps) {
24252
+ const content = deps.getEditContent();
24253
+ if (navLinksTo(page.path, content).length > 0) return false;
24254
+ const roots = listNavbarRootItems();
24255
+ const afterAnchor = roots[roots.length - 1] ?? null;
24256
+ let inserted;
24257
+ try {
24258
+ inserted = insertNavbarItem(page.path, page.title, afterAnchor);
24259
+ } catch {
24260
+ return false;
24261
+ }
24262
+ const { hrefKey, labelKey, index } = inserted;
24263
+ deps.applyLinkByKey(hrefKey, page.path);
24264
+ setLabelText(labelKey, page.title);
24265
+ commit(
24266
+ {
24267
+ [hrefKey]: page.path,
24268
+ [labelKey]: page.title,
24269
+ [NAV_COUNT_KEY]: String(index + 1),
24270
+ [NAV_ORDER_KEY]: getNavbarOrderJson()
24271
+ },
24272
+ deps
24273
+ );
24274
+ return true;
24275
+ }
24276
+ function retargetPageLinks(change, deps) {
24277
+ const { oldPath, newPath, oldTitle, newTitle } = change;
24278
+ if (!oldPath || !newPath || normalizePath2(oldPath) === normalizePath2(newPath)) return 0;
24279
+ const content = deps.getEditContent();
24280
+ const delta = {};
24281
+ for (const anchor of Array.from(document.querySelectorAll("[data-ohw-href-key]"))) {
24282
+ const hrefKey = anchor.getAttribute("data-ohw-href-key");
24283
+ if (!isPageLinkKey(hrefKey)) continue;
24284
+ const href = currentHref(hrefKey, anchor, content);
24285
+ if (!pointsAt(href, oldPath)) continue;
24286
+ const nextHref = retargetHref(href, oldPath, newPath);
24287
+ deps.applyLinkByKey(hrefKey, nextHref);
24288
+ delta[hrefKey] = nextHref;
24289
+ if (!oldTitle || !newTitle) continue;
24290
+ const labelKey = labelKeyFor(hrefKey);
24291
+ const label = content[labelKey] ?? anchor.querySelector('[data-ohw-editable="text"]')?.textContent ?? "";
24292
+ if (label.trim() !== oldTitle) continue;
24293
+ setLabelText(labelKey, newTitle);
24294
+ delta[labelKey] = newTitle;
24295
+ }
24296
+ commit(delta, deps);
24297
+ return Object.keys(delta).filter((key) => key.endsWith("-href")).length;
24298
+ }
24299
+
24204
24300
  // src/ui/navbar-container-chrome.tsx
24205
24301
  var import_lucide_react21 = require("lucide-react");
24206
24302
  var import_jsx_runtime37 = require("react/jsx-runtime");
@@ -26516,6 +26612,43 @@ function OhhwellsBridge() {
26516
26612
  if (!useFixtures) postToParent2({ type: "ow:request-site-pages" });
26517
26613
  return () => window.removeEventListener("message", onSitePages);
26518
26614
  }, [isEditMode, postToParent2]);
26615
+ (0, import_react23.useEffect)(() => {
26616
+ if (!isEditMode) return;
26617
+ const deps = {
26618
+ getEditContent: () => editContentRef.current,
26619
+ setEditContent: (next) => {
26620
+ editContentRef.current = next;
26621
+ },
26622
+ applyLinkByKey,
26623
+ postToParent: postToParent2
26624
+ };
26625
+ const onPageMessage = (e) => {
26626
+ if (e.data?.type === "ow:page-created") {
26627
+ const { path, title } = e.data;
26628
+ if (typeof path !== "string" || !path) return;
26629
+ if (addNavLinkForPage({ path, title: typeof title === "string" && title ? title : path }, deps)) {
26630
+ enforceLinkHrefs();
26631
+ }
26632
+ return;
26633
+ }
26634
+ if (e.data?.type === "ow:page-renamed") {
26635
+ const { oldPath, newPath, oldTitle, newTitle } = e.data;
26636
+ if (typeof oldPath !== "string" || typeof newPath !== "string") return;
26637
+ const moved = retargetPageLinks(
26638
+ {
26639
+ oldPath,
26640
+ newPath,
26641
+ oldTitle: typeof oldTitle === "string" ? oldTitle : void 0,
26642
+ newTitle: typeof newTitle === "string" ? newTitle : void 0
26643
+ },
26644
+ deps
26645
+ );
26646
+ if (moved > 0) enforceLinkHrefs();
26647
+ }
26648
+ };
26649
+ window.addEventListener("message", onPageMessage);
26650
+ return () => window.removeEventListener("message", onPageMessage);
26651
+ }, [isEditMode, postToParent2]);
26519
26652
  (0, import_react23.useEffect)(() => {
26520
26653
  if (!isEditMode || shouldUseDevFixtures()) return;
26521
26654
  void loadAllSectionsManifest().then((manifest) => {
@@ -32365,7 +32498,7 @@ function OhhwellsBridge() {
32365
32498
  postToParent2({
32366
32499
  type: "ow:ready",
32367
32500
  version: "1",
32368
- bridgeVersion: "0.1.161",
32501
+ bridgeVersion: "0.1.163",
32369
32502
  path: pathname,
32370
32503
  nodes: collectEditableNodes(editContentRef.current),
32371
32504
  sections