1
+ import { SELECTOR , QUERIES , ELEMENTS } from "./index" ;
2
+
1
3
/**
2
4
* Runs through all selectors of a meta object.
3
5
* @param {{} } meta
@@ -30,8 +32,9 @@ const mapMetaSelectors = (meta, cb) => {
30
32
* @return {{} }
31
33
*/
32
34
const remapMetaSelectors = ( rawMeta , styles ) => {
33
- // If meta is a string, then assume it's from a css-loader export
34
- // todo trim quotations instead of just slicing
35
+ // If meta is a string, then assume it's from a css-loader export.
36
+ // Unfortunately css-loader will add quotations around the exported JSON, so
37
+ // we need to trim that.
35
38
const meta =
36
39
typeof rawMeta === "string" ? JSON . parse ( rawMeta . slice ( 1 , - 1 ) ) : rawMeta ;
37
40
@@ -51,13 +54,27 @@ const remapMetaSelectors = (rawMeta, styles) => {
51
54
*/
52
55
const getMappedCssClass = selector => `.${ styles [ selector . slice ( 1 ) ] } ` ;
53
56
54
- mapMetaSelectors ( meta , selector => {
55
- if ( ! hasSelectorInStyles ( selector ) ) {
56
- return selector ;
57
- }
57
+ // We need to differentiate between single- and multi container mode here, as
58
+ // the meta object's structure would be slightly different.
59
+ if ( meta [ SELECTOR ] ) {
60
+ mapMetaSelectors ( meta , selector => {
61
+ if ( ! hasSelectorInStyles ( selector ) ) {
62
+ return selector ;
63
+ }
58
64
59
- return getMappedCssClass ( selector ) ;
60
- } ) ;
65
+ return getMappedCssClass ( selector ) ;
66
+ } ) ;
67
+ } else {
68
+ for ( let selector of Object . keys ( meta ) ) {
69
+ mapMetaSelectors ( meta [ selector ] , selector => {
70
+ if ( ! hasSelectorInStyles ( selector ) ) {
71
+ return selector ;
72
+ }
73
+
74
+ return getMappedCssClass ( selector ) ;
75
+ } ) ;
76
+ }
77
+ }
61
78
62
79
return meta ;
63
80
} ;
0 commit comments