@shopgate/engage 7.32.0-beta.3 → 7.32.0-beta.4
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/admin-preview/components/FrontendSettingsPreviewBridge/FrontendSettingsPreviewBridge.d.ts +2 -1
- package/admin-preview/components/FrontendSettingsPreviewBridge/FrontendSettingsPreviewBridge.d.ts.map +1 -1
- package/admin-preview/components/FrontendSettingsPreviewBridge/FrontendSettingsPreviewBridge.js +23 -1
- package/admin-preview/components/FrontendSettingsPreviewBridge/helpers.d.ts +7 -1
- package/admin-preview/components/FrontendSettingsPreviewBridge/helpers.d.ts.map +1 -1
- package/admin-preview/components/FrontendSettingsPreviewBridge/helpers.js +14 -2
- package/admin-preview/components/FrontendSettingsPreviewBridge/types.d.ts +6 -0
- package/admin-preview/components/FrontendSettingsPreviewBridge/types.d.ts.map +1 -1
- package/components/Badge/Badge.d.ts +30 -0
- package/components/Badge/Badge.d.ts.map +1 -0
- package/components/Badge/Badge.js +48 -0
- package/components/Badge/index.d.ts +3 -0
- package/components/Badge/index.d.ts.map +1 -0
- package/components/Badge/index.js +1 -0
- package/components/Badge/spec.d.ts +2 -0
- package/components/Badge/spec.d.ts.map +1 -0
- package/components/Badge/spec.js +75 -0
- package/components/View/components/Content/index.d.ts.map +1 -1
- package/components/View/components/Content/index.js +4 -1
- package/components/index.d.ts +1 -0
- package/components/index.d.ts.map +1 -1
- package/components/index.js +2 -1
- package/core/hooks/useLocalStorage.d.ts +8 -0
- package/core/hooks/useLocalStorage.d.ts.map +1 -1
- package/core/hooks/useLocalStorage.js +22 -15
- package/core/initialization/fetchSettings.d.ts +12 -0
- package/core/initialization/fetchSettings.d.ts.map +1 -0
- package/core/initialization/fetchSettings.js +134 -0
- package/core/initialization/index.d.ts +33 -2
- package/core/initialization/index.d.ts.map +1 -1
- package/core/initialization/index.js +25 -103
- package/package.json +9 -9
- package/product/components/Description/index.js +0 -2
- package/product/components/ProductCard/index.js +1 -0
- package/product/components/ProductGrid/components/Item/components/ItemDetails/index.js +1 -1
- package/product/components/ProductGrid/components/Item/components/ItemImage/index.js +10 -0
- package/product/components/ProductGrid/components/Item/components/ItemName/index.js +1 -0
- package/product/components/ProductGrid/components/Item/index.js +0 -1
- package/product/components/ProductGrid/components/Layout/index.js +17 -3
- package/product/components/ProductList/components/Layout/index.js +8 -20
- package/styles/helpers/index.d.ts +1 -0
- package/styles/helpers/index.js +1 -0
- package/styles/helpers/loadThemeCss.d.ts +14 -0
- package/styles/helpers/loadThemeCss.d.ts.map +1 -0
- package/styles/helpers/loadThemeCss.js +112 -0
- package/styles/index.d.ts +1 -1
- package/styles/index.d.ts.map +1 -1
- package/styles/reset/root.js +1 -1
- package/styles/theme/createDefaultThemeOptions/index.d.ts.map +1 -1
- package/styles/theme/createDefaultThemeOptions/index.js +12 -1
- package/styles/theme/createTheme/createComponents.types.d.ts +22 -0
- package/styles/theme/createTheme/createComponents.types.d.ts.map +1 -1
- package/styles/theme/createTheme/createComponents.types.js +23 -1
- package/styles/theme/createTheme/createCssVarsForColorSchemeThemes.d.ts.map +1 -1
- package/styles/theme/createTheme/createCssVarsForColorSchemeThemes.js +4 -1
- package/styles/theme/createTheme/index.d.ts +1 -0
- package/styles/theme/createTheme/index.d.ts.map +1 -1
- package/styles/theme/createTheme/index.js +2 -0
- package/styles/theme/createTheme/types.d.ts +2 -2
- package/styles/theme/createTheme/types.d.ts.map +1 -1
- package/styles/theme/createTheme/types.js +2 -3
- package/styles/theme/hooks/useColorScheme.d.ts +4 -3
- package/styles/theme/hooks/useColorScheme.d.ts.map +1 -1
- package/styles/theme/hooks/useColorScheme.js +4 -3
- package/styles/theme/index.d.ts +1 -1
- package/styles/theme/index.d.ts.map +1 -1
- package/styles/theme/providers/ColorSchemeContext.d.ts +19 -0
- package/styles/theme/providers/ColorSchemeContext.d.ts.map +1 -0
- package/styles/theme/providers/ColorSchemeContext.js +6 -0
- package/styles/theme/providers/ThemeProvider.d.ts +2 -12
- package/styles/theme/providers/ThemeProvider.d.ts.map +1 -1
- package/styles/theme/providers/ThemeProvider.js +32 -8
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { withScope, captureMessage, Severity as SentrySeverity } from '@sentry/browser';
|
|
2
|
+
import { appConfig } from '@shopgate/engage';
|
|
3
|
+
const REQUEST_TIMEOUT = 3000;
|
|
4
|
+
const LINK_TAG_ID = 'theme-css';
|
|
5
|
+
const INSERTION_POINT_SELECTOR = 'meta[name="theme-css-insertion-point"]';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Inserts the link at the theme css insertion point, which the html template declares between the
|
|
9
|
+
* emotion insertion point and the preview one. That position is what makes the cascade order
|
|
10
|
+
* structural rather than incidental: every tss style is pinned above it, and the admin preview
|
|
11
|
+
* pins its style tag to the anchor below it.
|
|
12
|
+
*
|
|
13
|
+
* Falls back to appending when the meta is absent - a head without the anchor still yields the
|
|
14
|
+
* desired order for anything that was already inserted, it just no longer guarantees it.
|
|
15
|
+
* @param linkTag The link tag to insert.
|
|
16
|
+
*/
|
|
17
|
+
const insertLinkTag = linkTag => {
|
|
18
|
+
const insertionPoint = document.querySelector(INSERTION_POINT_SELECTOR);
|
|
19
|
+
if (!insertionPoint) {
|
|
20
|
+
document.head.appendChild(linkTag);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
insertionPoint.parentNode?.insertBefore(linkTag, insertionPoint.nextSibling);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Loads the theme css file. It overrides the css custom properties that are generated during
|
|
28
|
+
* theme initialization, so it has to win the cascade against them - see `insertLinkTag` for how
|
|
29
|
+
* that order is established.
|
|
30
|
+
*
|
|
31
|
+
* A link applies at its position in the dom rather than at the time it finished loading, so the
|
|
32
|
+
* timeout below only decides how long app start waits - never which styles win.
|
|
33
|
+
*
|
|
34
|
+
* Resolves when the file loaded, when it failed, or when REQUEST_TIMEOUT elapsed - it never
|
|
35
|
+
* rejects, since the file is not guaranteed to exist and must not be able to block app start.
|
|
36
|
+
* @returns A promise that resolves once the file settled.
|
|
37
|
+
*/
|
|
38
|
+
export const loadThemeCss = () => new Promise(resolve => {
|
|
39
|
+
const {
|
|
40
|
+
themeCssUrl: href
|
|
41
|
+
} = appConfig;
|
|
42
|
+
if (!href) {
|
|
43
|
+
resolve();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let settled = false;
|
|
47
|
+
let timeout;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the promise once, whichever of load / error / timeout comes first.
|
|
51
|
+
*/
|
|
52
|
+
const settle = () => {
|
|
53
|
+
if (settled) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
settled = true;
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
resolve();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Starts the fallback that keeps app start from waiting on a stalled request. The link is
|
|
63
|
+
* deliberately left in place when the timeout hits: it still applies once it eventually loads,
|
|
64
|
+
* it just no longer holds up app start.
|
|
65
|
+
*/
|
|
66
|
+
const startTimeoutFallback = () => {
|
|
67
|
+
timeout = setTimeout(() => {
|
|
68
|
+
withScope(scope => {
|
|
69
|
+
scope.setLevel(SentrySeverity.Warning);
|
|
70
|
+
scope.setExtra('themeCssUrl', href);
|
|
71
|
+
scope.setExtra('timeout', REQUEST_TIMEOUT);
|
|
72
|
+
captureMessage('Fetching theme css took too long');
|
|
73
|
+
});
|
|
74
|
+
settle();
|
|
75
|
+
}, REQUEST_TIMEOUT);
|
|
76
|
+
};
|
|
77
|
+
const existingTag = document.querySelector(`#${LINK_TAG_ID}`);
|
|
78
|
+
if (existingTag) {
|
|
79
|
+
// Already loaded
|
|
80
|
+
if (existingTag.sheet) {
|
|
81
|
+
resolve();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Still loading - a stalled request must not leave the promise pending, so arm the timeout
|
|
86
|
+
// here too rather than relying on the load / error events alone.
|
|
87
|
+
existingTag.addEventListener('load', settle, {
|
|
88
|
+
once: true
|
|
89
|
+
});
|
|
90
|
+
existingTag.addEventListener('error', settle, {
|
|
91
|
+
once: true
|
|
92
|
+
});
|
|
93
|
+
startTimeoutFallback();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const linkTag = document.createElement('link');
|
|
97
|
+
linkTag.rel = 'stylesheet';
|
|
98
|
+
linkTag.type = 'text/css';
|
|
99
|
+
linkTag.href = href;
|
|
100
|
+
linkTag.id = LINK_TAG_ID;
|
|
101
|
+
linkTag.onload = settle;
|
|
102
|
+
linkTag.onerror = () => {
|
|
103
|
+
withScope(scope => {
|
|
104
|
+
scope.setLevel(SentrySeverity.Error);
|
|
105
|
+
scope.setExtra('themeCssUrl', href);
|
|
106
|
+
captureMessage('Fetching theme css failed');
|
|
107
|
+
});
|
|
108
|
+
settle();
|
|
109
|
+
};
|
|
110
|
+
insertLinkTag(linkTag);
|
|
111
|
+
startTimeoutFallback();
|
|
112
|
+
});
|
package/styles/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './helpers';
|
|
2
|
-
export { ThemeProvider, createTheme, useActiveBreakpoint, useMediaQuery, useResponsiveValue, useTheme, useColorScheme, withTheme, type Theme, type PaletteColorsWithMain, type WithThemeProps, } from './theme';
|
|
2
|
+
export { ThemeProvider, createTheme, useActiveBreakpoint, useMediaQuery, useResponsiveValue, useTheme, useColorScheme, withTheme, type Theme, type ColorSchemeName, type PaletteColorsWithMain, type WithThemeProps, } from './theme';
|
|
3
3
|
export { makeStyles, withStyles, useStyles, css, cx, tss, GlobalStyles, injectGlobal, keyframes, } from './tss';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/styles/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../styles/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,SAAS,EACT,KAAK,KAAK,EACV,KAAK,qBAAqB,EAC1B,KAAK,cAAc,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,UAAU,EACV,UAAU,EACV,SAAS,EACT,GAAG,EACH,EAAE,EACF,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,MAAM,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../styles/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,SAAS,EACT,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,UAAU,EACV,UAAU,EACV,SAAS,EACT,GAAG,EACH,EAAE,EACF,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,MAAM,OAAO,CAAC"}
|
package/styles/reset/root.js
CHANGED
|
@@ -38,7 +38,7 @@ injectGlobal({
|
|
|
38
38
|
WebkitOverflowScrolling: 'touch',
|
|
39
39
|
WebkitUserSelect: hasWebBridge() ? 'inherit' : 'none',
|
|
40
40
|
userSelect: hasWebBridge() ? 'inherit' : 'none',
|
|
41
|
-
color: 'var(--color-text-high-emphasis)'
|
|
41
|
+
color: 'var(--sg-palette-text-primary, var(--color-text-high-emphasis))'
|
|
42
42
|
},
|
|
43
43
|
'[data-pattern]': {
|
|
44
44
|
height: '100% !important'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createDefaultThemeOptions/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createDefaultThemeOptions/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QAAO,YAuH3C,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getCSSCustomProp } from '@shopgate/engage/styles';
|
|
2
2
|
import { themeConfig } from '@shopgate/engage';
|
|
3
3
|
const {
|
|
4
|
-
colors
|
|
4
|
+
colors,
|
|
5
|
+
settings
|
|
5
6
|
} = themeConfig;
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -66,6 +67,11 @@ export const createDefaultThemeOptions = () => ({
|
|
|
66
67
|
background: getCSSCustomProp('--color-button-cta') || getCSSCustomProp('--color-primary')
|
|
67
68
|
}
|
|
68
69
|
},
|
|
70
|
+
badge: {
|
|
71
|
+
vars: {
|
|
72
|
+
background: getCSSCustomProp('--color-secondary')
|
|
73
|
+
}
|
|
74
|
+
},
|
|
69
75
|
snackbar: {
|
|
70
76
|
vars: {
|
|
71
77
|
background: '#323232'
|
|
@@ -88,6 +94,11 @@ export const createDefaultThemeOptions = () => ({
|
|
|
88
94
|
badgeLeft: 'var(--tab-bar-item-badge-left, calc(50% + 20px))'
|
|
89
95
|
}
|
|
90
96
|
},
|
|
97
|
+
appBar: {
|
|
98
|
+
vars: {
|
|
99
|
+
background: settings?.['@shopgate/engage/components/AppBar']?.background || '#FFF'
|
|
100
|
+
}
|
|
101
|
+
},
|
|
91
102
|
ratingStars: {
|
|
92
103
|
vars: {
|
|
93
104
|
filled: `var(--rating-stars-filled, ${getCSSCustomProp('--color-primary')})`,
|
|
@@ -131,6 +131,17 @@ export declare const componentsSchema: {
|
|
|
131
131
|
readonly color: "";
|
|
132
132
|
};
|
|
133
133
|
};
|
|
134
|
+
readonly appBar: {
|
|
135
|
+
readonly vars: {
|
|
136
|
+
readonly background: "";
|
|
137
|
+
readonly color: "";
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
readonly badge: {
|
|
141
|
+
readonly vars: {
|
|
142
|
+
readonly background: "";
|
|
143
|
+
};
|
|
144
|
+
};
|
|
134
145
|
readonly discountBadge: {
|
|
135
146
|
readonly vars: {
|
|
136
147
|
readonly background: "";
|
|
@@ -231,6 +242,17 @@ export declare const componentsDefaults: {
|
|
|
231
242
|
color: (t: Theme) => string;
|
|
232
243
|
};
|
|
233
244
|
};
|
|
245
|
+
appBar: {
|
|
246
|
+
vars: {
|
|
247
|
+
background: string;
|
|
248
|
+
color: (t: Theme) => string;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
badge: {
|
|
252
|
+
vars: {
|
|
253
|
+
background: (t: Theme) => string;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
234
256
|
discountBadge: {
|
|
235
257
|
vars: {
|
|
236
258
|
background: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createComponents.types.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/createComponents.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,KAAK,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAE3C;;;GAGG;AACH,KAAK,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAClC,MAAM,GACN,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,o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O,GACnB,OAAO,CAAC,CAAC,CAAC,SAAS;QAAE,IAAI,EAAE,MAAM,KAAK,CAAA;KAAE,GACtC,oBAAoB,CAAC,KAAK,CAAC,GAC3B,KAAK;CACR,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"createComponents.types.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/createComponents.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,KAAK,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAE3C;;;GAGG;AACH,KAAK,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAClC,MAAM,GACN,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,oBAAoB,CAAC,OAAO,IACtC,OAAO,SAAS,IAAI,GAAG,MAAM,GAC3B,OAAO,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,GACzE,OAAO,SAAS,MAAM,GAAG;KAAG,CAAC,IAAI,MAAM,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAAE,GACnF,MAAM,CAAC;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,CAAC,OAAO,EAAE,MAAM,IACtD,OAAO,SAAS,IAAI,GAAG,mBAAmB,CAAC,MAAM,CAAC,GAChD,OAAO,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,4BAA4B,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,GACzF,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BAAkB,GAC5B,4BAA4B,CAAC,OAAO,gBAAgB,EAAE,KAAK,CAAC,CAAC;AAG/D,MAAM,MAAM,iBAAiB,GAC3B,4BAA4B,CAAC,OAAO,gBAAgB,EAAE,KAAK,CAAC,CAAC;AAG/D,MAAM,MAAM,UAAU,GAAG,oBAAoB,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEvE,MAAM,MAAM,aAAa,GAAG,uBAAuB,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -119,6 +119,17 @@ export const componentsSchema = {
|
|
|
119
119
|
color: ''
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
|
+
appBar: {
|
|
123
|
+
vars: {
|
|
124
|
+
background: '',
|
|
125
|
+
color: ''
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
badge: {
|
|
129
|
+
vars: {
|
|
130
|
+
background: ''
|
|
131
|
+
}
|
|
132
|
+
},
|
|
122
133
|
discountBadge: {
|
|
123
134
|
vars: {
|
|
124
135
|
background: ''
|
|
@@ -217,7 +228,18 @@ export const componentsDefaults = {
|
|
|
217
228
|
ctaButton: {
|
|
218
229
|
vars: {
|
|
219
230
|
background: t => t.palette.primary.main,
|
|
220
|
-
color: t => t.
|
|
231
|
+
color: t => t.contrastColor('var(--sg-components-ctaButton-background)')
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
appBar: {
|
|
235
|
+
vars: {
|
|
236
|
+
background: '#FFFFFF',
|
|
237
|
+
color: t => t.contrastColor('var(--sg-components-appBar-background)')
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
badge: {
|
|
241
|
+
vars: {
|
|
242
|
+
background: t => t.palette.secondary.main
|
|
221
243
|
}
|
|
222
244
|
},
|
|
223
245
|
discountBadge: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCssVarsForColorSchemeThemes.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/createCssVarsForColorSchemeThemes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,KAAK,EACV,iBAAiB,EAAE,SAAS,EAAmB,YAAY,EAC5D,MAAM,SAAS,CAAC;AAEjB,KAAK,wCAAwC,GAAG;IAC9C,sBAAsB,EAAE,sBAAsB,CAAC;CAChD,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAEvC,MAAM,MAAM,4CAA4C,GAAG;IACzD;;;OAGG;IACH,YAAY,EAAE,SAAS,GAAG;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,CAAC;IAC9C;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;CAC7C,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,YAAY,EAAE,iBAAiB,EAC/B,OAAO,EAAE,wCAAwC,GAChD,4CAA4C,
|
|
1
|
+
{"version":3,"file":"createCssVarsForColorSchemeThemes.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/createCssVarsForColorSchemeThemes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,KAAK,EACV,iBAAiB,EAAE,SAAS,EAAmB,YAAY,EAC5D,MAAM,SAAS,CAAC;AAEjB,KAAK,wCAAwC,GAAG;IAC9C,sBAAsB,EAAE,sBAAsB,CAAC;CAChD,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAEvC,MAAM,MAAM,4CAA4C,GAAG;IACzD;;;OAGG;IACH,YAAY,EAAE,SAAS,GAAG;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,CAAC;IAC9C;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;CAC7C,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,YAAY,EAAE,iBAAiB,EAC/B,OAAO,EAAE,wCAAwC,GAChD,4CAA4C,CA6G9C"}
|
|
@@ -40,7 +40,10 @@ export default function createCssVarsForColorSchemeThemes(colorSchemes, options)
|
|
|
40
40
|
}), rest, cssVarPrefix);
|
|
41
41
|
|
|
42
42
|
// Resolve component token values to actual CSS variable references
|
|
43
|
-
const resolvedComponents = flattenComponentVars(resolveComponentsValues(componentsInput,
|
|
43
|
+
const resolvedComponents = flattenComponentVars(resolveComponentsValues(componentsInput, {
|
|
44
|
+
...rest,
|
|
45
|
+
...vars
|
|
46
|
+
}));
|
|
44
47
|
const {
|
|
45
48
|
css: componentsCss,
|
|
46
49
|
vars: componentsVars,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ThemeOptions, type ThemeInternal } from './types';
|
|
2
2
|
export type { Theme, BaseTheme, ThemeInternal, ThemeOptions, Breakpoint, ColorSchemeName, ColorSchemeSelectorType, PaletteColorsWithMain, } from './types';
|
|
3
|
+
export { COLOR_SCHEME_NAMES } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a theme object for the ThemeProvider.
|
|
5
6
|
* @param options The theme options.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,UAAS,YAAiB,KAAG,aAkExD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,UAAS,YAAiB,KAAG,aAkExD,CAAC"}
|
|
@@ -9,6 +9,8 @@ import createThemeFromColorScheme from "./createThemeFromColorScheme";
|
|
|
9
9
|
import createCssVarsForColorSchemeThemes from "./createCssVarsForColorSchemeThemes";
|
|
10
10
|
import applyStyles from "./applyStyles";
|
|
11
11
|
import { createGetColorSchemeSelector, createSetActiveColorScheme } from "./helpers";
|
|
12
|
+
export { COLOR_SCHEME_NAMES } from "./types";
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Creates a theme object for the ThemeProvider.
|
|
14
16
|
* @param options The theme options.
|
|
@@ -13,8 +13,8 @@ import type { Shape, ShapeOptions } from './createShape';
|
|
|
13
13
|
import type { Shadows } from './shadows';
|
|
14
14
|
export type { Breakpoint } from './createBreakpoints';
|
|
15
15
|
export type { PaletteColorsWithMain } from './createPalette';
|
|
16
|
-
declare const
|
|
17
|
-
export type ColorSchemeName = (typeof
|
|
16
|
+
export declare const COLOR_SCHEME_NAMES: readonly ["light", "dark"];
|
|
17
|
+
export type ColorSchemeName = (typeof COLOR_SCHEME_NAMES)[number];
|
|
18
18
|
declare const selectorTypes: readonly ["data", "class"];
|
|
19
19
|
export type ColorSchemeSelectorType = (typeof selectorTypes)[number];
|
|
20
20
|
type DeepPartial<T> = T extends object ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,4CAA4C,EAAE,MAAM,qCAAqC,CAAC;AACxG,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAA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|
/**
|
|
@@ -17,5 +17,4 @@ const selectorTypes = ['data', 'class'];
|
|
|
17
17
|
/**
|
|
18
18
|
* A record of themes for each color scheme. Each key is a color scheme name (e.g., 'light', 'dark'),
|
|
19
19
|
* and the value is a fully-resolved color-scheme theme ({@link ColorSchemeTheme}).
|
|
20
|
-
*/
|
|
21
|
-
export {};
|
|
20
|
+
*/
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @returns
|
|
2
|
+
* Provides access to the color scheme context.
|
|
3
|
+
* @returns The color scheme context value, containing the current `mode`, a `setMode` function to
|
|
4
|
+
* update it, and the list of `modes` the active theme actually provides.
|
|
4
5
|
*/
|
|
5
|
-
declare const useColorScheme: () => import("../providers/
|
|
6
|
+
declare const useColorScheme: () => import("../providers/ColorSchemeContext").ColorSchemeContextValue;
|
|
6
7
|
export default useColorScheme;
|
|
7
8
|
//# sourceMappingURL=useColorScheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useColorScheme.d.ts","sourceRoot":"","sources":["../../../../styles/theme/hooks/useColorScheme.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"useColorScheme.d.ts","sourceRoot":"","sources":["../../../../styles/theme/hooks/useColorScheme.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,QAAA,MAAM,cAAc,yEAAuC,CAAC;AAE5D,eAAe,cAAc,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import { ColorSchemeContext } from "../providers/
|
|
2
|
+
import { ColorSchemeContext } from "../providers/ColorSchemeContext";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @returns
|
|
5
|
+
* Provides access to the color scheme context.
|
|
6
|
+
* @returns The color scheme context value, containing the current `mode`, a `setMode` function to
|
|
7
|
+
* update it, and the list of `modes` the active theme actually provides.
|
|
7
8
|
*/
|
|
8
9
|
const useColorScheme = () => useContext(ColorSchemeContext);
|
|
9
10
|
export default useColorScheme;
|
package/styles/theme/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as ThemeProvider } from './providers/ThemeProvider';
|
|
2
2
|
export { createTheme } from './createTheme';
|
|
3
|
-
export type { Theme, Breakpoint, PaletteColorsWithMain } from './createTheme';
|
|
3
|
+
export type { Theme, Breakpoint, PaletteColorsWithMain, ColorSchemeName, } from './createTheme';
|
|
4
4
|
export { useActiveBreakpoint, useMediaQuery, useResponsiveValue, useTheme, useColorScheme, } from './hooks';
|
|
5
5
|
export { withTheme, type WithThemeProps } from './hocs';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../styles/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../styles/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EACV,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,eAAe,GAC1D,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
|
+
import { type ColorSchemeName } from '../createTheme';
|
|
3
|
+
export interface ColorSchemeContextValue {
|
|
4
|
+
/**
|
|
5
|
+
* The current color scheme (e.g., 'light' or 'dark')
|
|
6
|
+
*/
|
|
7
|
+
mode: ColorSchemeName | null;
|
|
8
|
+
/**
|
|
9
|
+
* Function to update the color scheme
|
|
10
|
+
*/
|
|
11
|
+
setMode: Dispatch<SetStateAction<ColorSchemeName | null>>;
|
|
12
|
+
/**
|
|
13
|
+
* The modes the active theme actually provides. Only these can be set - passing anything else
|
|
14
|
+
* to setMode has no effect.
|
|
15
|
+
*/
|
|
16
|
+
modes: ColorSchemeName[];
|
|
17
|
+
}
|
|
18
|
+
export declare const ColorSchemeContext: import("react").Context<ColorSchemeContextValue>;
|
|
19
|
+
//# sourceMappingURL=ColorSchemeContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorSchemeContext.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ColorSchemeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7B;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1D;;;OAGG;IACH,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,eAAO,MAAM,kBAAkB,kDAI7B,CAAC"}
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import { type Theme, type ThemeInternal
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
* The current color scheme (e.g., 'light' or 'dark')
|
|
5
|
-
*/
|
|
6
|
-
mode: ColorSchemeName | null;
|
|
7
|
-
/**
|
|
8
|
-
* Function to update the color scheme
|
|
9
|
-
*/
|
|
10
|
-
setMode: React.Dispatch<React.SetStateAction<ColorSchemeName | null>>;
|
|
11
|
-
}
|
|
1
|
+
import { type Theme, type ThemeInternal } from '../createTheme';
|
|
2
|
+
export { ColorSchemeContext, type ColorSchemeContextValue } from './ColorSchemeContext';
|
|
12
3
|
export declare const ThemeContext: import("react").Context<Theme>;
|
|
13
|
-
export declare const ColorSchemeContext: import("react").Context<ColorSchemeContextValue>;
|
|
14
4
|
type ThemeProviderProps = {
|
|
15
5
|
/**
|
|
16
6
|
* The theme object to provide to the context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ThemeProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ThemeProvider.tsx"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,KAAK,EAAE,KAAK,aAAa,EAC/B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAExF,eAAO,MAAM,YAAY,gCAAqC,CAAC;AAwE/D,KAAK,kBAAkB,GAAG;IACxB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAA;mFAtEE,kBAAkB;AAwErB,wBAAmC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.array.includes.js";
|
|
2
|
+
import { createContext, memo, useCallback, useMemo, useLayoutEffect } from 'react';
|
|
2
3
|
import useLocalStorage from '@shopgate/engage/core/hooks/useLocalStorage';
|
|
4
|
+
import { logger } from '@shopgate/engage/core/helpers';
|
|
3
5
|
import { GlobalStyles } from '@shopgate/engage/styles';
|
|
4
6
|
import { isFrontendSettingsAdminPreviewActive } from '@shopgate/engage/admin-preview/helpers';
|
|
5
7
|
import { FrontendSettingsPreviewBridge } from '@shopgate/engage/admin-preview/components';
|
|
6
8
|
import ActiveBreakpointProvider from "./ActiveBreakpointProvider";
|
|
9
|
+
import { ColorSchemeContext } from "./ColorSchemeContext";
|
|
7
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
export { ColorSchemeContext } from "./ColorSchemeContext";
|
|
8
12
|
export const ThemeContext = /*#__PURE__*/createContext({});
|
|
9
|
-
export const ColorSchemeContext = /*#__PURE__*/createContext({
|
|
10
|
-
mode: 'light',
|
|
11
|
-
setMode: () => ''
|
|
12
|
-
});
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The ThemeProvider component provides the theme context to its children.
|
|
@@ -18,13 +18,37 @@ const ThemeProvider = ({
|
|
|
18
18
|
children,
|
|
19
19
|
theme
|
|
20
20
|
}) => {
|
|
21
|
+
// The color schemes the active theme actually provides. createTheme() can be configured with only
|
|
22
|
+
// a subset of the possible schemes (it defaults to just `light`), so `modes` and the validation
|
|
23
|
+
// below are derived from the resolved theme rather than the full COLOR_SCHEME_NAMES tuple.
|
|
24
|
+
// Otherwise the provider could expose and accept a scheme (e.g. `dark`) the theme doesn't style,
|
|
25
|
+
// and setActiveColorScheme would flip the root selector to an unstyled scheme.
|
|
26
|
+
const modes = useMemo(() => Object.keys(theme.colorSchemes), [theme]);
|
|
21
27
|
const [activeColorScheme, setActiveColorScheme] = useLocalStorage('persistedColorScheme', {
|
|
22
|
-
initialValue: theme.defaultColorScheme
|
|
28
|
+
initialValue: theme.defaultColorScheme,
|
|
29
|
+
// The frontend settings preview runs the app in an iframe on the shop origin. Persisting the
|
|
30
|
+
// color scheme there would write the admin's preview choice into the visitor's own storage and
|
|
31
|
+
// outlive the preview, so the scheme is kept in memory only while previewing.
|
|
32
|
+
persist: !isFrontendSettingsAdminPreviewActive()
|
|
23
33
|
});
|
|
34
|
+
|
|
35
|
+
// Wraps the raw storage setter, so an unsupported mode is rejected before it is persisted.
|
|
36
|
+
// Setting null is allowed and clears the stored preference.
|
|
37
|
+
const setMode = useCallback(value => {
|
|
38
|
+
setActiveColorScheme(currentColorScheme => {
|
|
39
|
+
const nextColorScheme = typeof value === 'function' ? value(currentColorScheme) : value;
|
|
40
|
+
if (nextColorScheme !== null && !modes.includes(nextColorScheme)) {
|
|
41
|
+
logger.warn(`ThemeProvider: "${nextColorScheme}" is not a supported color scheme.`);
|
|
42
|
+
return currentColorScheme;
|
|
43
|
+
}
|
|
44
|
+
return nextColorScheme;
|
|
45
|
+
});
|
|
46
|
+
}, [modes, setActiveColorScheme]);
|
|
24
47
|
const colorSchemeContextValue = useMemo(() => ({
|
|
25
48
|
mode: activeColorScheme,
|
|
26
|
-
setMode
|
|
27
|
-
|
|
49
|
+
setMode,
|
|
50
|
+
modes
|
|
51
|
+
}), [activeColorScheme, modes, setMode]);
|
|
28
52
|
useLayoutEffect(() => {
|
|
29
53
|
if (!activeColorScheme) return;
|
|
30
54
|
theme.setActiveColorScheme(activeColorScheme);
|