@ohhwells/bridge 0.1.154 → 0.1.156

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
@@ -83,6 +83,7 @@ __export(index_exports, {
83
83
  foldAlignIntoTrees: () => foldAlignIntoTrees,
84
84
  getEditModeInitialState: () => getEditModeInitialState,
85
85
  hasMountedContentNodes: () => hasMountedContentNodes,
86
+ indexCollectionItems: () => indexCollectionItems,
86
87
  insertFooterHours: () => insertFooterHours,
87
88
  isEditSessionActive: () => isEditSessionActive,
88
89
  isPlainLeftClick: () => isPlainLeftClick,
@@ -90,6 +91,7 @@ __export(index_exports, {
90
91
  isRenderableTree: () => isRenderableTree,
91
92
  isStickySearchParam: () => isStickySearchParam,
92
93
  isValidUrl: () => isValidUrl,
94
+ matchCollectionItemClick: () => matchCollectionItemClick,
93
95
  nextViableSlide: () => nextViableSlide,
94
96
  parseAiFooterState: () => parseAiFooterState,
95
97
  parseAiSectionsState: () => parseAiSectionsState,
@@ -11695,6 +11697,172 @@ function useLinkHrefGuardian(...deps) {
11695
11697
  }, deps);
11696
11698
  }
11697
11699
 
11700
+ // src/ui/link-modal/linkModal.utils.ts
11701
+ function parseTarget(target) {
11702
+ if (!target) return { pageRoute: "", sectionId: null };
11703
+ const hashIndex = target.indexOf("#");
11704
+ if (hashIndex === -1) return { pageRoute: target, sectionId: null };
11705
+ return {
11706
+ pageRoute: target.slice(0, hashIndex),
11707
+ sectionId: target.slice(hashIndex + 1) || null
11708
+ };
11709
+ }
11710
+ function normalizePath(path) {
11711
+ const trimmed = path.trim();
11712
+ if (!trimmed) return "/";
11713
+ try {
11714
+ if (/^https?:\/\//i.test(trimmed)) {
11715
+ return new URL(trimmed).pathname || "/";
11716
+ }
11717
+ } catch {
11718
+ }
11719
+ const withSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
11720
+ if (withSlash.length > 1 && withSlash.endsWith("/")) return withSlash.slice(0, -1);
11721
+ return withSlash;
11722
+ }
11723
+ function findPageByPath(pages, path) {
11724
+ const normalized = normalizePath(path);
11725
+ return pages.find((p) => normalizePath(p.path) === normalized);
11726
+ }
11727
+ function inferPageTitleFromPath(path) {
11728
+ const normalized = normalizePath(path);
11729
+ if (normalized === "/") return "Home";
11730
+ const segment = normalized.split("/").filter(Boolean).pop() ?? "";
11731
+ if (!segment) return "Home";
11732
+ return segment.split("-").filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
11733
+ }
11734
+ function isInternalPath(route) {
11735
+ const trimmed = route.trim();
11736
+ if (!trimmed) return false;
11737
+ if (/^https?:\/\//i.test(trimmed)) return false;
11738
+ if (trimmed.startsWith("/")) return true;
11739
+ if (trimmed.includes(" ") || trimmed.includes(".")) return false;
11740
+ return true;
11741
+ }
11742
+ function resolvePage(route, pages) {
11743
+ const found = findPageByPath(pages, route);
11744
+ if (found) return { path: found.path, title: found.title };
11745
+ return { path: normalizePath(route), title: inferPageTitleFromPath(route) };
11746
+ }
11747
+ function getSectionsForPath(sectionsByPath, pageRoute) {
11748
+ if (!sectionsByPath) return [];
11749
+ const normalized = normalizePath(pageRoute);
11750
+ return sectionsByPath[normalized] ?? sectionsByPath[pageRoute] ?? [];
11751
+ }
11752
+ function buildTarget(page, section) {
11753
+ if (section) return `${page.path}#${section.id}`;
11754
+ return page.path;
11755
+ }
11756
+ function isValidUrl(urlString) {
11757
+ try {
11758
+ const url = new URL(urlString);
11759
+ if (url.protocol !== "http:" && url.protocol !== "https:") return false;
11760
+ const hostname = url.hostname;
11761
+ if (!hostname || hostname.length === 0) return false;
11762
+ if (hostname.includes(" ")) return false;
11763
+ if (hostname === "localhost") return true;
11764
+ if (!hostname.includes(".")) return false;
11765
+ if (!/[a-z]/i.test(hostname)) return false;
11766
+ return true;
11767
+ } catch {
11768
+ return false;
11769
+ }
11770
+ }
11771
+ function normalizeUrl(value) {
11772
+ const trimmed = value.trim();
11773
+ if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return trimmed;
11774
+ return `https://${trimmed}`;
11775
+ }
11776
+ function validateUrlInput(value, pages, allPages) {
11777
+ const trimmed = value.trim();
11778
+ if (!trimmed) return "";
11779
+ const exactPage = allPages.find((p) => p.title.toLowerCase() === trimmed.toLowerCase());
11780
+ if (exactPage) return "";
11781
+ const hasPrefixMatch = pages.some((p) => p.title.toLowerCase().startsWith(trimmed.toLowerCase()));
11782
+ if (hasPrefixMatch) {
11783
+ return "Select a page from the list or enter a valid URL";
11784
+ }
11785
+ const hasScheme = /^https?:\/\//i.test(trimmed);
11786
+ if (!hasScheme && !trimmed.includes(".")) {
11787
+ return "Please enter a valid URL (e.g., https://example.com)";
11788
+ }
11789
+ if (!isValidUrl(normalizeUrl(trimmed))) {
11790
+ return "Please enter a valid URL (e.g., https://example.com)";
11791
+ }
11792
+ return "";
11793
+ }
11794
+ function getEditModeInitialState(target, pages, sections) {
11795
+ const empty = {
11796
+ searchValue: "",
11797
+ selectedPage: null,
11798
+ selectedSection: null,
11799
+ step: "input"
11800
+ };
11801
+ if (!target) return empty;
11802
+ if (isValidUrl(normalizeUrl(target))) {
11803
+ return { searchValue: target, selectedPage: null, selectedSection: null, step: "input" };
11804
+ }
11805
+ const { pageRoute, sectionId } = parseTarget(target);
11806
+ if (sectionId) {
11807
+ if (isInternalPath(pageRoute)) {
11808
+ const page = resolvePage(pageRoute, pages);
11809
+ const sec = sections.find((s) => s.id === sectionId);
11810
+ return {
11811
+ searchValue: page.title,
11812
+ selectedPage: page,
11813
+ selectedSection: sec ? { id: sec.id, label: sec.label } : null,
11814
+ step: "input"
11815
+ };
11816
+ }
11817
+ return { searchValue: pageRoute || target, selectedPage: null, selectedSection: null, step: "input" };
11818
+ }
11819
+ if (isInternalPath(pageRoute)) {
11820
+ const page = resolvePage(pageRoute, pages);
11821
+ return {
11822
+ searchValue: page.title,
11823
+ selectedPage: page,
11824
+ selectedSection: null,
11825
+ step: "input"
11826
+ };
11827
+ }
11828
+ return { searchValue: target, selectedPage: null, selectedSection: null, step: "input" };
11829
+ }
11830
+ function filterAvailablePages(pages, existingTargets) {
11831
+ const taken = new Set(existingTargets);
11832
+ return pages.filter((p) => !taken.has(p.path));
11833
+ }
11834
+
11835
+ // src/lib/collection-item-click.ts
11836
+ function indexCollectionItems(pages) {
11837
+ const index = /* @__PURE__ */ new Map();
11838
+ for (const page of pages) {
11839
+ if (page.kind !== "COLLECTION_ITEM" || !page.collection || !page.path) continue;
11840
+ index.set(normalizePath(page.path), { path: page.path, collection: page.collection });
11841
+ }
11842
+ return index;
11843
+ }
11844
+ function pathOfHref(href) {
11845
+ const trimmed = href.trim();
11846
+ if (!trimmed || trimmed.startsWith("#")) return null;
11847
+ if (/^[a-z][a-z0-9+.-]*:/i.test(trimmed) && !/^https?:/i.test(trimmed)) return null;
11848
+ const withoutHash = trimmed.split("#")[0];
11849
+ const withoutQuery = withoutHash.split("?")[0];
11850
+ if (!withoutQuery) return null;
11851
+ return normalizePath(withoutQuery);
11852
+ }
11853
+ function matchCollectionItemClick(target, index) {
11854
+ if (!target || index.size === 0) return null;
11855
+ const text = target.closest('[data-ohw-editable="text"], [data-ohw-editable="plain"]');
11856
+ if (!text) return null;
11857
+ const anchor = text.closest("a");
11858
+ if (!anchor || anchor.closest(CTA_BUTTON_SELECTOR)) return null;
11859
+ const href = anchor.getAttribute("href");
11860
+ if (!href) return null;
11861
+ const path = pathOfHref(href);
11862
+ if (!path) return null;
11863
+ return index.get(path) ?? null;
11864
+ }
11865
+
11698
11866
  // src/lib/sticky-search-params.ts
11699
11867
  var STICKY_EXACT = /* @__PURE__ */ new Set([
11700
11868
  // Site identity. Required in local dev and in the canvas editor's iframe, where there is no
@@ -17044,7 +17212,7 @@ function apiBase() {
17044
17212
  function bridgeVersion() {
17045
17213
  try {
17046
17214
  if (true) {
17047
- return "0.1.154";
17215
+ return "0.1.156";
17048
17216
  }
17049
17217
  } catch {
17050
17218
  }
@@ -17058,7 +17226,7 @@ function stampBridgeVersionOnDocument() {
17058
17226
  return;
17059
17227
  }
17060
17228
  try {
17061
- const v = true ? "0.1.154" : "";
17229
+ const v = true ? "0.1.156" : "";
17062
17230
  if (v) {
17063
17231
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17064
17232
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -17067,10 +17235,19 @@ function stampBridgeVersionOnDocument() {
17067
17235
  }
17068
17236
  }
17069
17237
  var RECOVERABLE_PAGE_ERROR = /Minified React error #(?:418|419|421|422|423|425)\b|Hydration failed because the initial UI does not match|Text content does not match server-rendered HTML|There was an error while hydrating|did not match\. Server:/i;
17238
+ function isVercelPreviewHost() {
17239
+ if (typeof location === "undefined") {
17240
+ return false;
17241
+ }
17242
+ return location.hostname.toLowerCase().endsWith(".vercel.ohhwells.site");
17243
+ }
17070
17244
  function reportOutageBeacon(args) {
17071
17245
  if (typeof window === "undefined" || !args.subdomain) {
17072
17246
  return;
17073
17247
  }
17248
+ if (isVercelPreviewHost()) {
17249
+ return;
17250
+ }
17074
17251
  if (args.reason === "page_error" && args.detail && RECOVERABLE_PAGE_ERROR.test(args.detail)) {
17075
17252
  return;
17076
17253
  }
@@ -20705,141 +20882,6 @@ function isEditSessionActive() {
20705
20882
  return new URLSearchParams(q).get("mode") === "edit";
20706
20883
  }
20707
20884
 
20708
- // src/ui/link-modal/linkModal.utils.ts
20709
- function parseTarget(target) {
20710
- if (!target) return { pageRoute: "", sectionId: null };
20711
- const hashIndex = target.indexOf("#");
20712
- if (hashIndex === -1) return { pageRoute: target, sectionId: null };
20713
- return {
20714
- pageRoute: target.slice(0, hashIndex),
20715
- sectionId: target.slice(hashIndex + 1) || null
20716
- };
20717
- }
20718
- function normalizePath(path) {
20719
- const trimmed = path.trim();
20720
- if (!trimmed) return "/";
20721
- try {
20722
- if (/^https?:\/\//i.test(trimmed)) {
20723
- return new URL(trimmed).pathname || "/";
20724
- }
20725
- } catch {
20726
- }
20727
- const withSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
20728
- if (withSlash.length > 1 && withSlash.endsWith("/")) return withSlash.slice(0, -1);
20729
- return withSlash;
20730
- }
20731
- function findPageByPath(pages, path) {
20732
- const normalized = normalizePath(path);
20733
- return pages.find((p) => normalizePath(p.path) === normalized);
20734
- }
20735
- function inferPageTitleFromPath(path) {
20736
- const normalized = normalizePath(path);
20737
- if (normalized === "/") return "Home";
20738
- const segment = normalized.split("/").filter(Boolean).pop() ?? "";
20739
- if (!segment) return "Home";
20740
- return segment.split("-").filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
20741
- }
20742
- function isInternalPath(route) {
20743
- const trimmed = route.trim();
20744
- if (!trimmed) return false;
20745
- if (/^https?:\/\//i.test(trimmed)) return false;
20746
- if (trimmed.startsWith("/")) return true;
20747
- if (trimmed.includes(" ") || trimmed.includes(".")) return false;
20748
- return true;
20749
- }
20750
- function resolvePage(route, pages) {
20751
- const found = findPageByPath(pages, route);
20752
- if (found) return { path: found.path, title: found.title };
20753
- return { path: normalizePath(route), title: inferPageTitleFromPath(route) };
20754
- }
20755
- function getSectionsForPath(sectionsByPath, pageRoute) {
20756
- if (!sectionsByPath) return [];
20757
- const normalized = normalizePath(pageRoute);
20758
- return sectionsByPath[normalized] ?? sectionsByPath[pageRoute] ?? [];
20759
- }
20760
- function buildTarget(page, section) {
20761
- if (section) return `${page.path}#${section.id}`;
20762
- return page.path;
20763
- }
20764
- function isValidUrl(urlString) {
20765
- try {
20766
- const url = new URL(urlString);
20767
- if (url.protocol !== "http:" && url.protocol !== "https:") return false;
20768
- const hostname = url.hostname;
20769
- if (!hostname || hostname.length === 0) return false;
20770
- if (hostname.includes(" ")) return false;
20771
- if (hostname === "localhost") return true;
20772
- if (!hostname.includes(".")) return false;
20773
- if (!/[a-z]/i.test(hostname)) return false;
20774
- return true;
20775
- } catch {
20776
- return false;
20777
- }
20778
- }
20779
- function normalizeUrl(value) {
20780
- const trimmed = value.trim();
20781
- if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return trimmed;
20782
- return `https://${trimmed}`;
20783
- }
20784
- function validateUrlInput(value, pages, allPages) {
20785
- const trimmed = value.trim();
20786
- if (!trimmed) return "";
20787
- const exactPage = allPages.find((p) => p.title.toLowerCase() === trimmed.toLowerCase());
20788
- if (exactPage) return "";
20789
- const hasPrefixMatch = pages.some((p) => p.title.toLowerCase().startsWith(trimmed.toLowerCase()));
20790
- if (hasPrefixMatch) {
20791
- return "Select a page from the list or enter a valid URL";
20792
- }
20793
- const hasScheme = /^https?:\/\//i.test(trimmed);
20794
- if (!hasScheme && !trimmed.includes(".")) {
20795
- return "Please enter a valid URL (e.g., https://example.com)";
20796
- }
20797
- if (!isValidUrl(normalizeUrl(trimmed))) {
20798
- return "Please enter a valid URL (e.g., https://example.com)";
20799
- }
20800
- return "";
20801
- }
20802
- function getEditModeInitialState(target, pages, sections) {
20803
- const empty = {
20804
- searchValue: "",
20805
- selectedPage: null,
20806
- selectedSection: null,
20807
- step: "input"
20808
- };
20809
- if (!target) return empty;
20810
- if (isValidUrl(normalizeUrl(target))) {
20811
- return { searchValue: target, selectedPage: null, selectedSection: null, step: "input" };
20812
- }
20813
- const { pageRoute, sectionId } = parseTarget(target);
20814
- if (sectionId) {
20815
- if (isInternalPath(pageRoute)) {
20816
- const page = resolvePage(pageRoute, pages);
20817
- const sec = sections.find((s) => s.id === sectionId);
20818
- return {
20819
- searchValue: page.title,
20820
- selectedPage: page,
20821
- selectedSection: sec ? { id: sec.id, label: sec.label } : null,
20822
- step: "input"
20823
- };
20824
- }
20825
- return { searchValue: pageRoute || target, selectedPage: null, selectedSection: null, step: "input" };
20826
- }
20827
- if (isInternalPath(pageRoute)) {
20828
- const page = resolvePage(pageRoute, pages);
20829
- return {
20830
- searchValue: page.title,
20831
- selectedPage: page,
20832
- selectedSection: null,
20833
- step: "input"
20834
- };
20835
- }
20836
- return { searchValue: target, selectedPage: null, selectedSection: null, step: "input" };
20837
- }
20838
- function filterAvailablePages(pages, existingTargets) {
20839
- const taken = new Set(existingTargets);
20840
- return pages.filter((p) => !taken.has(p.path));
20841
- }
20842
-
20843
20885
  // src/lib/prefetch-sections.ts
20844
20886
  function buildPageFetchUrl(path) {
20845
20887
  const normalized = normalizePath(path);
@@ -25998,6 +26040,7 @@ function OhhwellsBridge() {
25998
26040
  const appliedDrawerRef = (0, import_react21.useRef)(null);
25999
26041
  const pendingDeleteUndoRef = (0, import_react21.useRef)(null);
26000
26042
  const [sitePages, setSitePages] = (0, import_react21.useState)([]);
26043
+ const collectionItemsRef = (0, import_react21.useRef)(/* @__PURE__ */ new Map());
26001
26044
  const [sectionsByPath, setSectionsByPath] = (0, import_react21.useState)({});
26002
26045
  const sectionsPrefetchGenRef = (0, import_react21.useRef)(0);
26003
26046
  const setLinkPopoverRef = (0, import_react21.useRef)(setLinkPopover);
@@ -26141,10 +26184,12 @@ function OhhwellsBridge() {
26141
26184
  const onSitePages = (e) => {
26142
26185
  if (e.data?.type !== "ow:site-pages" || !Array.isArray(e.data.pages)) return;
26143
26186
  if (useFixtures) return;
26144
- const mapped = e.data.pages.map((p) => ({
26187
+ const incoming = e.data.pages;
26188
+ const mapped = incoming.map((p) => ({
26145
26189
  path: p.path,
26146
26190
  title: p.title
26147
26191
  }));
26192
+ collectionItemsRef.current = indexCollectionItems(incoming);
26148
26193
  setSitePages(mapped);
26149
26194
  runSectionsPrefetchRef.current(mapped);
26150
26195
  };
@@ -28564,6 +28609,17 @@ function OhhwellsBridge() {
28564
28609
  }
28565
28610
  if (isInsideFloatingPanel(target)) return;
28566
28611
  if (target.closest("[data-ohw-form-toolbar]")) return;
28612
+ const collectionItem = matchCollectionItemClick(target, collectionItemsRef.current);
28613
+ if (collectionItem) {
28614
+ e.preventDefault();
28615
+ e.stopPropagation();
28616
+ postToParentRef.current({
28617
+ type: "ow:collection-item-selected",
28618
+ path: collectionItem.path,
28619
+ collection: collectionItem.collection
28620
+ });
28621
+ return;
28622
+ }
28567
28623
  if (target.closest(
28568
28624
  '[data-ohw-field-toolbar], [data-ohw-field-type-picker], [data-radix-popper-content-wrapper], [role="menu"], [data-slot="dropdown-menu-content"]'
28569
28625
  )) {
@@ -31984,7 +32040,7 @@ function OhhwellsBridge() {
31984
32040
  postToParent2({
31985
32041
  type: "ow:ready",
31986
32042
  version: "1",
31987
- bridgeVersion: "0.1.154",
32043
+ bridgeVersion: "0.1.156",
31988
32044
  path: pathname,
31989
32045
  nodes: collectEditableNodes(editContentRef.current),
31990
32046
  sections
@@ -33210,6 +33266,7 @@ function EmptySection({ title, homeHref = "/", eyebrowKey, titleKey, subtitleKey
33210
33266
  foldAlignIntoTrees,
33211
33267
  getEditModeInitialState,
33212
33268
  hasMountedContentNodes,
33269
+ indexCollectionItems,
33213
33270
  insertFooterHours,
33214
33271
  isEditSessionActive,
33215
33272
  isPlainLeftClick,
@@ -33217,6 +33274,7 @@ function EmptySection({ title, homeHref = "/", eyebrowKey, titleKey, subtitleKey
33217
33274
  isRenderableTree,
33218
33275
  isStickySearchParam,
33219
33276
  isValidUrl,
33277
+ matchCollectionItemClick,
33220
33278
  nextViableSlide,
33221
33279
  parseAiFooterState,
33222
33280
  parseAiSectionsState,