@graphcommerce/hygraph-ui 10.0.0-canary.67 → 10.0.0-canary.72
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 +14 -0
- package/components/Asset/Asset.tsx +3 -15
- package/components/RichText/RichText.tsx +2 -9
- package/components/RichText/defaultRenderers.tsx +4 -6
- package/components/RichText/defaultSxRenderer.ts +1 -1
- package/lib/getAllHygraphPages.ts +7 -5
- package/lib/getHygraphPaths.ts +8 -7
- package/lib/hygraphPageContent.ts +13 -6
- package/package.json +9 -9
- package/plugins/hygraphGraphqlConfig.ts +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 10.0.0-canary.72
|
|
4
|
+
|
|
5
|
+
## 10.0.0-canary.71
|
|
6
|
+
|
|
7
|
+
## 10.0.0-canary.70
|
|
8
|
+
|
|
9
|
+
### Major Changes
|
|
10
|
+
|
|
11
|
+
- [#2565](https://github.com/graphcommerce-org/graphcommerce/pull/2565) [`c96dfcd`](https://github.com/graphcommerce-org/graphcommerce/commit/c96dfcdca981baca387c270ad9e2b9515cdd00cc) - Updated to Apollo Client 4 ([@paales](https://github.com/paales))
|
|
12
|
+
|
|
13
|
+
## 10.0.0-canary.69
|
|
14
|
+
|
|
15
|
+
## 10.0.0-canary.68
|
|
16
|
+
|
|
3
17
|
## 10.0.0-canary.67
|
|
4
18
|
|
|
5
19
|
## 10.0.0-canary.66
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ImageProps } from '@graphcommerce/image'
|
|
2
2
|
import { Image } from '@graphcommerce/image'
|
|
3
|
+
import { sxx } from '@graphcommerce/next-ui'
|
|
3
4
|
import type { SxProps, Theme } from '@mui/material'
|
|
4
5
|
import { styled } from '@mui/material'
|
|
5
6
|
import { memo } from 'react'
|
|
@@ -35,27 +36,14 @@ export const Asset = memo<AssetProps>((props) => {
|
|
|
35
36
|
{...imgProps}
|
|
36
37
|
{...assetProps}
|
|
37
38
|
unoptimized={typeof unoptimized === 'boolean' ? unoptimized : mimeType === 'image/svg+xml'}
|
|
38
|
-
sx={
|
|
39
|
+
sx={sx}
|
|
39
40
|
/>
|
|
40
41
|
)
|
|
41
42
|
}
|
|
42
|
-
|
|
43
43
|
if (asset.mimeType === 'video/mp4') {
|
|
44
44
|
const Video = styled('video')({})
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<Video
|
|
48
|
-
src={asset.url}
|
|
49
|
-
autoPlay
|
|
50
|
-
muted
|
|
51
|
-
loop
|
|
52
|
-
playsInline
|
|
53
|
-
disableRemotePlayback
|
|
54
|
-
sx={[...(Array.isArray(sx) ? sx : [sx])]}
|
|
55
|
-
/>
|
|
56
|
-
)
|
|
45
|
+
return <Video src={asset.url} autoPlay muted loop playsInline disableRemotePlayback sx={sx} />
|
|
57
46
|
}
|
|
58
|
-
|
|
59
47
|
if (process.env.NODE_ENV !== 'production') return <div>{asset.mimeType} not supported</div>
|
|
60
48
|
return null
|
|
61
49
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
import { sxx } from '@graphcommerce/next-ui'
|
|
2
3
|
import type { SxProps, Theme } from '@mui/material'
|
|
3
4
|
import React from 'react'
|
|
4
5
|
import { defaultRenderers } from './defaultRenderers'
|
|
@@ -150,15 +151,7 @@ function mergeSxRenderer(base: SxRenderer, sxRenderer?: SxRenderer) {
|
|
|
150
151
|
Object.entries<SxProps<Theme>>(base).map(([key, sx]) => {
|
|
151
152
|
const sxOverride: SxProps<Theme> = sxRenderer?.[key]
|
|
152
153
|
|
|
153
|
-
return sxOverride
|
|
154
|
-
? [
|
|
155
|
-
key,
|
|
156
|
-
[
|
|
157
|
-
...(Array.isArray(sx) ? sx : [sx]),
|
|
158
|
-
...(Array.isArray(sxOverride) ? sxOverride : [sxOverride]),
|
|
159
|
-
],
|
|
160
|
-
]
|
|
161
|
-
: [key, sx]
|
|
154
|
+
return sxOverride ? [key, [sx, sxOverride]] : [key, sx]
|
|
162
155
|
}),
|
|
163
156
|
) as SxRenderer
|
|
164
157
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sxx } from '@graphcommerce/next-ui'
|
|
1
2
|
import { Box, Link, Typography } from '@mui/material'
|
|
2
3
|
import { Asset } from '../Asset/Asset'
|
|
3
4
|
import type { Renderers } from './types'
|
|
@@ -24,10 +25,7 @@ export const defaultRenderers: Renderers = {
|
|
|
24
25
|
component='iframe'
|
|
25
26
|
src={url}
|
|
26
27
|
loading='lazy'
|
|
27
|
-
sx={
|
|
28
|
-
{ aspectRatio: `${width} / ${height}`, width: '100%' },
|
|
29
|
-
...(Array.isArray(sx) ? sx : [sx]),
|
|
30
|
-
]}
|
|
28
|
+
sx={sxx({ aspectRatio: `${width} / ${height}`, width: '100%' }, sx)}
|
|
31
29
|
/>
|
|
32
30
|
)
|
|
33
31
|
},
|
|
@@ -51,8 +49,8 @@ export const defaultRenderers: Renderers = {
|
|
|
51
49
|
table_row: (props) => <Box component='tr' {...props} />,
|
|
52
50
|
table_cell: (props) => <Box component='td' {...props} />,
|
|
53
51
|
code: (props) => <Box component='code' {...props} />,
|
|
54
|
-
bold: (props) => <Box component='strong' fontWeight
|
|
55
|
-
italic: (props) => <Box component='em' fontStyle
|
|
52
|
+
bold: (props) => <Box component='strong' {...props} sx={sxx({ fontWeight: 'bold' }, props.sx)} />,
|
|
53
|
+
italic: (props) => <Box component='em' {...props} sx={sxx({ fontStyle: 'italic' }, props.sx)} />,
|
|
56
54
|
underlined: (props) => <Box component='span' {...props} />,
|
|
57
55
|
class: (props) => <Box component='div' {...props} />,
|
|
58
56
|
'code-block': (props) => (
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { cacheFirst } from '@graphcommerce/graphql'
|
|
2
|
-
import type { ApolloClient
|
|
2
|
+
import type { ApolloClient } from '@apollo/client'
|
|
3
3
|
import type { HygraphAllPagesQuery } from '../graphql'
|
|
4
4
|
import { HygraphAllPagesDocument } from '../graphql'
|
|
5
5
|
|
|
6
6
|
type Urls = { url: string }
|
|
7
7
|
|
|
8
8
|
export async function getAllHygraphPages(
|
|
9
|
-
client: ApolloClient
|
|
9
|
+
client: ApolloClient,
|
|
10
10
|
options: { pageSize?: number } = {},
|
|
11
11
|
) {
|
|
12
12
|
const { pageSize = 100 } = options
|
|
@@ -16,10 +16,11 @@ export async function getAllHygraphPages(
|
|
|
16
16
|
variables: { first: pageSize },
|
|
17
17
|
fetchPolicy: cacheFirst(client),
|
|
18
18
|
})
|
|
19
|
-
const pages: Promise<ApolloQueryResult<HygraphAllPagesQuery>>[] = [query]
|
|
20
19
|
|
|
21
20
|
const { data } = await query
|
|
22
|
-
const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize)
|
|
21
|
+
const totalPages = data ? Math.ceil(data.pagesConnection.aggregate.count / pageSize) : 1
|
|
22
|
+
|
|
23
|
+
const pages = [query]
|
|
23
24
|
|
|
24
25
|
if (totalPages > 1) {
|
|
25
26
|
for (let i = 2; i <= totalPages; i++) {
|
|
@@ -34,8 +35,9 @@ export async function getAllHygraphPages(
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const paths: Urls[] = (await Promise.all(pages))
|
|
37
|
-
.map((q) => q.data
|
|
38
|
+
.map((q) => q.data?.pages ?? [])
|
|
38
39
|
.flat(1)
|
|
40
|
+
.filter((page): page is NonNullable<typeof page> & { url: string } => !!page?.url)
|
|
39
41
|
.map((page) => ({
|
|
40
42
|
url: page.url,
|
|
41
43
|
}))
|
package/lib/getHygraphPaths.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { PageWhereInput } from '@graphcommerce/graphql-mesh'
|
|
2
|
-
import type { ApolloClient
|
|
2
|
+
import type { ApolloClient } from '@apollo/client'
|
|
3
3
|
import type { GetStaticPathsResult } from 'next'
|
|
4
|
-
import type { HygraphStaticPathsQuery } from '../graphql/HygraphStaticPaths.gql'
|
|
5
4
|
import { HygraphStaticPathsDocument } from '../graphql/HygraphStaticPaths.gql'
|
|
6
5
|
|
|
7
6
|
type Return = GetStaticPathsResult<{ url: string }>
|
|
8
7
|
|
|
9
8
|
export async function getHygraphStaticPaths(
|
|
10
|
-
client: ApolloClient
|
|
9
|
+
client: ApolloClient,
|
|
11
10
|
locale: string,
|
|
12
11
|
options: { pageSize?: number; filter?: PageWhereInput } = {},
|
|
13
12
|
) {
|
|
@@ -16,10 +15,11 @@ export async function getHygraphStaticPaths(
|
|
|
16
15
|
query: HygraphStaticPathsDocument,
|
|
17
16
|
variables: { pageSize, where: filter },
|
|
18
17
|
})
|
|
19
|
-
const pages: Promise<ApolloQueryResult<HygraphStaticPathsQuery>>[] = [query]
|
|
20
18
|
|
|
21
19
|
const { data } = await query
|
|
22
|
-
const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize)
|
|
20
|
+
const totalPages = data ? Math.ceil(data.pagesConnection.aggregate.count / pageSize) : 1
|
|
21
|
+
|
|
22
|
+
const pages = [query]
|
|
23
23
|
|
|
24
24
|
if (totalPages > 1) {
|
|
25
25
|
for (let i = 2; i <= totalPages; i++) {
|
|
@@ -33,9 +33,10 @@ export async function getHygraphStaticPaths(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const paths: Return['paths'] = (await Promise.all(pages))
|
|
36
|
-
.map((q) => q.data
|
|
36
|
+
.map((q) => q.data?.pages ?? [])
|
|
37
37
|
.flat(1)
|
|
38
|
-
.
|
|
38
|
+
.filter((page): page is NonNullable<typeof page> & { url: string } => !!page?.url)
|
|
39
|
+
.map((page) => ({ params: { url: page.url }, locale }))
|
|
39
40
|
|
|
40
41
|
return paths
|
|
41
42
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApolloClient
|
|
1
|
+
import type { ApolloClient } from '@graphcommerce/graphql'
|
|
2
2
|
import type { HygraphPagesQuery } from '../graphql'
|
|
3
3
|
import { HygraphPagesDocument } from '../graphql'
|
|
4
4
|
import { getAllHygraphPages } from './getAllHygraphPages'
|
|
@@ -10,7 +10,7 @@ import { getAllHygraphPages } from './getAllHygraphPages'
|
|
|
10
10
|
* - Implements an alias sytem to merge the content of multiple pages.
|
|
11
11
|
*/
|
|
12
12
|
async function pageContent(
|
|
13
|
-
client: ApolloClient
|
|
13
|
+
client: ApolloClient,
|
|
14
14
|
url: string,
|
|
15
15
|
cached: boolean,
|
|
16
16
|
): Promise<{ data: HygraphPagesQuery }> {
|
|
@@ -34,13 +34,20 @@ async function pageContent(
|
|
|
34
34
|
// Only do the query when there the page is found in the allRoutes
|
|
35
35
|
const found = allRoutes.some((page) => page.url === url)
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (found) {
|
|
38
|
+
const result = await client.query({
|
|
39
|
+
query: HygraphPagesDocument,
|
|
40
|
+
variables: { url },
|
|
41
|
+
fetchPolicy,
|
|
42
|
+
})
|
|
43
|
+
return { data: result.data ?? { pages: [] } }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { data: { pages: [] } }
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
export async function hygraphPageContent(
|
|
43
|
-
client: ApolloClient
|
|
50
|
+
client: ApolloClient,
|
|
44
51
|
url: string,
|
|
45
52
|
additionalProperties?: Promise<object> | object,
|
|
46
53
|
cached = false,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/hygraph-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "10.0.0-canary.
|
|
5
|
+
"version": "10.0.0-canary.72",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/ecommerce-ui": "^10.0.0-canary.
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^10.0.0-canary.
|
|
17
|
-
"@graphcommerce/graphql": "^10.0.0-canary.
|
|
18
|
-
"@graphcommerce/image": "^10.0.0-canary.
|
|
19
|
-
"@graphcommerce/next-ui": "^10.0.0-canary.
|
|
20
|
-
"@graphcommerce/prettier-config-pwa": "^10.0.0-canary.
|
|
21
|
-
"@graphcommerce/typescript-config-pwa": "^10.0.0-canary.
|
|
22
|
-
"@mui/material": "^
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^10.0.0-canary.72",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^10.0.0-canary.72",
|
|
17
|
+
"@graphcommerce/graphql": "^10.0.0-canary.72",
|
|
18
|
+
"@graphcommerce/image": "^10.0.0-canary.72",
|
|
19
|
+
"@graphcommerce/next-ui": "^10.0.0-canary.72",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "^10.0.0-canary.72",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "^10.0.0-canary.72",
|
|
22
|
+
"@mui/material": "^7.0.0",
|
|
23
23
|
"next": "*",
|
|
24
24
|
"react": "^19.2.0",
|
|
25
25
|
"react-dom": "^19.2.0"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { graphqlConfig as graphqlConfigType } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
2
|
+
import { SetContextLink } from '@graphcommerce/graphql'
|
|
3
3
|
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
4
4
|
|
|
5
5
|
export const config: PluginConfig = {
|
|
@@ -18,16 +18,16 @@ export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, co
|
|
|
18
18
|
|
|
19
19
|
const locales = conf.storefront.hygraphLocales
|
|
20
20
|
|
|
21
|
-
const hygraphLink =
|
|
22
|
-
|
|
23
|
-
if (locales)
|
|
21
|
+
const hygraphLink = new SetContextLink((prevContext) => {
|
|
22
|
+
const headers: Record<string, string> = { ...prevContext.headers }
|
|
23
|
+
if (locales) headers['gcms-locales'] = locales.join(',')
|
|
24
24
|
|
|
25
25
|
const stage = conf.previewData?.hygraphStage ?? 'DRAFT'
|
|
26
26
|
if (conf.preview) {
|
|
27
|
-
|
|
27
|
+
headers['gcms-stage'] = stage
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
return
|
|
30
|
+
return { headers }
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
return { ...results, links: [...results.links, hygraphLink] }
|