@faststore/core 2.1.99 → 2.1.100
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/.turbo/turbo-build.log
CHANGED
|
@@ -21,11 +21,11 @@ info - Generating static pages (7/7)
|
|
|
21
21
|
info - Finalizing page optimization...
|
|
22
22
|
|
|
23
23
|
Route (pages) Size First Load JS
|
|
24
|
-
┌ ● / 3.
|
|
24
|
+
┌ ● / 3.15 kB 130 kB
|
|
25
25
|
├ /_app 0 B 77.9 kB
|
|
26
|
-
├ ● /[...slug] 4.06 kB
|
|
26
|
+
├ ● /[...slug] 4.06 kB 141 kB
|
|
27
27
|
├ └ css/527e334fa69cf40a.css 1.85 kB
|
|
28
|
-
├ ● /[slug]/p 10.6 kB
|
|
28
|
+
├ ● /[slug]/p 10.6 kB 137 kB
|
|
29
29
|
├ └ css/7ca374e5534a3f68.css 11.3 kB
|
|
30
30
|
├ ○ /404 1.19 kB 114 kB
|
|
31
31
|
├ ● /500 1.21 kB 114 kB
|
|
@@ -37,11 +37,11 @@ Route (pages) Size First Load JS
|
|
|
37
37
|
├ ● /checkout 657 B 113 kB
|
|
38
38
|
├ ● /login 1.09 kB 114 kB
|
|
39
39
|
└ ● /s 4.6 kB 128 kB
|
|
40
|
-
+ First Load JS shared by all
|
|
40
|
+
+ First Load JS shared by all 80.9 kB
|
|
41
41
|
├ chunks/framework-dfd14d7ce6600b03.js 45.3 kB
|
|
42
42
|
├ chunks/main-fd466221927468fd.js 23.9 kB
|
|
43
43
|
├ chunks/pages/_app-40cff0982559d0b8.js 6.46 kB
|
|
44
|
-
├ chunks/webpack-
|
|
44
|
+
├ chunks/webpack-7bbdc4ae00f1fa43.js 2.22 kB
|
|
45
45
|
└ css/9e76fef1c9ca89af.css 3.06 kB
|
|
46
46
|
|
|
47
47
|
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.100",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"browserslist": "supports es6-module and not dead",
|
|
6
6
|
"scripts": {
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"autoprefixer": "^10.4.0",
|
|
40
40
|
"chalk": "^5.2.0",
|
|
41
41
|
"css-loader": "^6.7.1",
|
|
42
|
-
"
|
|
43
|
-
"draft-js-export-html": "^1.4.1",
|
|
42
|
+
"draftjs-to-html": "^0.9.1",
|
|
44
43
|
"graphql": "^15.0.0",
|
|
45
44
|
"include-media": "^1.4.10",
|
|
46
45
|
"msw": "^0.43.1",
|
|
@@ -110,5 +109,5 @@
|
|
|
110
109
|
"msw": {
|
|
111
110
|
"workerDirectory": "public"
|
|
112
111
|
},
|
|
113
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "c1c5860557d7751c49caba0b8dae76f0f8926d85"
|
|
114
113
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
InputField as UIInputField,
|
|
4
4
|
Icon as UIIcon,
|
|
5
5
|
} from '@faststore/ui'
|
|
6
|
+
import { NewsletterAddendum } from 'src/components/ui/Newsletter/NewsletterAddendum'
|
|
6
7
|
|
|
7
8
|
import { getSectionOverrides } from 'src/utils/overrides'
|
|
8
9
|
import { override } from 'src/customizations/components/overrides/Newsletter'
|
|
@@ -15,6 +16,7 @@ const {
|
|
|
15
16
|
InputFieldName,
|
|
16
17
|
InputFieldEmail,
|
|
17
18
|
Button,
|
|
19
|
+
__experimentalNewsletterAddendum,
|
|
18
20
|
} = getSectionOverrides(
|
|
19
21
|
{
|
|
20
22
|
ToastIconSuccess: UIIcon,
|
|
@@ -23,6 +25,7 @@ const {
|
|
|
23
25
|
InputFieldName: UIInputField,
|
|
24
26
|
InputFieldEmail: UIInputField,
|
|
25
27
|
Button: UIButton,
|
|
28
|
+
__experimentalNewsletterAddendum: NewsletterAddendum,
|
|
26
29
|
},
|
|
27
30
|
override as NewsletterOverrideDefinition
|
|
28
31
|
)
|
|
@@ -34,4 +37,5 @@ export {
|
|
|
34
37
|
InputFieldName,
|
|
35
38
|
InputFieldEmail,
|
|
36
39
|
Button,
|
|
40
|
+
__experimentalNewsletterAddendum,
|
|
37
41
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ComponentPropsWithRef, FormEvent, useMemo } from 'react'
|
|
2
2
|
import { forwardRef, useRef } from 'react'
|
|
3
|
-
import { convertFromRaw } from 'draft-js'
|
|
4
|
-
import { stateToHTML } from 'draft-js-export-html'
|
|
5
3
|
import { useUI } from '@faststore/ui'
|
|
6
4
|
import type { InputFieldProps } from '@faststore/ui'
|
|
7
5
|
|
|
@@ -13,39 +11,9 @@ import {
|
|
|
13
11
|
InputFieldName,
|
|
14
12
|
InputFieldEmail,
|
|
15
13
|
Button,
|
|
14
|
+
__experimentalNewsletterAddendum as NewsletterAddendum,
|
|
16
15
|
} from 'src/components/sections/Newsletter/Overrides'
|
|
17
16
|
|
|
18
|
-
const cmsToHtml = (content) => {
|
|
19
|
-
if (!content) {
|
|
20
|
-
return ''
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const rawDraftContentState = JSON.parse(content)
|
|
24
|
-
const html = stateToHTML(convertFromRaw(rawDraftContentState), {
|
|
25
|
-
entityStyleFn: (entity) => {
|
|
26
|
-
const entityType = entity.get('type').toLowerCase()
|
|
27
|
-
|
|
28
|
-
if (entityType === 'link') {
|
|
29
|
-
const data = entity.getData()
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
element: 'a',
|
|
33
|
-
attributes: {
|
|
34
|
-
'data-fs-link': 'true',
|
|
35
|
-
'data-fs-link-variant': 'inline',
|
|
36
|
-
'data-fs-link-inverse': 'true',
|
|
37
|
-
'data-fs-link-size': 'regular',
|
|
38
|
-
'data-testid': 'fs-link',
|
|
39
|
-
href: data.url,
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
return html
|
|
47
|
-
}
|
|
48
|
-
|
|
49
17
|
export type SubscribeMessage = {
|
|
50
18
|
title: string
|
|
51
19
|
message: string
|
|
@@ -124,10 +92,6 @@ const Newsletter = forwardRef<HTMLFormElement, NewsletterProps>(
|
|
|
124
92
|
const { subscribeUser, loading, data } = useNewsletter()
|
|
125
93
|
const nameInputRef = useRef<HTMLInputElement>(null)
|
|
126
94
|
const emailInputRef = useRef<HTMLInputElement>(null)
|
|
127
|
-
const subscriptionButtonLabel = useMemo(
|
|
128
|
-
() => (loading ? subscribeButtonLoadingLabel : subscribeButtonLabel),
|
|
129
|
-
[loading, subscribeButtonLabel, subscribeButtonLoadingLabel]
|
|
130
|
-
)
|
|
131
95
|
|
|
132
96
|
const { pushToast } = useUI()
|
|
133
97
|
|
|
@@ -217,12 +181,10 @@ const Newsletter = forwardRef<HTMLFormElement, NewsletterProps>(
|
|
|
217
181
|
// This decision can be reviewed later if needed
|
|
218
182
|
inputRef={emailInputRef}
|
|
219
183
|
/>
|
|
220
|
-
<
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}}
|
|
225
|
-
></span>
|
|
184
|
+
<NewsletterAddendum.Component
|
|
185
|
+
addendum={privacyPolicy}
|
|
186
|
+
{...NewsletterAddendum.props}
|
|
187
|
+
/>
|
|
226
188
|
<Button.Component
|
|
227
189
|
variant="secondary"
|
|
228
190
|
inverse
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO:
|
|
3
|
+
*
|
|
4
|
+
* This library hasn't been updated in 4 years at the time of writing.
|
|
5
|
+
*
|
|
6
|
+
* We're using it as a patch, and it is expected that some Rich Text use cases of draftjs are not supported by it.
|
|
7
|
+
* We have the dependency on draftjs because of the way the headless CMS send us the data.
|
|
8
|
+
*
|
|
9
|
+
* This library should be removed as soon as possible, which will probably be possible through one of two cases:
|
|
10
|
+
* 1. We support React Server Components and go back to using the official draftjs library for doing this, only on the server.
|
|
11
|
+
* This is still not the ideal solution, since it still relies on a unsupported, deprecated and archived library (draftjs).
|
|
12
|
+
* 2. CMS uses a new library or changes how it sends the data to not depend on draftjs.
|
|
13
|
+
*
|
|
14
|
+
* This is a limitation not only for this component, but for every native & custom component that makes use of Rich Text.
|
|
15
|
+
*/
|
|
16
|
+
import draftToHtml from 'draftjs-to-html'
|
|
17
|
+
|
|
18
|
+
export interface NewsletterAddendumProps {
|
|
19
|
+
/**
|
|
20
|
+
* Expects a string of a JSON object in the form of draftjs's raw content state.
|
|
21
|
+
*/
|
|
22
|
+
addendum: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getLinkElementAsString(url: string, text: string) {
|
|
26
|
+
return `
|
|
27
|
+
<a
|
|
28
|
+
data-fs-link="true"
|
|
29
|
+
data-fs-link-variant="inline"
|
|
30
|
+
data-fs-link-inverse="true"
|
|
31
|
+
data-fs-link-size="regular"
|
|
32
|
+
data-testid="fs-link"
|
|
33
|
+
href="${url}"
|
|
34
|
+
>${text}</a>`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function cmsToHtml(addendum: string) {
|
|
38
|
+
if (!addendum) {
|
|
39
|
+
return ''
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let rawDraftContentState = null
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
rawDraftContentState = JSON.parse(addendum)
|
|
46
|
+
} catch (e) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'Newsletter\'s prop "addendum" is not a JSON string. This is happening because the overridden prop is malformed or the CMS is providing malformed content for that prop.',
|
|
49
|
+
{
|
|
50
|
+
cause: e,
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!rawDraftContentState) {
|
|
56
|
+
return ''
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return draftToHtml(
|
|
60
|
+
rawDraftContentState,
|
|
61
|
+
undefined,
|
|
62
|
+
undefined,
|
|
63
|
+
(entity: { type: string; data: { url: string } }, text: string) => {
|
|
64
|
+
if (entity.type !== 'LINK') {
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return getLinkElementAsString(entity.data.url, text)
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function NewsletterAddendum({
|
|
74
|
+
addendum,
|
|
75
|
+
...otherProps
|
|
76
|
+
}: NewsletterAddendumProps) {
|
|
77
|
+
return (
|
|
78
|
+
<span
|
|
79
|
+
data-fs-newsletter-addendum
|
|
80
|
+
dangerouslySetInnerHTML={{
|
|
81
|
+
__html: cmsToHtml(addendum),
|
|
82
|
+
}}
|
|
83
|
+
{...otherProps}
|
|
84
|
+
></span>
|
|
85
|
+
)
|
|
86
|
+
}
|
package/src/typings/overrides.ts
CHANGED
|
@@ -40,6 +40,7 @@ import type {
|
|
|
40
40
|
ComponentOverrideDefinition,
|
|
41
41
|
SectionOverrideDefinition,
|
|
42
42
|
} from './overrideDefinitionUtils'
|
|
43
|
+
import { NewsletterAddendumProps } from 'src/components/ui/Newsletter/NewsletterAddendum'
|
|
43
44
|
|
|
44
45
|
export type SectionOverride =
|
|
45
46
|
| AlertOverrideDefinition
|
|
@@ -164,6 +165,7 @@ export type NewsletterOverrideDefinition = SectionOverrideDefinition<
|
|
|
164
165
|
Omit<InputFieldProps, 'inputRef'>
|
|
165
166
|
>
|
|
166
167
|
Button: ComponentOverrideDefinition<ButtonProps, ButtonProps>
|
|
168
|
+
__experimentalNewsletterAddendum: ComponentOverrideDefinition<NewsletterAddendumProps, NewsletterAddendumProps>
|
|
167
169
|
}
|
|
168
170
|
>
|
|
169
171
|
|