@wix/origami-site 1.1.0 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-site",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Runs an exported Wix origami site: file-based routing, Wix dynamic pages, popups and build checks. Use with @wix/origami-site-astro or @wix/origami-site-express.",
5
5
  "type": "module",
6
6
  "files": [
@@ -48,11 +48,11 @@
48
48
  "dependencies": {
49
49
  "@wix/origami-types": "^1.5.0",
50
50
  "@wix/builder-error-pages": "^1.1.6",
51
- "@wix/origami-transforms": "^0.1.66",
51
+ "@wix/origami-transforms": "^0.1.67",
52
52
  "@babel/parser": "^7.25.0",
53
- "@wix/origami-services": "^1.3.0",
53
+ "@wix/origami-services": "^1.4.0",
54
54
  "@wix/services-manager-react": "^1.0.8",
55
- "@wix/origami-bi": "^0.24.1"
55
+ "@wix/origami-bi": "^0.24.2"
56
56
  },
57
57
  "exports": {
58
58
  "./server": {
@@ -93,5 +93,5 @@
93
93
  "optional": true
94
94
  }
95
95
  },
96
- "falconPackageHash": "853798bbb8b1cb95d8f867ecc4487657e8e848d9eb0c44b0598415a3"
96
+ "falconPackageHash": "6649a721555d393e583d946ebf521346e9b8cd1f61080ed1105ec9fa"
97
97
  }
@@ -65,6 +65,9 @@ export async function mountPage(element, { pages, popups = {}, seoUriByPageId =
65
65
  userAgent: navigator.userAgent, reducedMotion: globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches,
66
66
  })
67
67
  sealServicesConfigs()
68
+ // Before the page renders, so a reload's reset of the popups shown this visit and `?popup=`'s mark come before the
69
+ // page's auto-open reads them. PopupHost reads the controller when it mounts.
70
+ if (hasPopups) startPopups()
68
71
  const root = createRoot(element)
69
72
  // #main_MF is the container-query root: editor-components' `--one-unit: 1cqw` resolves against it.
70
73
  // PopupHost sits inside it too, so popups share the page's services and container-query root.
@@ -72,7 +75,6 @@ export async function mountPage(element, { pages, popups = {}, seoUriByPageId =
72
75
  createElement(Page), hasPopups ? createElement(PopupHost) : null)
73
76
  root.render(createElement(StrictMode, null, createElement(WixServices, { servicesMap: map, children: main })))
74
77
  if (!hasPopups) return () => root.unmount()
75
- startPopups()
76
78
  document.addEventListener('click', onPopupLinkClick)
77
79
  return () => {
78
80
  document.removeEventListener('click', onPopupLinkClick)
@@ -62,8 +62,40 @@ export const lightboxConfig = {
62
62
  getPayload: () => current?.payload,
63
63
  }
64
64
 
65
- /** Opens the popup a `?popup=<seoUri>` URL names, right away and every time. Opening never changes the URL. */
65
+ /**
66
+ * Opens the popup a `?popup=<seoUri>` URL names, right away and every time. Opening never changes the URL. It marks the
67
+ * popup shown for this visit so the page's auto-open doesn't open it again. mountPage calls it on every page load
68
+ * before the page renders, so it also resets shown markers on refresh before the page reads them.
69
+ */
66
70
  export function startPopups() {
71
+ forgetShownOnReload()
67
72
  const seoUri = new URL(location.href).searchParams.get('popup')
68
- if (seoUri) openPopup(seoUri).catch(error => console.warn(`Cannot open ?popup=${seoUri}:`, error))
73
+ if (!seoUri) return
74
+ const key = SHOWN_PREFIX + seoUri
75
+ markShown(key)
76
+ openPopup(seoUri).catch(error => {
77
+ forgetShown(key)
78
+ console.warn(`Cannot open ?popup=${seoUri}:`, error)
79
+ })
80
+ }
81
+
82
+ const SHOWN_PREFIX = 'wix-auto-popup-shown-'
83
+
84
+ // Refresh starts a new popup visit across the site, so clear all popup shown markers.
85
+ // Normal navigation and Back preserve them. Run before the page checks whether to auto-open.
86
+ function forgetShownOnReload() {
87
+ try {
88
+ if (!performance.getEntriesByType?.('navigation').some(entry => /** @type {PerformanceNavigationTiming} */ (entry).type === 'reload')) return
89
+ for (const key of Object.keys(sessionStorage)) if (key.startsWith(SHOWN_PREFIX)) sessionStorage.removeItem(key)
90
+ } catch {}
91
+ }
92
+
93
+ /** @param {string} key */
94
+ function markShown(key) {
95
+ try { sessionStorage.setItem(key, 'true') } catch {}
96
+ }
97
+
98
+ /** @param {string} key */
99
+ function forgetShown(key) {
100
+ try { sessionStorage.removeItem(key) } catch {}
69
101
  }