@graphcommerce/next-ui 11.0.0-canary.48 → 11.0.0-canary.50

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.0.0-canary.50
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2707](https://github.com/graphcommerce-org/graphcommerce/pull/2707) [`abcfce1`](https://github.com/graphcommerce-org/graphcommerce/commit/abcfce130beaf5544a6ceec794fdeb99e4b3e3ba) - **Breaking change:** configuration fields are server-only, unless their definition in `Config.graphqls` has `@public`. In the browser, `@graphcommerce/next-config/config` resolves to a file with only the `@public` fields, so secrets such as `previewSecret` and `hygraphSecret` stay out of the client JavaScript and its source maps. Turbopack stops the build on a browser import of a server-only field. See [docs/upgrading/graphcommerce-10-to-11.md](docs/upgrading/graphcommerce-10-to-11.md). ([@paales](https://github.com/paales))
8
+
9
+ ## 11.0.0-canary.49
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2701](https://github.com/graphcommerce-org/graphcommerce/pull/2701) [`561f62d`](https://github.com/graphcommerce-org/graphcommerce/commit/561f62dd0072d3080dc18a01fa5fda66a96af410) - A page that opens with `#gallery`, for example after a reload of the zoomed gallery or after Back from another site, renders without zoom, the same as the server render, and removes `#gallery` without a "Cancel rendering route" error. Before, the gallery rendered zoomed in the browser and closed again, so the image moved on page load. ([@DivaniNL](https://github.com/DivaniNL))
14
+
15
+ - [#2701](https://github.com/graphcommerce-org/graphcommerce/pull/2701) [`7df196c`](https://github.com/graphcommerce-org/graphcommerce/commit/7df196c9115966de4b794c55d9d21f2e1dad007c) - The zoomed SidebarGallery fills the full screen height. It moves up by its measured distance to the top of the page instead of a fixed margin based on the header height. With the fixed margin, the zoomed gallery on desktop started 11px below the top of the screen and the bottom 11px was cut off. ([@DivaniNL](https://github.com/DivaniNL))
16
+
3
17
  ## 11.0.0-canary.48
4
18
 
5
19
  ### Minor Changes
package/Config.graphqls CHANGED
@@ -21,7 +21,7 @@ input SidebarGalleryConfig {
21
21
  """
22
22
  Variant used for the pagination
23
23
  """
24
- paginationVariant: SidebarGalleryPaginationVariant
24
+ paginationVariant: SidebarGalleryPaginationVariant @public
25
25
  }
26
26
 
27
27
  extend input GraphCommerceConfig {
@@ -33,15 +33,15 @@ extend input GraphCommerceConfig {
33
33
  """
34
34
  Configuration for the SidebarGallery component
35
35
  """
36
- breadcrumbs: Boolean = false
36
+ breadcrumbs: Boolean = false @public
37
37
 
38
38
  """
39
39
  Configures the max width of the shell (header, footer, overlays, etc.)
40
40
  """
41
- containerSizingShell: ContainerSizing = FULL_WIDTH
41
+ containerSizingShell: ContainerSizing = FULL_WIDTH @public
42
42
 
43
43
  """
44
44
  Configures the max width of the content (main content area)
45
45
  """
46
- containerSizingContent: ContainerSizing = FULL_WIDTH
46
+ containerSizingContent: ContainerSizing = FULL_WIDTH @public
47
47
  }
@@ -16,7 +16,7 @@ import type { SxProps, Theme } from '@mui/material'
16
16
  import { Box, Fab, styled, Unstable_TrapFocus as TrapFocus, useTheme } from '@mui/material'
17
17
  import { m, useDomEvent, useMotionValue } from 'framer-motion'
18
18
  import { useRouter } from 'next/router'
19
- import React, { useEffect, useRef } from 'react'
19
+ import React, { useCallback, useEffect, useRef } from 'react'
20
20
  import { iconChevronLeft, iconChevronRight, iconFullscreen, iconFullscreenExit } from '../icons'
21
21
  import { IconSvg } from '../IconSvg'
22
22
  import { Row } from '../Row/Row'
@@ -82,28 +82,67 @@ export function SidebarGallery(props: SidebarGalleryProps) {
82
82
  afterScroller,
83
83
  } = props
84
84
 
85
+ const rootRef = useRef<HTMLDivElement>(null)
86
+ const sidebarWrapperRef = useRef<HTMLDivElement>(null)
85
87
  const router = useRouter()
86
88
  const prevRoute = usePrevPageRouter()
87
89
  // const classes = useMergedClasses(useStyles({ clientHeight, aspectRatio }).classes, props.classes)
88
90
 
89
91
  const route = `#${routeHash}`
90
- // We're using the URL to manage the state of the gallery.
91
- const zoomed = router.asPath.endsWith(route)
92
+ // We're using the URL to manage the state of the gallery. A page that opens with #gallery has no
93
+ // previous page and renders without zoom, the same as the server render.
94
+ const zoomed = router.asPath.endsWith(route) && Boolean(prevRoute?.pathname)
92
95
  usePreventScroll(zoomed)
93
96
 
94
97
  // cleanup if someone enters the page with #gallery
95
98
  useEffect(() => {
96
- if (!prevRoute?.pathname && zoomed) {
97
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
98
- router.replace(router.asPath.replace(route, ''))
99
+ if (prevRoute?.pathname || !router.asPath.endsWith(route)) return undefined
100
+ let active = true
101
+ const removeHash = async () => {
102
+ try {
103
+ await router.replace(router.asPath.replace(route, ''))
104
+ } catch (e) {
105
+ // The route change of Next.js after hydration can cancel this replace.
106
+ if (!(e as { cancelled?: boolean }).cancelled) throw e
107
+ if (active) await removeHash()
108
+ }
109
+ }
110
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
111
+ removeHash()
112
+ return () => {
113
+ active = false
99
114
  }
100
115
  }, [prevRoute?.pathname, route, router, zoomed])
101
116
 
117
+ // The zoomed gallery moves up by its layout distance to the top of the page, so it fills the full
118
+ // screen height. offsetTop ignores transforms, so the Framer layout animation and the translate
119
+ // do not change the measurement. The sidebar keeps its height from before the zoom, so its content
120
+ // does not move while it slides out.
121
+ const measureZoomOffsets = useCallback(() => {
122
+ const root = rootRef.current
123
+ if (!root || !sidebarWrapperRef.current) return
124
+ let top = 0
125
+ for (let el: HTMLElement | null = root; el; el = el.offsetParent as HTMLElement | null) {
126
+ top += el.offsetTop
127
+ }
128
+ root.style.setProperty('--zoom-offset', `${top}px`)
129
+ if (!zoomed) {
130
+ root.style.setProperty('--sidebar-height', `${sidebarWrapperRef.current.offsetHeight}px`)
131
+ }
132
+ }, [zoomed])
133
+
134
+ useEffect(() => {
135
+ measureZoomOffsets()
136
+ window.addEventListener('resize', measureZoomOffsets)
137
+ return () => window.removeEventListener('resize', measureZoomOffsets)
138
+ }, [measureZoomOffsets])
139
+
102
140
  const toggle = () => {
103
141
  if (disableZoom) {
104
142
  return
105
143
  }
106
144
  if (!zoomed) {
145
+ measureZoomOffsets()
107
146
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
108
147
  router.push(route, undefined, { shallow: true })
109
148
  window.scrollTo({ top: 0, behavior: 'smooth' })
@@ -160,6 +199,7 @@ export function SidebarGallery(props: SidebarGalleryProps) {
160
199
  )}
161
200
  >
162
201
  <MotionBox
202
+ ref={rootRef}
163
203
  layout
164
204
  layoutDependency={zoomed}
165
205
  className={classes.root}
@@ -175,9 +215,8 @@ export function SidebarGallery(props: SidebarGalleryProps) {
175
215
  '&.zoomed': {
176
216
  position: 'relative',
177
217
  zIndex: theme.zIndex.modal,
178
- marginTop: `calc(${theme.appShell.headerHeightSm} * -1)`,
218
+ translate: '0 calc(var(--zoom-offset) * -1)',
179
219
  [theme.breakpoints.up('md')]: {
180
- marginTop: `calc(${theme.appShell.headerHeightMd} * -1 - ${theme.spacings.lg})`,
181
220
  gridTemplateColumns: '1fr auto',
182
221
  },
183
222
  px: 0,
@@ -367,6 +406,7 @@ export function SidebarGallery(props: SidebarGalleryProps) {
367
406
  </MotionBox>
368
407
  </TrapFocus>
369
408
  <Box
409
+ ref={sidebarWrapperRef}
370
410
  className={classes.sidebarWrapper}
371
411
  sx={sxx(
372
412
  {
@@ -386,6 +426,8 @@ export function SidebarGallery(props: SidebarGalleryProps) {
386
426
  left: `calc(${responsiveVal(300, 500, undefined, theme.breakpoints.values.lg)} + ${
387
427
  theme.page.horizontal
388
428
  } * 2)`,
429
+ marginTop: 'var(--zoom-offset)',
430
+ height: 'var(--sidebar-height)',
389
431
  },
390
432
  },
391
433
  )}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/next-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "11.0.0-canary.48",
5
+ "version": "11.0.0-canary.50",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -43,13 +43,13 @@
43
43
  "@emotion/react": "^11.14.0",
44
44
  "@emotion/server": "^11.11.0",
45
45
  "@emotion/styled": "^11.14.1",
46
- "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.48",
47
- "@graphcommerce/framer-next-pages": "^11.0.0-canary.48",
48
- "@graphcommerce/framer-scroller": "^11.0.0-canary.48",
49
- "@graphcommerce/framer-utils": "^11.0.0-canary.48",
50
- "@graphcommerce/image": "^11.0.0-canary.48",
51
- "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.48",
52
- "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.48",
46
+ "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.50",
47
+ "@graphcommerce/framer-next-pages": "^11.0.0-canary.50",
48
+ "@graphcommerce/framer-scroller": "^11.0.0-canary.50",
49
+ "@graphcommerce/framer-utils": "^11.0.0-canary.50",
50
+ "@graphcommerce/image": "^11.0.0-canary.50",
51
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.50",
52
+ "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.50",
53
53
  "@lingui/core": "^5",
54
54
  "@lingui/macro": "^5",
55
55
  "@lingui/react": "^5",