@graphcommerce/graphcms-ui 2.106.39 → 3.0.2

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,158 +1,194 @@
1
1
  # Change Log
2
2
 
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
3
+ ## 3.0.2
5
4
 
6
- ## [2.106.12](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.106.11...@graphcommerce/graphcms-ui@2.106.12) (2021-12-17)
5
+ ### Patch Changes
7
6
 
7
+ - [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
8
+ [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2)
9
+ Thanks [@paales](https://github.com/paales)! - We've moved lots of internal packages from
10
+ `dependencies` to `peerDependencies`. The result of this is that there will be significantly less
11
+ duplicate packages in the node_modules folders.
8
12
 
9
- ### Bug Fixes
13
+ * [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
14
+ [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)
15
+ Thanks [@paales](https://github.com/paales)! - Upgraded to
16
+ [NextJS 12.1](https://nextjs.org/blog/next-12-1)! This is just for compatibility, but we'll be
17
+ implementing
18
+ [On-demand Incremental Static Regeneration](https://nextjs.org/blog/next-12-1#on-demand-incremental-static-regeneration-beta)
19
+ soon.
10
20
 
11
- * make sure we're able to render table_header_cell and do not throw when rendering unknown elements in production ([f7b7972](https://github.com/ho-nl/m2-pwa/commit/f7b797272f5765801c3f2e217fa9905f65dbe6d6))
21
+ This will greatly reduce the requirement to rebuid stuff and we'll add a management UI on the
22
+ frontend to be able to revalidate pages manually.
12
23
 
24
+ * Updated dependencies
25
+ [[`381e4c86a`](https://github.com/ho-nl/m2-pwa/commit/381e4c86a8321ce96e1fa5c7d3c0a0c0ff3e02c7),
26
+ [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2),
27
+ [`e7c8e2756`](https://github.com/ho-nl/m2-pwa/commit/e7c8e2756d637cbcd2e793d62ef5721d35d9fa7b),
28
+ [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)]:
29
+ - @graphcommerce/next-ui@4.1.1
30
+ - @graphcommerce/graphql@3.0.2
31
+ - @graphcommerce/image@3.0.2
13
32
 
33
+ ## 3.0.1
14
34
 
35
+ ### Patch Changes
15
36
 
37
+ - [`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)
38
+ Thanks [@paales](https://github.com/paales)! - Added homepage and repository package.json files,
39
+ so that the packages link to back to the website and repository
40
+ - Updated dependencies
41
+ [[`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)]:
42
+ - @graphcommerce/graphql@3.0.1
43
+ - @graphcommerce/image@3.0.1
44
+ - @graphcommerce/next-ui@4.0.1
16
45
 
17
- # [2.106.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.105.4...@graphcommerce/graphcms-ui@2.106.0) (2021-12-01)
46
+ ## 3.0.0
18
47
 
48
+ ### Major Changes
19
49
 
20
- ### Bug Fixes
50
+ - [#1258](https://github.com/ho-nl/m2-pwa/pull/1258)
51
+ [`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)
52
+ Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
21
53
 
22
- * build ([72d9353](https://github.com/ho-nl/m2-pwa/commit/72d935376a1967cc976c20b984ef15a862e5d0f4))
23
- * fontWeights ([7172527](https://github.com/ho-nl/m2-pwa/commit/71725272fe9f0b854d918ae357a668f641bfe8e5))
24
- * hero text spacing ([79dd6aa](https://github.com/ho-nl/m2-pwa/commit/79dd6aa2fe576104ebbbdd092f6b415d319dec48))
25
- * render bug stroke variable fonts ([582de18](https://github.com/ho-nl/m2-pwa/commit/582de187800ee9c53718bf43a39ca77398d21b91)), closes [/github.com/rsms/inter/issues/292#issuecomment-674993644](https://github.com//github.com/rsms/inter/issues/292/issues/issuecomment-674993644)
54
+ ### Patch Changes
26
55
 
56
+ - Updated dependencies
57
+ [[`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)]:
58
+ - @graphcommerce/graphql@3.0.0
59
+ - @graphcommerce/image@3.0.0
60
+ - @graphcommerce/next-ui@4.0.0
27
61
 
28
- ### Features
29
-
30
- * breakpointVal ([0294503](https://github.com/ho-nl/m2-pwa/commit/029450343051cf6995babad9f9b42c7e6ad1094e))
31
- * responsiveTyp ([6108b61](https://github.com/ho-nl/m2-pwa/commit/6108b6148e76ddbbe2db1614f10aaf88423db5ca))
62
+ All notable changes to this project will be documented in this file. See
63
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
32
64
 
65
+ ## [2.106.12](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.106.11...@graphcommerce/graphcms-ui@2.106.12) (2021-12-17)
33
66
 
67
+ ### Bug Fixes
34
68
 
69
+ - make sure we're able to render table_header_cell and do not throw when rendering unknown elements
70
+ in production
71
+ ([f7b7972](https://github.com/ho-nl/m2-pwa/commit/f7b797272f5765801c3f2e217fa9905f65dbe6d6))
35
72
 
73
+ # [2.106.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.105.4...@graphcommerce/graphcms-ui@2.106.0) (2021-12-01)
36
74
 
37
- # [2.105.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.29...@graphcommerce/graphcms-ui@2.105.0) (2021-11-12)
75
+ ### Bug Fixes
38
76
 
77
+ - build ([72d9353](https://github.com/ho-nl/m2-pwa/commit/72d935376a1967cc976c20b984ef15a862e5d0f4))
78
+ - fontWeights
79
+ ([7172527](https://github.com/ho-nl/m2-pwa/commit/71725272fe9f0b854d918ae357a668f641bfe8e5))
80
+ - hero text spacing
81
+ ([79dd6aa](https://github.com/ho-nl/m2-pwa/commit/79dd6aa2fe576104ebbbdd092f6b415d319dec48))
82
+ - render bug stroke variable fonts
83
+ ([582de18](https://github.com/ho-nl/m2-pwa/commit/582de187800ee9c53718bf43a39ca77398d21b91)),
84
+ closes
85
+ [/github.com/rsms/inter/issues/292#issuecomment-674993644](https://github.com//github.com/rsms/inter/issues/292/issues/issuecomment-674993644)
39
86
 
40
87
  ### Features
41
88
 
42
- * added tons of translations ([9bb0ac7](https://github.com/ho-nl/m2-pwa/commit/9bb0ac709b58df6ea6141e92e4923a5ca9ae2963))
43
-
89
+ - breakpointVal
90
+ ([0294503](https://github.com/ho-nl/m2-pwa/commit/029450343051cf6995babad9f9b42c7e6ad1094e))
91
+ - responsiveTyp
92
+ ([6108b61](https://github.com/ho-nl/m2-pwa/commit/6108b6148e76ddbbe2db1614f10aaf88423db5ca))
44
93
 
94
+ # [2.105.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.29...@graphcommerce/graphcms-ui@2.105.0) (2021-11-12)
45
95
 
96
+ ### Features
46
97
 
98
+ - added tons of translations
99
+ ([9bb0ac7](https://github.com/ho-nl/m2-pwa/commit/9bb0ac709b58df6ea6141e92e4923a5ca9ae2963))
47
100
 
48
101
  ## [2.104.29](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.28...@graphcommerce/graphcms-ui@2.104.29) (2021-11-12)
49
102
 
50
-
51
103
  ### Bug Fixes
52
104
 
53
- * must have smaller sizes for mobile ([34cf81e](https://github.com/ho-nl/m2-pwa/commit/34cf81eed6c5996f70be8b2c10888e44fad4d57f))
54
-
55
-
56
-
57
-
105
+ - must have smaller sizes for mobile
106
+ ([34cf81e](https://github.com/ho-nl/m2-pwa/commit/34cf81eed6c5996f70be8b2c10888e44fad4d57f))
58
107
 
59
108
  ## [2.104.18](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.17...@graphcommerce/graphcms-ui@2.104.18) (2021-11-04)
60
109
 
61
-
62
110
  ### Bug Fixes
63
111
 
64
- * remove hardcoded fontSize ([e4e09e1](https://github.com/ho-nl/m2-pwa/commit/e4e09e11baeb8edeff634550b8cdb88571d96911))
65
-
66
-
67
-
68
-
112
+ - remove hardcoded fontSize
113
+ ([e4e09e1](https://github.com/ho-nl/m2-pwa/commit/e4e09e11baeb8edeff634550b8cdb88571d96911))
69
114
 
70
115
  ## [2.104.16](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.15...@graphcommerce/graphcms-ui@2.104.16) (2021-11-03)
71
116
 
72
-
73
117
  ### Bug Fixes
74
118
 
75
- * various accessibility improvements ([47481a9](https://github.com/ho-nl/m2-pwa/commit/47481a9a882ba87968de6dd797557b0b275d75fb))
76
-
77
-
78
-
79
-
119
+ - various accessibility improvements
120
+ ([47481a9](https://github.com/ho-nl/m2-pwa/commit/47481a9a882ba87968de6dd797557b0b275d75fb))
80
121
 
81
122
  ## [2.104.9](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.8...@graphcommerce/graphcms-ui@2.104.9) (2021-11-02)
82
123
 
83
-
84
124
  ### Bug Fixes
85
125
 
86
- * color from palette ([283cca1](https://github.com/ho-nl/m2-pwa/commit/283cca169ec00cbac8b973e14e6b77a443e26c99))
87
- * darkMode ([c7573de](https://github.com/ho-nl/m2-pwa/commit/c7573de6bb80643b26931c35ac61735539e7fbf0))
88
-
89
-
90
-
91
-
126
+ - color from palette
127
+ ([283cca1](https://github.com/ho-nl/m2-pwa/commit/283cca169ec00cbac8b973e14e6b77a443e26c99))
128
+ - darkMode
129
+ ([c7573de](https://github.com/ho-nl/m2-pwa/commit/c7573de6bb80643b26931c35ac61735539e7fbf0))
92
130
 
93
131
  ## [2.104.3](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.104.2...@graphcommerce/graphcms-ui@2.104.3) (2021-10-28)
94
132
 
95
-
96
133
  ### Bug Fixes
97
134
 
98
- * default heading margins for CMS content ([ac7c24f](https://github.com/ho-nl/m2-pwa/commit/ac7c24f731abf9573ad93d534d84b9f7c1b16a2b))
99
-
100
-
101
-
102
-
135
+ - default heading margins for CMS content
136
+ ([ac7c24f](https://github.com/ho-nl/m2-pwa/commit/ac7c24f731abf9573ad93d534d84b9f7c1b16a2b))
103
137
 
104
138
  # [2.104.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.103.30...@graphcommerce/graphcms-ui@2.104.0) (2021-10-27)
105
139
 
106
-
107
140
  ### Features
108
141
 
109
- * **nextjs:** upgraded to nextjs 12 ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
110
-
111
-
112
-
113
-
142
+ - **nextjs:** upgraded to nextjs 12
143
+ ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
114
144
 
115
145
  ## [2.103.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphcms-ui@2.103.0...@graphcommerce/graphcms-ui@2.103.1) (2021-09-27)
116
146
 
117
147
  **Note:** Version bump only for package @graphcommerce/graphcms-ui
118
148
 
119
-
120
-
121
-
122
-
123
149
  # 2.103.0 (2021-09-27)
124
150
 
125
-
126
151
  ### Bug Fixes
127
152
 
128
- * ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
129
- * implement next-ui barrel imports ([75bea70](https://github.com/ho-nl/m2-pwa/commit/75bea703dba898f18a2a1dfa3243ebd0a4e6f0e1))
130
- * narrow quote on mobile ([e06ccc2](https://github.com/ho-nl/m2-pwa/commit/e06ccc25048124431dcdb786f1719f688a5e429c))
131
- * remove conflicting files ([0c17ae4](https://github.com/ho-nl/m2-pwa/commit/0c17ae46be62b775ac83b35f11c532ce2d9401a3))
132
- * since all links are of next/link we need to add passHref for custom components ([16fb931](https://github.com/ho-nl/m2-pwa/commit/16fb93100d367203ea79bb4f93357221253f2ecd))
133
-
153
+ - ignore md files from triggering version updates
154
+ ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
155
+ - implement next-ui barrel imports
156
+ ([75bea70](https://github.com/ho-nl/m2-pwa/commit/75bea703dba898f18a2a1dfa3243ebd0a4e6f0e1))
157
+ - narrow quote on mobile
158
+ ([e06ccc2](https://github.com/ho-nl/m2-pwa/commit/e06ccc25048124431dcdb786f1719f688a5e429c))
159
+ - remove conflicting files
160
+ ([0c17ae4](https://github.com/ho-nl/m2-pwa/commit/0c17ae46be62b775ac83b35f11c532ce2d9401a3))
161
+ - since all links are of next/link we need to add passHref for custom components
162
+ ([16fb931](https://github.com/ho-nl/m2-pwa/commit/16fb93100d367203ea79bb4f93357221253f2ecd))
134
163
 
135
164
  ### Features
136
165
 
137
- * created stacked-pages package ([d86008e](https://github.com/ho-nl/m2-pwa/commit/d86008ee659ccb25b194a41d624b394a1ddbd088))
138
- * **image:** introduced completely rewritten Image component ([e3413b3](https://github.com/ho-nl/m2-pwa/commit/e3413b3a57392d6571ea64cb8d9c8dca05ea31df))
139
- * implemented the ability to load graphcms content by URL ([99bc970](https://github.com/ho-nl/m2-pwa/commit/99bc970fc46d40b7efa99a71819529aeaa206bb4))
140
- * introduced graphcms-ui package to quickly build pages ([04d89c3](https://github.com/ho-nl/m2-pwa/commit/04d89c3fecf25f64923caf437eeb4b73f8887102))
141
- * introduces framer-next-pages and framer-sheet to next-ui and soxbase package ([e04ad8a](https://github.com/ho-nl/m2-pwa/commit/e04ad8a94cd1fd5a7c5575c9db7916b6e8a88f16))
142
- * next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
143
- * **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
144
- * renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of [@reachdigital](https://github.com/reachdigital) ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
145
- * upgrade to node 14 ([d079a75](https://github.com/ho-nl/m2-pwa/commit/d079a751e9bfd8dc7f5009d2c9f31c336a0c96ab))
146
- * upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
147
-
166
+ - created stacked-pages package
167
+ ([d86008e](https://github.com/ho-nl/m2-pwa/commit/d86008ee659ccb25b194a41d624b394a1ddbd088))
168
+ - **image:** introduced completely rewritten Image component
169
+ ([e3413b3](https://github.com/ho-nl/m2-pwa/commit/e3413b3a57392d6571ea64cb8d9c8dca05ea31df))
170
+ - implemented the ability to load graphcms content by URL
171
+ ([99bc970](https://github.com/ho-nl/m2-pwa/commit/99bc970fc46d40b7efa99a71819529aeaa206bb4))
172
+ - introduced graphcms-ui package to quickly build pages
173
+ ([04d89c3](https://github.com/ho-nl/m2-pwa/commit/04d89c3fecf25f64923caf437eeb4b73f8887102))
174
+ - introduces framer-next-pages and framer-sheet to next-ui and soxbase package
175
+ ([e04ad8a](https://github.com/ho-nl/m2-pwa/commit/e04ad8a94cd1fd5a7c5575c9db7916b6e8a88f16))
176
+ - next.js 11
177
+ ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
178
+ - **playwright:** added new playwright package to enable browser testing
179
+ ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
180
+ - renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of
181
+ [@reachdigital](https://github.com/reachdigital)
182
+ ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
183
+ - upgrade to node 14
184
+ ([d079a75](https://github.com/ho-nl/m2-pwa/commit/d079a751e9bfd8dc7f5009d2c9f31c336a0c96ab))
185
+ - upgraded to nextjs 11
186
+ ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
148
187
 
149
188
  ### Reverts
150
189
 
151
- * Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
152
-
153
-
154
-
155
-
190
+ - Revert "chore: upgrade @apollo/client"
191
+ ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
156
192
 
157
193
  # Change Log
158
194
 
@@ -0,0 +1,7 @@
1
+ fragment Asset on Asset @injectable {
2
+ url
3
+ width
4
+ height
5
+ mimeType
6
+ size
7
+ }
@@ -0,0 +1,34 @@
1
+ import { removeNull } from '@graphcommerce/graphql'
2
+ import { Image, ImageProps } from '@graphcommerce/image'
3
+ import { AssetFragment } from './Asset.gql'
4
+
5
+ export type { AssetFragment } from './Asset.gql'
6
+
7
+ type ImageAsset = Omit<AssetFragment, 'width' | 'height'> & {
8
+ width: number
9
+ height: number
10
+ }
11
+
12
+ function isImage(asset: AssetFragment): asset is ImageAsset {
13
+ return !!(asset.width && asset.height)
14
+ }
15
+
16
+ type AssetProps = {
17
+ asset: AssetFragment
18
+ } & Omit<ImageProps, 'src' | 'width' | 'height' | 'alt'>
19
+
20
+ export function Asset(props: AssetProps) {
21
+ const { asset, ...imgProps } = props
22
+
23
+ if (isImage(asset)) {
24
+ const { url, height, mimeType, size, width, ...assetProps } = removeNull(asset)
25
+ return <Image src={url} height={height} width={width} {...imgProps} {...assetProps} />
26
+ }
27
+
28
+ if (asset.mimeType === 'video/mp4') {
29
+ return <video src={asset.url} autoPlay muted loop playsInline disableRemotePlayback />
30
+ }
31
+
32
+ if (process.env.NODE_ENV !== 'production') return <div>{asset.mimeType} not supported</div>
33
+ return null
34
+ }
@@ -0,0 +1,117 @@
1
+ import { SxProps, Theme } from '@mui/material'
2
+ import { defaultRenderers } from './defaultRenderers'
3
+ import { defaultSxRenderer } from './defaultSxRenderer'
4
+ import {
5
+ AdditionalProps,
6
+ Renderers,
7
+ SxRenderer,
8
+ TextNode,
9
+ ElementOrTextNode,
10
+ ElementNode,
11
+ } from './types'
12
+
13
+ const RenderText = ({ classes, text, ...textProps }: TextNode) => {
14
+ let result = <>{text}</>
15
+ if (textProps.bold) result = <strong>{result}</strong>
16
+ if (textProps.italic) result = <em>{result}</em>
17
+ if (textProps.underlined) result = <em>{result}</em>
18
+
19
+ return result
20
+ }
21
+
22
+ export function isTextNode(node: ElementOrTextNode): node is TextNode {
23
+ return (node as TextNode).text !== undefined
24
+ }
25
+
26
+ export function isElementNode(node: ElementOrTextNode): node is ElementNode {
27
+ return (node as ElementNode).children !== undefined
28
+ }
29
+
30
+ function RenderNode(node: ElementOrTextNode & AdditionalProps) {
31
+ if (isTextNode(node)) {
32
+ return <RenderText {...node} />
33
+ }
34
+ if (isElementNode(node)) {
35
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
36
+ return <RenderElement {...node} />
37
+ }
38
+
39
+ if (process.env.NODE_ENV !== 'production') {
40
+ console.error(node)
41
+ throw Error(`RichText: Node not recognized`)
42
+ }
43
+
44
+ return null
45
+ }
46
+
47
+ function RenderChildren({
48
+ childNodes,
49
+ ...props
50
+ }: { childNodes: ElementNode['children'] } & AdditionalProps) {
51
+ return (
52
+ <>
53
+ {childNodes.map((node, key) => (
54
+ // Since we don't know any unique identifiers of the element and since this doesn't rerender often this is fine.
55
+ // eslint-disable-next-line react/no-array-index-key
56
+ <RenderNode {...node} {...props} key={key} />
57
+ ))}
58
+ </>
59
+ )
60
+ }
61
+
62
+ function RenderElement(element: ElementNode & AdditionalProps) {
63
+ const { type, children, sxRenderer, renderers, ...props } = element
64
+
65
+ // todo: this has the any type, could be improved
66
+ const Component = renderers[type]
67
+ const sx = sxRenderer?.[type] ?? []
68
+
69
+ if (Component) {
70
+ return (
71
+ <Component {...props} sx={[sxRenderer.all, ...(Array.isArray(sx) ? sx : [sx])]}>
72
+ <RenderChildren childNodes={children} sxRenderer={sxRenderer} renderers={renderers} />
73
+ </Component>
74
+ )
75
+ }
76
+
77
+ if (process.env.NODE_ENV !== 'production') {
78
+ console.error(element)
79
+ throw Error(`RichText: Unknown Element: ${element.type}`)
80
+ }
81
+ return <RenderChildren childNodes={children} sxRenderer={sxRenderer} renderers={renderers} />
82
+ }
83
+
84
+ export type RichTextProps = { raw: ElementNode } & {
85
+ renderers?: Partial<Renderers>
86
+ sxRenderer?: SxRenderer
87
+ }
88
+
89
+ export function mergeSxRenderer(base: SxRenderer, sxRenderer?: SxRenderer) {
90
+ if (!sxRenderer) return base
91
+
92
+ return Object.fromEntries(
93
+ Object.entries<SxProps<Theme>>(base).map(([key, sx]) => {
94
+ const sxOverride: SxProps<Theme> = sxRenderer?.[key]
95
+
96
+ return sxOverride
97
+ ? [
98
+ key,
99
+ [
100
+ ...(Array.isArray(sx) ? sx : [sx]),
101
+ ...(Array.isArray(sxOverride) ? sxOverride : [sxOverride]),
102
+ ],
103
+ ]
104
+ : [key, sx]
105
+ }),
106
+ ) as SxRenderer
107
+ }
108
+
109
+ export function RichText({ raw, sxRenderer, renderers }: RichTextProps) {
110
+ return (
111
+ <RenderChildren
112
+ childNodes={raw.children}
113
+ sxRenderer={mergeSxRenderer(defaultSxRenderer, sxRenderer)}
114
+ renderers={{ ...defaultRenderers, ...renderers }}
115
+ />
116
+ )
117
+ }
@@ -0,0 +1,42 @@
1
+ import { Box, Typography, Link } from '@mui/material'
2
+ import PageLink from 'next/link'
3
+ import { Asset } from '../Asset'
4
+ import { Renderers } from './types'
5
+
6
+ export const defaultRenderers: Renderers = {
7
+ 'heading-one': (props) => <Typography variant='h1' {...props} />,
8
+ 'heading-two': (props) => <Typography variant='h2' {...props} />,
9
+ 'heading-three': (props) => <Typography variant='h3' {...props} />,
10
+ 'heading-four': (props) => <Typography variant='h4' {...props} />,
11
+ 'heading-five': (props) => <Typography variant='h5' {...props} />,
12
+ 'heading-six': (props) => <Typography variant='h6' {...props} />,
13
+ paragraph: (props) => <Typography variant='body1' gutterBottom {...props} />,
14
+ 'bulleted-list': (props) => <Box component='ul' {...props} />,
15
+ 'numbered-list': (props) => <Box component='ol' {...props} />,
16
+ 'list-item': (props) => <Box component='li' {...props} />,
17
+ 'list-item-child': (props) => <Box component='span' {...props} />,
18
+ 'block-quote': (props) => <Box component='blockquote' {...props} />,
19
+ iframe: (props) => (
20
+ // todo add security attributes to iframe
21
+ // todo make iframe responsive (generic IFrame component?)
22
+ <Box component='iframe' title='embedded content' loading='lazy' {...props} />
23
+ ),
24
+ image: ({ src, width, height, title, mimeType }) => (
25
+ <Asset asset={{ url: src, alt: title, width, height, mimeType }} />
26
+ ),
27
+ video: ({ src, width, height, title, mimeType }) => (
28
+ <Asset asset={{ url: src, alt: title, width, height, mimeType }} />
29
+ ),
30
+ link: ({ href, ...props }) => (
31
+ <PageLink href={href} passHref>
32
+ <Link underline='hover' {...props} />
33
+ </PageLink>
34
+ ),
35
+ table: (props) => <Box component='table' {...props} />,
36
+ table_head: (props) => <Box component='thead' {...props} />,
37
+ table_header_cell: (props) => <Box component='th' {...props} />,
38
+ table_body: (props) => <Box component='tbody' {...props} />,
39
+ table_row: (props) => <Box component='tr' {...props} />,
40
+ table_cell: (props) => <Box component='td' {...props} />,
41
+ code: (props) => <Box component='code' {...props} />,
42
+ }
@@ -0,0 +1,103 @@
1
+ import { SxRenderer } from './types'
2
+
3
+ export const defaultSxRenderer: SxRenderer = {
4
+ all: {
5
+ '&:empty': {
6
+ display: 'none',
7
+ },
8
+ '&:last-of-type': { marginBottom: 0 },
9
+ },
10
+ paragraph: {
11
+ marginBottom: '1em',
12
+ wordBreak: 'break-word',
13
+ },
14
+ 'heading-one': {
15
+ marginTop: '0.5em',
16
+ marginBottom: '0.5em',
17
+ },
18
+ 'heading-two': {
19
+ marginTop: '0.5em',
20
+ marginBottom: '0.5em',
21
+ '&:first-of-type': { marginTop: 0 },
22
+ },
23
+ 'heading-three': {
24
+ marginTop: '0.5em',
25
+ marginBottom: '0.5em',
26
+ '&:first-of-type': { marginTop: 0 },
27
+ },
28
+ 'heading-four': {
29
+ marginTop: '0.5em',
30
+ marginBottom: '0.5em',
31
+ '&:first-of-type': { marginTop: 0 },
32
+ },
33
+ 'heading-five': {
34
+ marginTop: '0.5em',
35
+ marginBottom: '0.5em',
36
+ '&:first-of-type': { marginTop: 0 },
37
+ },
38
+ image: {
39
+ width: '100%',
40
+ height: 'auto',
41
+ },
42
+ video: {
43
+ width: '100%',
44
+ height: 'auto',
45
+ },
46
+ 'block-quote': (theme) => ({
47
+ paddingLeft: theme.spacings.sm,
48
+ margin: `${theme.spacings.md} 0`,
49
+ }),
50
+ 'bulleted-list': {
51
+ marginBottom: '1em',
52
+ },
53
+ 'numbered-list': {
54
+ marginBottom: '1em',
55
+ },
56
+ code: {
57
+ width: 'fit-content',
58
+ maxWidth: '100%',
59
+ padding: 5,
60
+ overflow: 'scroll',
61
+ },
62
+ table: (theme) => ({
63
+ display: 'table',
64
+ width: '100%',
65
+ borderSpacing: '2px',
66
+ borderCollapse: 'collapse',
67
+ marginTop: theme.spacings.md,
68
+ marginBottom: theme.spacings.sm,
69
+ '& thead, tbody': {
70
+ '& td': {
71
+ padding: '10px 20px',
72
+ },
73
+ },
74
+ '& thead': {
75
+ '& tr': {
76
+ '& td': {
77
+ '& p': {
78
+ fontWeight: theme.typography.fontWeightBold,
79
+ },
80
+ },
81
+ },
82
+ },
83
+ '& tbody': {
84
+ display: 'table-row-group',
85
+ verticalAlign: 'center',
86
+ borderColor: 'inherit',
87
+ '& tr': {
88
+ '&:nth-of-type(odd)': {
89
+ background: theme.palette.background.paper,
90
+ },
91
+ },
92
+ '& td': {
93
+ [theme.breakpoints.up('sm')]: {
94
+ minWidth: '150px',
95
+ },
96
+ '& p': {},
97
+ },
98
+ },
99
+ }),
100
+ link: {
101
+ wordBreak: 'break-word',
102
+ },
103
+ }
@@ -1,6 +1,7 @@
1
- import { isElementNode, isTextNode, Node } from '.'
1
+ import { isElementNode, isTextNode } from './RichText'
2
+ import { ElementOrTextNode } from './types'
2
3
 
3
- export default function getNodeLength(node: Node): number {
4
+ export function getNodeLength(node: ElementOrTextNode): number {
4
5
  if (isElementNode(node))
5
6
  return node.children.map(getNodeLength).reduce<number>((prev, curr) => prev + curr, 0)
6
7
 
@@ -0,0 +1,2 @@
1
+ export * from './RichText'
2
+ export * from './getNodeLength'