@graphcommerce/graphcms-ui 8.1.0-canary.9 → 9.0.0-canary.101

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,11 +1,210 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.101
4
+
5
+ ## 9.0.0-canary.100
6
+
7
+ ## 9.0.0-canary.99
8
+
9
+ ## 9.0.0-canary.98
10
+
11
+ ## 9.0.0-canary.97
12
+
13
+ ## 9.0.0-canary.96
14
+
15
+ ## 9.0.0-canary.95
16
+
17
+ ## 9.0.0-canary.94
18
+
19
+ ### Patch Changes
20
+
21
+ - [#2400](https://github.com/graphcommerce-org/graphcommerce/pull/2400) [`f9f7276`](https://github.com/graphcommerce-org/graphcommerce/commit/f9f7276501127ba8dbb31b6a9670d7f62647573a) - Remove ‘up’ data from the blogoverview page. ([@carlocarels90](https://github.com/carlocarels90))
22
+
23
+ ## 9.0.0-canary.93
24
+
25
+ ## 9.0.0-canary.92
26
+
27
+ ## 9.0.0-canary.91
28
+
29
+ ### Patch Changes
30
+
31
+ - [#2384](https://github.com/graphcommerce-org/graphcommerce/pull/2384) [`d7c293a`](https://github.com/graphcommerce-org/graphcommerce/commit/d7c293aa49be39f499b46ea57bfda4dbdf67ebe6) - feat(GCOM-1494: Add support for linebreaks in Hygraph content ) ([@FrankHarland](https://github.com/FrankHarland))
32
+
33
+ ## 9.0.0-canary.90
34
+
35
+ ## 9.0.0-canary.89
36
+
37
+ ## 9.0.0-canary.88
38
+
39
+ ## 9.0.0-canary.87
40
+
41
+ ## 9.0.0-canary.86
42
+
43
+ ## 9.0.0-canary.85
44
+
45
+ ## 9.0.0-canary.84
46
+
47
+ ## 9.0.0-canary.83
48
+
49
+ ## 9.0.0-canary.82
50
+
51
+ ## 9.0.0-canary.81
52
+
53
+ ## 9.0.0-canary.80
54
+
55
+ ## 9.0.0-canary.79
56
+
57
+ ## 9.0.0-canary.78
58
+
59
+ ## 9.0.0-canary.77
60
+
61
+ ## 9.0.0-canary.76
62
+
63
+ ## 9.0.0-canary.75
64
+
65
+ ## 9.0.0-canary.74
66
+
67
+ ## 9.0.0-canary.73
68
+
69
+ ## 9.0.0-canary.72
70
+
71
+ ## 9.0.0-canary.71
72
+
73
+ ## 9.0.0-canary.70
74
+
75
+ ## 9.0.0-canary.69
76
+
77
+ ## 9.0.0-canary.68
78
+
79
+ ## 9.0.0-canary.67
80
+
81
+ ## 9.0.0-canary.66
82
+
83
+ ## 9.0.0-canary.65
84
+
85
+ ## 9.0.0-canary.64
86
+
87
+ ## 9.0.0-canary.63
88
+
89
+ ## 9.0.0-canary.62
90
+
91
+ ## 9.0.0-canary.61
92
+
93
+ ## 9.0.0-canary.60
94
+
95
+ ### Patch Changes
96
+
97
+ - [#2331](https://github.com/graphcommerce-org/graphcommerce/pull/2331) [`702bfc9`](https://github.com/graphcommerce-org/graphcommerce/commit/702bfc93566c9745546988e57988431d5d4d8cb0) - Moved plugins to new format ([@paales](https://github.com/paales))
98
+
99
+ ## 9.0.0-canary.59
100
+
101
+ ## 9.0.0-canary.58
102
+
103
+ ## 9.0.0-canary.57
104
+
105
+ ## 9.0.0-canary.56
106
+
107
+ ## 9.0.0-canary.55
108
+
109
+ ## 9.0.0-canary.54
110
+
111
+ ## 8.1.0-canary.53
112
+
113
+ ## 8.1.0-canary.52
114
+
115
+ ## 8.1.0-canary.51
116
+
117
+ ## 8.1.0-canary.50
118
+
119
+ ## 8.1.0-canary.49
120
+
121
+ ## 8.1.0-canary.48
122
+
123
+ ## 8.1.0-canary.47
124
+
125
+ ## 8.1.0-canary.46
126
+
127
+ ## 8.1.0-canary.45
128
+
129
+ ## 8.1.0-canary.44
130
+
131
+ ## 8.1.0-canary.43
132
+
133
+ ## 8.1.0-canary.42
134
+
135
+ ### Patch Changes
136
+
137
+ - [#2308](https://github.com/graphcommerce-org/graphcommerce/pull/2308) [`8faa5ac`](https://github.com/graphcommerce-org/graphcommerce/commit/8faa5ac618ecfdacd6d5eb751b4110c423aef97f) - Added Draft Mode support. When enabled it will be shown. ([@paales](https://github.com/paales))
138
+
139
+ ## 8.1.0-canary.41
140
+
141
+ ## 8.1.0-canary.40
142
+
143
+ ## 8.1.0-canary.39
144
+
145
+ ## 8.1.0-canary.38
146
+
147
+ ## 8.1.0-canary.37
148
+
149
+ ## 8.1.0-canary.36
150
+
151
+ ## 8.1.0-canary.35
152
+
153
+ ## 8.1.0-canary.34
154
+
155
+ ## 8.1.0-canary.33
156
+
157
+ ## 8.1.0-canary.32
158
+
159
+ ## 8.1.0-canary.31
160
+
161
+ ## 8.1.0-canary.30
162
+
163
+ ## 8.1.0-canary.29
164
+
165
+ ## 8.1.0-canary.28
166
+
167
+ ## 8.1.0-canary.27
168
+
169
+ ## 8.1.0-canary.26
170
+
171
+ ## 8.1.0-canary.25
172
+
173
+ ## 8.1.0-canary.24
174
+
175
+ ## 8.1.0-canary.23
176
+
177
+ ## 8.1.0-canary.22
178
+
179
+ ## 8.1.0-canary.21
180
+
181
+ ## 8.1.0-canary.20
182
+
183
+ ## 8.1.0-canary.19
184
+
185
+ ## 8.1.0-canary.18
186
+
187
+ ## 8.1.0-canary.17
188
+
189
+ ## 8.1.0-canary.16
190
+
191
+ ## 8.1.0-canary.15
192
+
193
+ ## 8.1.0-canary.14
194
+
195
+ ## 8.1.0-canary.13
196
+
197
+ ## 8.1.0-canary.12
198
+
199
+ ## 8.1.0-canary.11
200
+
201
+ ## 8.1.0-canary.10
202
+
3
203
  ## 8.1.0-canary.9
4
204
 
5
205
  ### Patch Changes
6
206
 
7
- - [#2223](https://github.com/graphcommerce-org/graphcommerce/pull/2223) [`0ccec63`](https://github.com/graphcommerce-org/graphcommerce/commit/0ccec630825d5fad398366beae90b3c90b2f84b8) - Added helper method to get Hygraph paths
8
- ([@bramvanderholst](https://github.com/bramvanderholst))
207
+ - [#2223](https://github.com/graphcommerce-org/graphcommerce/pull/2223) [`0ccec63`](https://github.com/graphcommerce-org/graphcommerce/commit/0ccec630825d5fad398366beae90b3c90b2f84b8) - Added helper method to get Hygraph paths ([@bramvanderholst](https://github.com/bramvanderholst))
9
208
 
10
209
  ## 8.1.0-canary.8
11
210
 
@@ -21,8 +220,7 @@
21
220
 
22
221
  ### Patch Changes
23
222
 
24
- - [#2219](https://github.com/graphcommerce-org/graphcommerce/pull/2219) [`2ed2055`](https://github.com/graphcommerce-org/graphcommerce/commit/2ed20550324c104265d72f22339fbedb26fb433b) - Allow blog pages to be nested
25
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
223
+ - [#2219](https://github.com/graphcommerce-org/graphcommerce/pull/2219) [`2ed2055`](https://github.com/graphcommerce-org/graphcommerce/commit/2ed20550324c104265d72f22339fbedb26fb433b) - Allow blog pages to be nested ([@Jessevdpoel](https://github.com/Jessevdpoel))
26
224
 
27
225
  ## 8.0.6-canary.2
28
226
 
@@ -34,8 +232,7 @@
34
232
 
35
233
  ### Patch Changes
36
234
 
37
- - [#2238](https://github.com/graphcommerce-org/graphcommerce/pull/2238) [`db86432`](https://github.com/graphcommerce-org/graphcommerce/commit/db864324277fd5fb680c66eaa87d211cd7be4905) - Changed query limit to 100 from a 1000 on HygraphAllPages and AllDynamicRows query and added pagination.
38
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
235
+ - [#2238](https://github.com/graphcommerce-org/graphcommerce/pull/2238) [`db86432`](https://github.com/graphcommerce-org/graphcommerce/commit/db864324277fd5fb680c66eaa87d211cd7be4905) - Changed query limit to 100 from a 1000 on HygraphAllPages and AllDynamicRows query and added pagination. ([@Jessevdpoel](https://github.com/Jessevdpoel))
39
236
 
40
237
  ## 8.0.5-canary.10
41
238
 
@@ -43,8 +240,7 @@
43
240
 
44
241
  ### Patch Changes
45
242
 
46
- - [#2238](https://github.com/graphcommerce-org/graphcommerce/pull/2238) [`db86432`](https://github.com/graphcommerce-org/graphcommerce/commit/db864324277fd5fb680c66eaa87d211cd7be4905) - Changed query limit to 100 from a 1000 on HygraphAllPages and AllDynamicRows query and added pagination.
47
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
243
+ - [#2238](https://github.com/graphcommerce-org/graphcommerce/pull/2238) [`db86432`](https://github.com/graphcommerce-org/graphcommerce/commit/db864324277fd5fb680c66eaa87d211cd7be4905) - Changed query limit to 100 from a 1000 on HygraphAllPages and AllDynamicRows query and added pagination. ([@Jessevdpoel](https://github.com/Jessevdpoel))
48
244
 
49
245
  ## 8.0.5-canary.8
50
246
 
@@ -112,11 +308,9 @@
112
308
 
113
309
  ### Patch Changes
114
310
 
115
- - [#2114](https://github.com/graphcommerce-org/graphcommerce/pull/2114) [`5b63623`](https://github.com/graphcommerce-org/graphcommerce/commit/5b63623e70cb72afa82f6e39cefc77c7b0fec74e) - Added support for the alt attribute for images inside Rich text areas coming from Hygraph.
116
- ([@StefanAngenent](https://github.com/StefanAngenent))
311
+ - [#2114](https://github.com/graphcommerce-org/graphcommerce/pull/2114) [`5b63623`](https://github.com/graphcommerce-org/graphcommerce/commit/5b63623e70cb72afa82f6e39cefc77c7b0fec74e) - Added support for the alt attribute for images inside Rich text areas coming from Hygraph. ([@StefanAngenent](https://github.com/StefanAngenent))
117
312
 
118
- - [#2071](https://github.com/graphcommerce-org/graphcommerce/pull/2071) [`6876939`](https://github.com/graphcommerce-org/graphcommerce/commit/68769398f64604443a148583f1392976f71c2423) - Added support to add css class names to RichText elements from Hygraph
119
- ([@FrankHarland](https://github.com/FrankHarland))
313
+ - [#2071](https://github.com/graphcommerce-org/graphcommerce/pull/2071) [`6876939`](https://github.com/graphcommerce-org/graphcommerce/commit/68769398f64604443a148583f1392976f71c2423) - Added support to add css class names to RichText elements from Hygraph ([@FrankHarland](https://github.com/FrankHarland))
120
314
 
121
315
  ## 8.0.0-canary.100
122
316
 
@@ -1,4 +1,4 @@
1
- fragment Asset on Asset @injectable {
1
+ fragment Asset on Asset {
2
2
  url
3
3
  width
4
4
  height
@@ -1,5 +1,6 @@
1
1
  import { Image, ImageProps } from '@graphcommerce/image'
2
2
  import { styled, SxProps, Theme } from '@mui/material'
3
+ import { memo } from 'react'
3
4
  import { AssetFragment } from './Asset.gql'
4
5
 
5
6
  export type { AssetFragment } from './Asset.gql'
@@ -18,7 +19,7 @@ type AssetProps = {
18
19
  sx?: SxProps<Theme>
19
20
  } & Omit<ImageProps, 'src' | 'width' | 'height' | 'alt' | 'sx'>
20
21
 
21
- export function Asset(props: AssetProps) {
22
+ export const Asset = memo<AssetProps>((props) => {
22
23
  const { asset, sx = [], ...imgProps } = props
23
24
 
24
25
  if (isImage(asset)) {
@@ -55,4 +56,4 @@ export function Asset(props: AssetProps) {
55
56
 
56
57
  if (process.env.NODE_ENV !== 'production') return <div>{asset.mimeType} not supported</div>
57
58
  return null
58
- }
59
+ })
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
2
  import { SxProps, Theme } from '@mui/material'
3
+ import React from 'react'
3
4
  import { defaultRenderers } from './defaultRenderers'
4
5
  import { defaultSxRenderer } from './defaultSxRenderer'
5
6
  import {
@@ -33,6 +34,20 @@ function useRenderProps(
33
34
  ]
34
35
  }
35
36
 
37
+ function LineBreakToBr(props: { text: string }) {
38
+ const { text } = props
39
+
40
+ const textA = text.split('\n')
41
+ const textArray: React.ReactNode[] = []
42
+ textA.forEach((val, index) => {
43
+ textArray.push(val)
44
+ if (index < textA.length - 1) textArray.push(<br />)
45
+ })
46
+
47
+ // eslint-disable-next-line react/no-array-index-key
48
+ return textArray.map((val, idx) => <React.Fragment key={idx}>{val}</React.Fragment>)
49
+ }
50
+
36
51
  function RenderText({
37
52
  text,
38
53
  renderers,
@@ -49,11 +64,13 @@ function RenderText({
49
64
 
50
65
  const sx = useRenderProps({ first, last, sxRenderer }, type)
51
66
 
52
- if (!type) return <>{text}</>
53
-
67
+ if (!type) return <LineBreakToBr text={text} />
54
68
  const Component: Renderer<SimpleElement> = renderers[type]
55
-
56
- return <Component sx={sx}>{text}</Component>
69
+ return (
70
+ <Component sx={sx}>
71
+ <LineBreakToBr text={text} />
72
+ </Component>
73
+ )
57
74
  }
58
75
 
59
76
  export function isTextNode(node: ElementOrTextNode): node is TextNode {
@@ -1,4 +1,4 @@
1
- fragment HygraphPage on Page @injectable {
1
+ fragment HygraphPage on Page {
2
2
  title
3
3
  metaTitle
4
4
  metaDescription
@@ -1,4 +1,4 @@
1
- fragment PageLink on PageLink @injectable {
1
+ fragment PageLink on PageLink {
2
2
  title
3
3
  url
4
4
  description {
package/index.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './components'
2
2
  export * from './graphql'
3
3
  export * from './lib'
4
- export * from './links/createHygraphLink'
@@ -1,4 +1,5 @@
1
1
  import type { ApolloClient, NormalizedCacheObject, ApolloQueryResult } from '@apollo/client'
2
+ import { cacheFirst } from '@graphcommerce/graphql'
2
3
  import { HygraphAllPagesDocument, HygraphAllPagesQuery } from '../graphql'
3
4
 
4
5
  type Urls = { url: string }
@@ -8,10 +9,11 @@ export async function getAllHygraphPages(
8
9
  options: { pageSize?: number } = {},
9
10
  ) {
10
11
  const { pageSize = 100 } = options
12
+
11
13
  const query = client.query({
12
14
  query: HygraphAllPagesDocument,
13
15
  variables: { first: pageSize },
14
- fetchPolicy: process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined,
16
+ fetchPolicy: cacheFirst(client),
15
17
  })
16
18
  const pages: Promise<ApolloQueryResult<HygraphAllPagesQuery>>[] = [query]
17
19
 
@@ -24,7 +26,7 @@ export async function getAllHygraphPages(
24
26
  client.query({
25
27
  query: HygraphAllPagesDocument,
26
28
  variables: { first: pageSize, skip: pageSize * (i - 1) },
27
- fetchPolicy: process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined,
29
+ fetchPolicy: cacheFirst(client),
28
30
  }),
29
31
  )
30
32
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/graphcms-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.1.0-canary.9",
5
+ "version": "9.0.0-canary.101",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,12 +12,13 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.9",
16
- "@graphcommerce/graphql": "^8.1.0-canary.9",
17
- "@graphcommerce/image": "^8.1.0-canary.9",
18
- "@graphcommerce/next-ui": "^8.1.0-canary.9",
19
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.9",
20
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.9",
15
+ "@graphcommerce/ecommerce-ui": "^9.0.0-canary.101",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.101",
17
+ "@graphcommerce/graphql": "^9.0.0-canary.101",
18
+ "@graphcommerce/image": "^9.0.0-canary.101",
19
+ "@graphcommerce/next-ui": "^9.0.0-canary.101",
20
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.101",
21
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.101",
21
22
  "@mui/material": "^5.10.16",
22
23
  "next": "*",
23
24
  "react": "^18.2.0",
@@ -0,0 +1,83 @@
1
+ import {
2
+ usePreviewModeForm,
3
+ type PreviewModeToolbarProps,
4
+ SelectElement,
5
+ previewModeDefaults,
6
+ useWatch,
7
+ } from '@graphcommerce/ecommerce-ui'
8
+ import { TypedDocumentNode, gql, useQuery } from '@graphcommerce/graphql'
9
+ import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
10
+ import { filterNonNullableKeys } from '@graphcommerce/next-ui'
11
+ import React, { useMemo } from 'react'
12
+
13
+ export const config: PluginConfig = {
14
+ type: 'component',
15
+ module: '@graphcommerce/ecommerce-ui',
16
+ }
17
+
18
+ const ContentStages = gql`
19
+ query {
20
+ __type(name: "Stage") {
21
+ name
22
+ enumValues {
23
+ name
24
+ description
25
+ }
26
+ }
27
+ }
28
+ ` as TypedDocumentNode<{
29
+ __type: {
30
+ name: 'Stage'
31
+ enumValues: {
32
+ name: string
33
+ description: string
34
+ }[]
35
+ }
36
+ }>
37
+
38
+ const HygraphConfig = React.memo(() => {
39
+ const form = usePreviewModeForm()
40
+ const { control } = form
41
+
42
+ const contentStages = useQuery(ContentStages)
43
+
44
+ const defaultValue =
45
+ useWatch({ control, name: 'previewData.hygraphStage' }) ??
46
+ previewModeDefaults().hygraphStage ??
47
+ 'PUBLISHED'
48
+
49
+ return useMemo(
50
+ () => (
51
+ <SelectElement
52
+ control={control}
53
+ name='previewData.hygraphStage'
54
+ color='secondary'
55
+ defaultValue={defaultValue}
56
+ label='Hygraph Stage'
57
+ size='small'
58
+ sx={{ width: '150px' }}
59
+ SelectProps={{ MenuProps: { style: { zIndex: 20000 } } }}
60
+ onChange={() => {}}
61
+ options={
62
+ contentStages.loading
63
+ ? [{ id: defaultValue, label: defaultValue }]
64
+ : filterNonNullableKeys(contentStages.data?.__type.enumValues).map(({ name }) => ({
65
+ id: name,
66
+ label: name,
67
+ }))
68
+ }
69
+ />
70
+ ),
71
+ [contentStages.data?.__type.enumValues, contentStages.loading, control, defaultValue],
72
+ )
73
+ })
74
+
75
+ export const PreviewModeToolbar = (props: PluginProps<PreviewModeToolbarProps>) => {
76
+ const { Prev, ...rest } = props
77
+ return (
78
+ <>
79
+ <Prev {...rest} />
80
+ <HygraphConfig />
81
+ </>
82
+ )
83
+ }
@@ -1,10 +1,18 @@
1
- import { graphqlConfig, setContext } from '@graphcommerce/graphql'
2
- import type { FunctionPlugin } from '@graphcommerce/next-config'
1
+ import { graphqlConfig as graphqlConfigType, setContext } from '@graphcommerce/graphql'
2
+ import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
3
3
 
4
- export const func = 'graphqlConfig'
5
- export const exported = '@graphcommerce/graphql'
4
+ export const config: PluginConfig = {
5
+ type: 'function',
6
+ module: '@graphcommerce/graphql',
7
+ }
8
+
9
+ declare module '@graphcommerce/graphql/config' {
10
+ interface PreviewData {
11
+ hygraphStage?: string
12
+ }
13
+ }
6
14
 
7
- const hygraphGraphqlConfig: FunctionPlugin<typeof graphqlConfig> = (prev, config) => {
15
+ export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, config) => {
8
16
  const results = prev(config)
9
17
 
10
18
  const locales = config.storefront.hygraphLocales
@@ -14,10 +22,14 @@ const hygraphGraphqlConfig: FunctionPlugin<typeof graphqlConfig> = (prev, config
14
22
  const hygraphLink = setContext((_, context) => {
15
23
  if (!context.headers) context.headers = {}
16
24
  context.headers['gcms-locales'] = locales.join(',')
25
+
26
+ const stage = config.previewData?.hygraphStage ?? 'DRAFT'
27
+ if (config.preview) {
28
+ context.headers['gcms-stage'] = stage
29
+ }
30
+
17
31
  return context
18
32
  })
19
33
 
20
34
  return { ...results, links: [...results.links, hygraphLink] }
21
35
  }
22
-
23
- export const plugin = hygraphGraphqlConfig
@@ -0,0 +1,12 @@
1
+ import { previewModeDefaults as base } from '@graphcommerce/ecommerce-ui'
2
+ import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
3
+
4
+ export const config: PluginConfig = {
5
+ type: 'function',
6
+ module: '@graphcommerce/ecommerce-ui',
7
+ }
8
+
9
+ export const previewModeDefaults: FunctionPlugin<typeof base> = (prev, ...args) => ({
10
+ ...prev(...args),
11
+ hygraphStage: 'DRAFT',
12
+ })
@@ -1,13 +0,0 @@
1
- import { setContext } from '@graphcommerce/graphql'
2
- import { storefrontConfig } from '@graphcommerce/next-ui'
3
-
4
- /** Add a gcms-locales header to make sure queries return in a certain language. */
5
- export const createHygraphLink = (locale?: string) =>
6
- setContext((_, context) => {
7
- if (!context.headers) context.headers = {}
8
-
9
- const locales = storefrontConfig(locale)?.hygraphLocales
10
- if (locales) context.headers['gcms-locales'] = locales.join(',')
11
-
12
- return context
13
- })