@graphcommerce/next-ui 8.1.0-canary.8 → 9.0.0-canary.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/ActionCard/ActionCard.tsx +66 -39
- package/ActionCard/ActionCardAccordion.tsx +2 -1
- package/ActionCard/ActionCardLayout.tsx +1 -1
- package/ActionCard/ActionCardList.tsx +11 -10
- package/ActionCard/index.ts +0 -1
- package/Blog/BlogAuthor/BlogAuthor.tsx +2 -4
- package/Blog/BlogListItem/BlogListItem.tsx +2 -4
- package/Blog/BlogTags/BlogTag.tsx +4 -1
- package/Breadcrumbs/Breadcrumbs.tsx +195 -0
- package/Breadcrumbs/BreadcrumbsJsonLd.tsx +13 -0
- package/Breadcrumbs/BreadcrumbsList.tsx +101 -0
- package/Breadcrumbs/BreadcrumbsPopper.tsx +48 -0
- package/Breadcrumbs/index.ts +4 -0
- package/Breadcrumbs/jsonLdBreadcrumb.tsx +19 -0
- package/Breadcrumbs/types.ts +11 -0
- package/CHANGELOG.md +341 -98
- package/Config.graphqls +5 -0
- package/Document/DocumentBodyEnd.tsx +7 -0
- package/Document/DocumentBodyStart.tsx +7 -0
- package/Document/DocumentHeadEnd.tsx +7 -0
- package/Document/DocumentHeadStart.tsx +7 -0
- package/Document/index.ts +4 -0
- package/Footer/Footer.tsx +1 -1
- package/FramerScroller/SidebarGallery.tsx +54 -27
- package/FullPageMessage/FullPageMessage.tsx +1 -0
- package/Intl/DateTimeFormat/DateFormat.tsx +10 -0
- package/Intl/DateTimeFormat/DateTimeFormat.tsx +20 -0
- package/Intl/DateTimeFormat/TimeFormat.tsx +10 -0
- package/Intl/DateTimeFormat/index.ts +3 -0
- package/Intl/DateTimeFormat/toDate.ts +16 -0
- package/Intl/DisplayNames/DisplayNames.tsx +22 -0
- package/Intl/DisplayNames/index.ts +1 -0
- package/Intl/ListFormat.tsx +33 -0
- package/Intl/NumberFormat/CurrencyFormat.tsx +191 -0
- package/Intl/NumberFormat/NumberFormat.tsx +24 -0
- package/Intl/NumberFormat/PercentFormat.tsx +5 -0
- package/Intl/NumberFormat/UnitFormat.tsx +59 -0
- package/Intl/NumberFormat/index.ts +4 -0
- package/Intl/RelativeTimeFormat/RelativeTimeFormat.tsx +34 -0
- package/Intl/RelativeTimeFormat/RelativeToTimeFormat.tsx +35 -0
- package/Intl/RelativeTimeFormat/index.ts +2 -0
- package/Intl/RelativeTimeFormat/relativeTimeFormatAutoUnit.ts +23 -0
- package/Intl/index.ts +11 -0
- package/JsonLd/JsonLd.tsx +3 -2
- package/Layout/components/LayoutHeader.tsx +30 -10
- package/Layout/components/LayoutHeaderBack.tsx +20 -9
- package/Layout/components/LayoutHeaderClose.tsx +8 -2
- package/Layout/components/LayoutTitle.tsx +0 -5
- package/LayoutDefault/components/LayoutDefault.tsx +15 -13
- package/LazyHydrate/LazyHydrate.tsx +19 -3
- package/Overlay/components/OverlayBase.tsx +31 -6
- package/Overlay/components/OverlayHeader.tsx +27 -0
- package/Overlay/components/index.ts +1 -0
- package/PageLoadIndicator/PageLoadIndicator.tsx +25 -14
- package/PageMeta/PageMeta.tsx +1 -71
- package/PageMeta/canonicalize.ts +78 -0
- package/Pagination/PaginationExtended.tsx +103 -0
- package/Snackbar/MessageSnackbarImpl.tsx +60 -19
- package/Styles/responsiveVal.tsx +4 -5
- package/Styles/withEmotionCache.tsx +2 -2
- package/Theme/DarkLightModeThemeProvider.tsx +41 -19
- package/Theme/MuiButton.ts +11 -3
- package/TimeAgo/TimeAgo.tsx +3 -0
- package/hooks/index.ts +2 -1
- package/hooks/memoDeep.ts +38 -0
- package/hooks/useDateTimeFormat.ts +4 -4
- package/hooks/{useSsr.ts → useIsSsr.ts} +3 -0
- package/hooks/useLocale.ts +2 -2
- package/hooks/useNumberFormat.ts +4 -3
- package/hooks/useStorefrontConfig.ts +1 -9
- package/hooks/useUrlQuery.ts +6 -4
- package/icons.ts +55 -0
- package/index.ts +11 -2
- package/package.json +14 -14
- package/server.ts +9 -0
- package/utils/cssFlags.tsx +53 -0
- package/utils/getCssFlagInitScript.tsx +20 -0
- package/utils/normalizeLocale.ts +26 -0
- package/utils/robots.ts +41 -0
- package/utils/sitemap.ts +47 -0
- package/utils/storefrontConfig.ts +8 -0
- package/ActionCard/ActionCardListForm.tsx +0 -88
- package/icons/index.ts +0 -48
package/hooks/useLocale.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { normalizeLocale } from '
|
|
1
|
+
import { normalizeLocale } from '../utils/normalizeLocale'
|
|
2
2
|
import { useStorefrontConfig } from './useStorefrontConfig'
|
|
3
3
|
|
|
4
|
-
export function useLocale() {
|
|
4
|
+
export function useLocale(): Intl.UnicodeBCP47LocaleIdentifier {
|
|
5
5
|
const { locale } = useStorefrontConfig()
|
|
6
6
|
return normalizeLocale(locale)
|
|
7
7
|
}
|
package/hooks/useNumberFormat.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useMemo } from 'react'
|
|
2
2
|
import { useLocale } from './useLocale'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use <NumberFormat />, <PercentFormat /> or <UnitFormat /> instead
|
|
6
|
+
*/
|
|
7
|
+
export function useNumberFormat(props?: Intl.NumberFormatOptions) {
|
|
7
8
|
const locale = useLocale()
|
|
8
9
|
const formatter = useMemo(() => new Intl.NumberFormat(locale, props), [locale, props])
|
|
9
10
|
return formatter
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { useRouter } from 'next/router'
|
|
2
|
-
|
|
3
|
-
export const storefrontAll = import.meta.graphCommerce.storefront
|
|
4
|
-
|
|
5
|
-
/** Get the current storefront config based on the provided locale */
|
|
6
|
-
export const storefrontConfig = (locale?: string | undefined) =>
|
|
7
|
-
storefrontAll.find((l) => l.locale === locale)
|
|
8
|
-
|
|
9
|
-
export const storefrontConfigDefault = () =>
|
|
10
|
-
storefrontAll.find((l) => l.defaultLocale) ?? storefrontAll[0]
|
|
2
|
+
import { storefrontConfig } from '../utils/storefrontConfig'
|
|
11
3
|
|
|
12
4
|
/** Automatically selects the correct storefront config based on the current locale */
|
|
13
5
|
export function useStorefrontConfig(locale?: string | undefined) {
|
package/hooks/useUrlQuery.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useRouter } from 'next/router'
|
|
2
2
|
import { useCallback } from 'react'
|
|
3
3
|
|
|
4
|
-
export function useUrlQuery<T extends Record<string, string | null>>() {
|
|
5
|
-
const { query, replace } = useRouter()
|
|
4
|
+
export function useUrlQuery<T extends Record<string, string | null>>(doPush?: boolean) {
|
|
5
|
+
const { query, replace, push } = useRouter()
|
|
6
6
|
|
|
7
7
|
const setRouterQuery = useCallback(
|
|
8
8
|
(incoming: T) => {
|
|
@@ -13,9 +13,11 @@ export function useUrlQuery<T extends Record<string, string | null>>() {
|
|
|
13
13
|
|
|
14
14
|
if (JSON.stringify(current) === JSON.stringify(newQuery)) return Promise.resolve(true)
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return doPush
|
|
17
|
+
? push({ query: newQuery })
|
|
18
|
+
: replace({ query: newQuery }, undefined, { shallow: true })
|
|
17
19
|
},
|
|
18
|
-
[replace],
|
|
20
|
+
[doPush, push, replace],
|
|
19
21
|
)
|
|
20
22
|
|
|
21
23
|
return [query as T, setRouterQuery] as const
|
package/icons.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export { default as iconArrowDown } from './icons/arrow-down.svg'
|
|
2
|
+
export { default as iconArrowBack } from './icons/arrow-left.svg'
|
|
3
|
+
export { default as iconArrowForward } from './icons/arrow-right.svg'
|
|
4
|
+
export { default as iconArrowUp } from './icons/arrow-up.svg'
|
|
5
|
+
export { default as iconShoppingBag } from './icons/bag.svg'
|
|
6
|
+
export { default as iconBin } from './icons/bin.svg'
|
|
7
|
+
export { default as iconInvoice } from './icons/box-alt.svg'
|
|
8
|
+
export { default as iconBox } from './icons/box.svg'
|
|
9
|
+
export { default as iconOrderBefore } from './icons/calendar.svg'
|
|
10
|
+
export { default as iconCancelAlt } from './icons/cancel-alt.svg'
|
|
11
|
+
export { default as iconCancel } from './icons/cancel.svg'
|
|
12
|
+
export { default as iconCartAdd } from './icons/cart-add.svg'
|
|
13
|
+
export { default as iconCart } from './icons/cart.svg'
|
|
14
|
+
export { default as iconChat } from './icons/chat-alt.svg'
|
|
15
|
+
export { default as iconCustomerService } from './icons/chat.svg'
|
|
16
|
+
export { default as iconChevronDown } from './icons/chevron-down.svg'
|
|
17
|
+
export { default as iconChevronBack, default as iconChevronLeft } from './icons/chevron-left.svg'
|
|
18
|
+
export { default as iconChevronRight } from './icons/chevron-right.svg'
|
|
19
|
+
export { default as iconChevronUp } from './icons/chevron-up.svg'
|
|
20
|
+
export { default as iconCirle } from './icons/circle.svg'
|
|
21
|
+
export { default as iconClose } from './icons/close.svg'
|
|
22
|
+
export { default as iconCompare } from './icons/compare-arrows.svg'
|
|
23
|
+
export { default as iconContrast } from './icons/contrast.svg'
|
|
24
|
+
export { default as iconCreditCard, default as iconId } from './icons/credit-card.svg'
|
|
25
|
+
export { default as iconEllypsis } from './icons/ellypsis.svg'
|
|
26
|
+
export { default as iconEmail, default as iconEmailOutline } from './icons/envelope-alt.svg'
|
|
27
|
+
export { default as iconExit } from './icons/exit.svg'
|
|
28
|
+
export { default as icon404 } from './icons/explore.svg'
|
|
29
|
+
export { default as iconEyeClosed } from './icons/eye-closed.svg'
|
|
30
|
+
export { default as iconEyeCrossed } from './icons/eye-crossed.svg'
|
|
31
|
+
export { default as iconEye } from './icons/eye.svg'
|
|
32
|
+
export { default as iconHeart } from './icons/favourite.svg'
|
|
33
|
+
export { default as iconMenu } from './icons/hamburger.svg'
|
|
34
|
+
export { default as iconParty } from './icons/happy-face.svg'
|
|
35
|
+
export { default as iconAddresses, default as iconHome } from './icons/home-alt.svg'
|
|
36
|
+
export { default as iconLanguage } from './icons/language.svg'
|
|
37
|
+
export { default as iconLocation } from './icons/location.svg'
|
|
38
|
+
export { default as iconLock } from './icons/lock.svg'
|
|
39
|
+
export { default as iconFullscreen } from './icons/maximise.svg'
|
|
40
|
+
export { default as iconFullscreenExit } from './icons/minimise.svg'
|
|
41
|
+
export { default as iconMin } from './icons/minus.svg'
|
|
42
|
+
export { default as iconMoon } from './icons/moon.svg'
|
|
43
|
+
export { default as iconNewspaper } from './icons/news.svg'
|
|
44
|
+
export { default as iconCheckmark } from './icons/ok.svg'
|
|
45
|
+
export { default as iconPerson } from './icons/person-alt.svg'
|
|
46
|
+
export { default as iconPlay } from './icons/play.svg'
|
|
47
|
+
export { default as iconPlus } from './icons/plus.svg'
|
|
48
|
+
export { default as iconShutdown } from './icons/power.svg'
|
|
49
|
+
export { default as iconRefresh } from './icons/refresh.svg'
|
|
50
|
+
export { default as iconSadFace } from './icons/sad-face.svg'
|
|
51
|
+
export { default as iconSearch } from './icons/search.svg'
|
|
52
|
+
export { default as iconPhone } from './icons/smartphone.svg'
|
|
53
|
+
export { default as iconStar } from './icons/star.svg'
|
|
54
|
+
export { default as iconSun } from './icons/sun.svg'
|
|
55
|
+
export { default as iconInfo } from './icons/info.svg'
|
package/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './Blog/BlogList/BlogList'
|
|
|
7
7
|
export * from './Blog/BlogListItem/BlogListItem'
|
|
8
8
|
export * from './Blog/BlogTags/BlogTags'
|
|
9
9
|
export * from './Blog/BlogTitle/BlogTitle'
|
|
10
|
+
export * from './Breadcrumbs'
|
|
10
11
|
export * from './Button'
|
|
11
12
|
export * from './ChipMenu/ChipMenu'
|
|
12
13
|
export * from './ContainerWithHeader/ContainerWithHeader'
|
|
@@ -22,8 +23,11 @@ export * from './Form/InputCheckmark'
|
|
|
22
23
|
export * from './FramerScroller'
|
|
23
24
|
export * from './FullPageMessage/FullPageMessage'
|
|
24
25
|
export * from './Highlight/Highlight'
|
|
26
|
+
export * from './hooks'
|
|
25
27
|
export * from './IconHeader/IconHeader'
|
|
28
|
+
export * from './icons'
|
|
26
29
|
export * from './IconSvg'
|
|
30
|
+
export * from './Intl'
|
|
27
31
|
export * from './JsonLd/JsonLd'
|
|
28
32
|
export * from './Layout'
|
|
29
33
|
export * from './LayoutDefault'
|
|
@@ -35,8 +39,10 @@ export * from './Overlay'
|
|
|
35
39
|
export * from './OverlayOrPopperChip'
|
|
36
40
|
export * from './Page'
|
|
37
41
|
export * from './PageLoadIndicator/PageLoadIndicator'
|
|
42
|
+
export * from './PageMeta/canonicalize'
|
|
38
43
|
export * from './PageMeta/PageMeta'
|
|
39
44
|
export * from './Pagination/Pagination'
|
|
45
|
+
export * from './Pagination/PaginationExtended'
|
|
40
46
|
export * from './RenderType'
|
|
41
47
|
export * from './Row'
|
|
42
48
|
export * from './SectionContainer/SectionContainer'
|
|
@@ -56,6 +62,9 @@ export * from './ToggleButton/ToggleButton'
|
|
|
56
62
|
export * from './ToggleButtonGroup/ToggleButtonGroup'
|
|
57
63
|
export * from './UspList/UspList'
|
|
58
64
|
export * from './UspList/UspListItem'
|
|
59
|
-
export * from './hooks'
|
|
60
|
-
export * from './icons'
|
|
61
65
|
export * from './utils/cookie'
|
|
66
|
+
export * from './utils/cssFlags'
|
|
67
|
+
export * from './utils/normalizeLocale'
|
|
68
|
+
export * from './utils/robots'
|
|
69
|
+
export * from './utils/sitemap'
|
|
70
|
+
export * from './utils/storefrontConfig'
|
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": "
|
|
5
|
+
"version": "9.0.0-canary.100",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -13,26 +13,26 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@emotion/cache": "^11.11.0",
|
|
16
|
-
"@emotion/react": "^11.11.
|
|
16
|
+
"@emotion/react": "^11.11.4",
|
|
17
17
|
"@emotion/server": "^11.11.0",
|
|
18
|
-
"@emotion/styled": "^11.11.
|
|
18
|
+
"@emotion/styled": "^11.11.5",
|
|
19
19
|
"cookie": "^0.6.0",
|
|
20
|
-
"
|
|
20
|
+
"next-sitemap": "4.2.3",
|
|
21
|
+
"react-is": "^18.3.1"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/cookie": "^0.6.0",
|
|
24
|
-
"@types/react-is": "^18.
|
|
25
|
-
"typescript": "5.
|
|
25
|
+
"@types/react-is": "^18.3.0",
|
|
26
|
+
"typescript": "5.5.3"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"@graphcommerce/eslint-config-pwa": "^
|
|
29
|
-
"@graphcommerce/framer-next-pages": "^
|
|
30
|
-
"@graphcommerce/framer-scroller": "^
|
|
31
|
-
"@graphcommerce/framer-utils": "^
|
|
32
|
-
"@graphcommerce/image": "^
|
|
33
|
-
"@graphcommerce/
|
|
34
|
-
"@graphcommerce/
|
|
35
|
-
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.8",
|
|
29
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.100",
|
|
30
|
+
"@graphcommerce/framer-next-pages": "^9.0.0-canary.100",
|
|
31
|
+
"@graphcommerce/framer-scroller": "^9.0.0-canary.100",
|
|
32
|
+
"@graphcommerce/framer-utils": "^9.0.0-canary.100",
|
|
33
|
+
"@graphcommerce/image": "^9.0.0-canary.100",
|
|
34
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.100",
|
|
35
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.100",
|
|
36
36
|
"@lingui/core": "^4.2.1",
|
|
37
37
|
"@lingui/macro": "^4.2.1",
|
|
38
38
|
"@lingui/react": "^4.2.1",
|
package/server.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './Styles/withEmotionCache'
|
|
2
|
+
export * from './utils/getCssFlagInitScript'
|
|
3
|
+
export * from './utils/normalizeLocale'
|
|
4
|
+
export * from './utils/robots'
|
|
5
|
+
export * from './utils/sitemap'
|
|
6
|
+
export * from './utils/storefrontConfig'
|
|
7
|
+
export * from './PageMeta/canonicalize'
|
|
8
|
+
export * from './Document'
|
|
9
|
+
export * from './utils/cookie'
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { FLAGS_STORAGE_KEY } from './getCssFlagInitScript'
|
|
2
|
+
|
|
3
|
+
function loadFlags() {
|
|
4
|
+
const flags = JSON.parse(localStorage.getItem(FLAGS_STORAGE_KEY) || '{}')
|
|
5
|
+
if (typeof flags !== 'object' && flags !== null) return {}
|
|
6
|
+
return flags as Record<string, true | string>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function saveFlags(flags: Record<string, true | string>) {
|
|
10
|
+
window.localStorage?.setItem(FLAGS_STORAGE_KEY, JSON.stringify(flags))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function removeCssFlag(flagName: string) {
|
|
14
|
+
const flags = loadFlags()
|
|
15
|
+
delete flags[flagName]
|
|
16
|
+
document.documentElement.removeAttribute(`data-${flagName}`)
|
|
17
|
+
saveFlags(flags)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function setCssFlag(flagName: string, val: true | string) {
|
|
21
|
+
document.documentElement.setAttribute(`data-${flagName}`, typeof val === 'boolean' ? '' : val)
|
|
22
|
+
|
|
23
|
+
const flags = loadFlags()
|
|
24
|
+
flags[flagName] = val
|
|
25
|
+
saveFlags(flags)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getCssFlag(flagName: string) {
|
|
29
|
+
return loadFlags()[flagName]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Easily create a CSS selector that only applies when a flag is set.
|
|
34
|
+
*
|
|
35
|
+
* Example:
|
|
36
|
+
*
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <Box sx={{ [cssFlagSelector('dark')]: { color: 'white' } }} />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const cssFlag = <T extends string>(flagName: T) => `html[data-${flagName}] &` as const
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Easily create a CSS selector that only applies when a flag is not set.
|
|
45
|
+
*
|
|
46
|
+
* Example:
|
|
47
|
+
*
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <Box sx={{ [cssNotFlagSelector('dark')]: { color: 'black' } }} />
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const cssNotFlag = <T extends string>(flagName: T) =>
|
|
53
|
+
`html:not([data-${flagName}]) &` as const
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const FLAGS_STORAGE_KEY = 'gc-flags'
|
|
2
|
+
|
|
3
|
+
export function getCssFlagsInitScript() {
|
|
4
|
+
return (
|
|
5
|
+
<script
|
|
6
|
+
id='init-gc-flags'
|
|
7
|
+
key='mui-color-scheme-init'
|
|
8
|
+
// eslint-disable-next-line react/no-danger
|
|
9
|
+
dangerouslySetInnerHTML={{
|
|
10
|
+
__html: `(function() {
|
|
11
|
+
try {
|
|
12
|
+
const flags = JSON.parse(localStorage.getItem('${FLAGS_STORAGE_KEY}') || '{}')
|
|
13
|
+
Object.entries(flags).forEach(([key, val]) => {
|
|
14
|
+
document.documentElement.setAttribute('data-' +key, typeof val === 'boolean' ? '' : val)
|
|
15
|
+
})
|
|
16
|
+
} catch(e){}})();`,
|
|
17
|
+
}}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { storefrontConfig, storefrontConfigDefault } from './storefrontConfig'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* To support using multiple storefronts using the same language locale (which
|
|
5
|
+
* next.js does not support), we use an additional 'tag' in the locale code in
|
|
6
|
+
* which we specify a unique string (i.e. a Magento store code).
|
|
7
|
+
*
|
|
8
|
+
* This makes next.js happy, as it still follows the BCP47 spec. However, the
|
|
9
|
+
* Intl API and other places may not accept this as a valid locale.
|
|
10
|
+
*
|
|
11
|
+
* Use this method to get a 'normalized' locale that can safely be used in such
|
|
12
|
+
* places.
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeLocale(locale: string | undefined = storefrontConfigDefault().locale) {
|
|
15
|
+
const linguiLocale = storefrontConfig(locale)?.linguiLocale
|
|
16
|
+
if (linguiLocale) return linguiLocale
|
|
17
|
+
|
|
18
|
+
// Specifically match the xx-yy-storecode format, so we don't accidently 'fix'
|
|
19
|
+
// valid locales such as he-Hebr-IL or zh-Hans-CN. This this isn't perfect and
|
|
20
|
+
// we should consider a more formalized way to use such pseudo-locales, which
|
|
21
|
+
// can be matched more precisely.
|
|
22
|
+
|
|
23
|
+
const matches = locale?.match(/([a-z]{2})-([a-z]{2})-([a-z]+)/i)
|
|
24
|
+
if (matches) return `${matches[1]}-${matches[2]}`
|
|
25
|
+
return locale
|
|
26
|
+
}
|
package/utils/robots.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GetServerSidePropsContext } from 'next'
|
|
2
|
+
|
|
3
|
+
type Stringifyable = boolean | string | number | null | undefined
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tagged template literal for robots.txt that will automatically stringify values and indent them correctly.
|
|
7
|
+
* https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt#syntax
|
|
8
|
+
*/
|
|
9
|
+
export function robotsTxt(strings: TemplateStringsArray, ...values: Stringifyable[]) {
|
|
10
|
+
return strings
|
|
11
|
+
.reduce((acc, str, i) => {
|
|
12
|
+
let value = values[i]
|
|
13
|
+
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
const [conditional, val] = value
|
|
16
|
+
value = conditional ? val : null
|
|
17
|
+
}
|
|
18
|
+
if (!value) value = ''
|
|
19
|
+
if (typeof value === 'boolean') value = value ? 'true' : 'false'
|
|
20
|
+
if (typeof value === 'number') value = String(value)
|
|
21
|
+
|
|
22
|
+
return acc + str + value
|
|
23
|
+
}, '')
|
|
24
|
+
.split('\n')
|
|
25
|
+
.map((v) => v.trim())
|
|
26
|
+
.join('\n')
|
|
27
|
+
.trim()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
31
|
+
export async function getServerSidePropsRobotsTxt(
|
|
32
|
+
context: GetServerSidePropsContext,
|
|
33
|
+
robots: string,
|
|
34
|
+
) {
|
|
35
|
+
context.res.setHeader('Content-Type', 'text/plain')
|
|
36
|
+
context.res.write(robots)
|
|
37
|
+
context.res.end()
|
|
38
|
+
context.res.setHeader('Cache-Control', `public, s-maxage=${60 * 60 * 2}`)
|
|
39
|
+
|
|
40
|
+
return { props: {} }
|
|
41
|
+
}
|
package/utils/sitemap.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GetServerSidePropsContext, GetStaticPathsResult } from 'next'
|
|
2
|
+
import { getServerSideSitemapLegacy, ISitemapField } from 'next-sitemap'
|
|
3
|
+
import { canonicalize } from '../PageMeta/canonicalize'
|
|
4
|
+
|
|
5
|
+
export function excludeSitemap(excludes: string[]) {
|
|
6
|
+
const regexp = excludes.map((exclude) => new RegExp(exclude.replace(/\*/g, '.*?')))
|
|
7
|
+
|
|
8
|
+
return (path: string) => !regexp.some((pattern) => pattern.test(`/${path}`))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function staticPathsToString(
|
|
12
|
+
path: GetStaticPathsResult<{ url: string[] | string }>['paths'][0],
|
|
13
|
+
) {
|
|
14
|
+
if (typeof path === 'string') return path
|
|
15
|
+
if (typeof path.params.url === 'string') return path.params.url
|
|
16
|
+
return path.params.url.join('/')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function toSitemapFields(
|
|
20
|
+
context: GetServerSidePropsContext,
|
|
21
|
+
paths: string[],
|
|
22
|
+
): ISitemapField[] {
|
|
23
|
+
const lastmod = new Date().toISOString()
|
|
24
|
+
const options = {
|
|
25
|
+
locale: context.locale,
|
|
26
|
+
defaultLocale: context.defaultLocale,
|
|
27
|
+
pathname: '/',
|
|
28
|
+
isLocaleDomain: false,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const sitemapPaths = paths.map<ISitemapField>((path) => ({
|
|
32
|
+
loc: canonicalize(options, `/${path}`) ?? '',
|
|
33
|
+
lastmod,
|
|
34
|
+
changefreq: 'daily',
|
|
35
|
+
priority: 0.7,
|
|
36
|
+
}))
|
|
37
|
+
|
|
38
|
+
return sitemapPaths
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getServerSidePropsSitemap(
|
|
42
|
+
context: GetServerSidePropsContext,
|
|
43
|
+
paths: ISitemapField[],
|
|
44
|
+
) {
|
|
45
|
+
context.res.setHeader('Cache-Control', `public, s-maxage=${60 * 60 * 2}`)
|
|
46
|
+
return getServerSideSitemapLegacy(context, paths)
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const storefrontAll = import.meta.graphCommerce.storefront
|
|
2
|
+
|
|
3
|
+
/** Get the current storefront config based on the provided locale */
|
|
4
|
+
export const storefrontConfig = (locale?: string | undefined) =>
|
|
5
|
+
storefrontAll.find((l) => l.locale === locale)
|
|
6
|
+
|
|
7
|
+
export const storefrontConfigDefault = () =>
|
|
8
|
+
storefrontAll.find((l) => l.defaultLocale) ?? storefrontAll[0]
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
import {
|
|
3
|
-
Controller,
|
|
4
|
-
ControllerProps,
|
|
5
|
-
FieldValues,
|
|
6
|
-
useController,
|
|
7
|
-
} from '@graphcommerce/react-hook-form'
|
|
8
|
-
import React, { MouseEventHandler } from 'react'
|
|
9
|
-
import { ActionCardProps } from './ActionCard'
|
|
10
|
-
import { ActionCardList, ActionCardListProps } from './ActionCardList'
|
|
11
|
-
|
|
12
|
-
export type ActionCardItemBase = Pick<ActionCardProps, 'value'>
|
|
13
|
-
|
|
14
|
-
export type ActionCardItemRenderProps<T> = ActionCardProps & {
|
|
15
|
-
onReset: MouseEventHandler<HTMLAnchorElement> & MouseEventHandler<HTMLSpanElement>
|
|
16
|
-
} & T
|
|
17
|
-
|
|
18
|
-
export type ActionCardListFormProps<A, F extends FieldValues = FieldValues> = Omit<
|
|
19
|
-
ActionCardListProps,
|
|
20
|
-
'value' | 'error' | 'onChange' | 'children'
|
|
21
|
-
> &
|
|
22
|
-
Omit<ControllerProps<F>, 'render'> & {
|
|
23
|
-
items: A[]
|
|
24
|
-
render: React.FC<ActionCardItemRenderProps<A>>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function ActionCardListForm<
|
|
28
|
-
T extends ActionCardItemBase,
|
|
29
|
-
F extends FieldValues = FieldValues,
|
|
30
|
-
>(props: ActionCardListFormProps<T, F>) {
|
|
31
|
-
const {
|
|
32
|
-
required,
|
|
33
|
-
rules,
|
|
34
|
-
items,
|
|
35
|
-
render,
|
|
36
|
-
control,
|
|
37
|
-
name,
|
|
38
|
-
errorMessage,
|
|
39
|
-
defaultValue,
|
|
40
|
-
multiple,
|
|
41
|
-
...other
|
|
42
|
-
} = props
|
|
43
|
-
const RenderItem = render as React.FC<ActionCardItemRenderProps<ActionCardItemBase>>
|
|
44
|
-
|
|
45
|
-
function onSelect(itemValue: unknown, selectValues: unknown) {
|
|
46
|
-
return multiple
|
|
47
|
-
? Array.isArray(selectValues) && selectValues.some((selectValue) => selectValue === itemValue)
|
|
48
|
-
: selectValues === itemValue
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const {
|
|
52
|
-
field: { onChange, value, ref },
|
|
53
|
-
fieldState,
|
|
54
|
-
formState,
|
|
55
|
-
} = useController({
|
|
56
|
-
...props,
|
|
57
|
-
control,
|
|
58
|
-
name,
|
|
59
|
-
defaultValue,
|
|
60
|
-
rules: { required: errorMessage || required, ...rules },
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<ActionCardList
|
|
65
|
-
{...other}
|
|
66
|
-
multiple={multiple}
|
|
67
|
-
required={required}
|
|
68
|
-
value={value}
|
|
69
|
-
ref={ref}
|
|
70
|
-
onChange={(_, incomming) => onChange(incomming)}
|
|
71
|
-
error={formState.isSubmitted && !!fieldState.error}
|
|
72
|
-
errorMessage={fieldState.error?.message}
|
|
73
|
-
>
|
|
74
|
-
{items.map((item) => (
|
|
75
|
-
<RenderItem
|
|
76
|
-
{...item}
|
|
77
|
-
key={item.value ?? ''}
|
|
78
|
-
value={item.value}
|
|
79
|
-
selected={onSelect(item.value, value)}
|
|
80
|
-
onReset={(e) => {
|
|
81
|
-
e.preventDefault()
|
|
82
|
-
onChange(null)
|
|
83
|
-
}}
|
|
84
|
-
/>
|
|
85
|
-
))}
|
|
86
|
-
</ActionCardList>
|
|
87
|
-
)
|
|
88
|
-
}
|
package/icons/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export { default as iconArrowBack } from './arrow-left.svg'
|
|
2
|
-
export { default as iconArrowForward } from './arrow-right.svg'
|
|
3
|
-
export { default as iconShoppingBag } from './bag.svg'
|
|
4
|
-
export { default as iconInvoice } from './box-alt.svg'
|
|
5
|
-
export { default as iconBox } from './box.svg'
|
|
6
|
-
export { default as iconOrderBefore } from './calendar.svg'
|
|
7
|
-
export { default as iconCancelAlt } from './cancel-alt.svg'
|
|
8
|
-
export { default as iconCartAdd } from './cart-add.svg'
|
|
9
|
-
export { default as iconCart } from './cart.svg'
|
|
10
|
-
export { default as iconChat } from './chat-alt.svg'
|
|
11
|
-
export { default as iconCustomerService } from './chat.svg'
|
|
12
|
-
export { default as iconChevronDown } from './chevron-down.svg'
|
|
13
|
-
export { default as iconChevronBack, default as iconChevronLeft } from './chevron-left.svg'
|
|
14
|
-
export { default as iconChevronRight } from './chevron-right.svg'
|
|
15
|
-
export { default as iconChevronUp } from './chevron-up.svg'
|
|
16
|
-
export { default as iconCirle } from './circle.svg'
|
|
17
|
-
export { default as iconClose } from './close.svg'
|
|
18
|
-
export { default as iconCreditCard, default as iconId } from './credit-card.svg'
|
|
19
|
-
export { default as iconEllypsis } from './ellypsis.svg'
|
|
20
|
-
export { default as iconEmail, default as iconEmailOutline } from './envelope-alt.svg'
|
|
21
|
-
export { default as icon404 } from './explore.svg'
|
|
22
|
-
export { default as iconEyeClosed } from './eye-closed.svg'
|
|
23
|
-
export { default as iconEyeCrossed } from './eye-crossed.svg'
|
|
24
|
-
export { default as iconEye } from './eye.svg'
|
|
25
|
-
export { default as iconHeart } from './favourite.svg'
|
|
26
|
-
export { default as iconMenu } from './hamburger.svg'
|
|
27
|
-
export { default as iconParty } from './happy-face.svg'
|
|
28
|
-
export { default as iconAddresses, default as iconHome } from './home-alt.svg'
|
|
29
|
-
export { default as iconLanguage } from './language.svg'
|
|
30
|
-
export { default as iconLocation } from './location.svg'
|
|
31
|
-
export { default as iconLock } from './lock.svg'
|
|
32
|
-
export { default as iconFullscreen } from './maximise.svg'
|
|
33
|
-
export { default as iconFullscreenExit } from './minimise.svg'
|
|
34
|
-
export { default as iconMin } from './minus.svg'
|
|
35
|
-
export { default as iconMoon } from './moon.svg'
|
|
36
|
-
export { default as iconNewspaper } from './news.svg'
|
|
37
|
-
export { default as iconCheckmark } from './ok.svg'
|
|
38
|
-
export { default as iconPerson } from './person-alt.svg'
|
|
39
|
-
export { default as iconPlay } from './play.svg'
|
|
40
|
-
export { default as iconPlus } from './plus.svg'
|
|
41
|
-
export { default as iconShutdown } from './power.svg'
|
|
42
|
-
export { default as iconRefresh } from './refresh.svg'
|
|
43
|
-
export { default as iconSadFace } from './sad-face.svg'
|
|
44
|
-
export { default as iconSearch } from './search.svg'
|
|
45
|
-
export { default as iconPhone } from './smartphone.svg'
|
|
46
|
-
export { default as iconStar } from './star.svg'
|
|
47
|
-
export { default as iconSun } from './sun.svg'
|
|
48
|
-
export { default as iconCompare } from './compare-arrows.svg'
|