@viewfly/scoped-css 0.0.26 → 0.0.27
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/bundles/css-modules.d.ts +1 -1
- package/bundles/index.esm.js +16 -23
- package/bundles/index.js +15 -22
- package/package.json +3 -3
package/bundles/css-modules.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { JSXInternal } from '@viewfly/core';
|
|
2
|
-
export declare function withScopedCSS(cssNamespace: string | string[], render: () => JSXInternal.
|
|
2
|
+
export declare function withScopedCSS(cssNamespace: string | string[], render: () => JSXInternal.JSXNode): () => JSXInternal.JSXNode;
|
package/bundles/index.esm.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
import { JSXElement
|
|
1
|
+
import { JSXElement } from '@viewfly/core';
|
|
2
2
|
|
|
3
|
-
function addOnScopedKeys(template, cssNamespace) {
|
|
4
|
-
if (template instanceof JSXElement || template instanceof JSXComponent) {
|
|
5
|
-
const children = template.props.children;
|
|
6
|
-
const nameSpaces = Array.isArray(cssNamespace) ? cssNamespace : [cssNamespace];
|
|
7
|
-
nameSpaces.forEach(i => {
|
|
8
|
-
if (typeof i === 'string' && i) {
|
|
9
|
-
template.props[i] = '';
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
if (Array.isArray(children)) {
|
|
13
|
-
children.forEach(child => {
|
|
14
|
-
addOnScopedKeys(child, cssNamespace);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
addOnScopedKeys(children, cssNamespace);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return template;
|
|
22
|
-
}
|
|
23
3
|
function withScopedCSS(cssNamespace, render) {
|
|
24
|
-
|
|
25
|
-
return
|
|
4
|
+
if (!cssNamespace) {
|
|
5
|
+
return render;
|
|
6
|
+
}
|
|
7
|
+
return function () {
|
|
8
|
+
const oldCreate = JSXElement.create;
|
|
9
|
+
const spaces = Array.isArray(cssNamespace) ? cssNamespace : [cssNamespace];
|
|
10
|
+
JSXElement.create = function (name, props, key) {
|
|
11
|
+
for (const scopedId of spaces) {
|
|
12
|
+
props[scopedId] = '';
|
|
13
|
+
}
|
|
14
|
+
return oldCreate.apply(JSXElement, [name, props, key]);
|
|
15
|
+
};
|
|
16
|
+
const vDom = render();
|
|
17
|
+
JSXElement.create = oldCreate;
|
|
18
|
+
return vDom;
|
|
26
19
|
};
|
|
27
20
|
}
|
|
28
21
|
|
package/bundles/index.js
CHANGED
|
@@ -2,29 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@viewfly/core');
|
|
4
4
|
|
|
5
|
-
function addOnScopedKeys(template, cssNamespace) {
|
|
6
|
-
if (template instanceof core.JSXElement || template instanceof core.JSXComponent) {
|
|
7
|
-
const children = template.props.children;
|
|
8
|
-
const nameSpaces = Array.isArray(cssNamespace) ? cssNamespace : [cssNamespace];
|
|
9
|
-
nameSpaces.forEach(i => {
|
|
10
|
-
if (typeof i === 'string' && i) {
|
|
11
|
-
template.props[i] = '';
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
if (Array.isArray(children)) {
|
|
15
|
-
children.forEach(child => {
|
|
16
|
-
addOnScopedKeys(child, cssNamespace);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
addOnScopedKeys(children, cssNamespace);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return template;
|
|
24
|
-
}
|
|
25
5
|
function withScopedCSS(cssNamespace, render) {
|
|
26
|
-
|
|
27
|
-
return
|
|
6
|
+
if (!cssNamespace) {
|
|
7
|
+
return render;
|
|
8
|
+
}
|
|
9
|
+
return function () {
|
|
10
|
+
const oldCreate = core.JSXElement.create;
|
|
11
|
+
const spaces = Array.isArray(cssNamespace) ? cssNamespace : [cssNamespace];
|
|
12
|
+
core.JSXElement.create = function (name, props, key) {
|
|
13
|
+
for (const scopedId of spaces) {
|
|
14
|
+
props[scopedId] = '';
|
|
15
|
+
}
|
|
16
|
+
return oldCreate.apply(core.JSXElement, [name, props, key]);
|
|
17
|
+
};
|
|
18
|
+
const vDom = render();
|
|
19
|
+
core.JSXElement.create = oldCreate;
|
|
20
|
+
return vDom;
|
|
28
21
|
};
|
|
29
22
|
}
|
|
30
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/scoped-css",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "A library for supporting scoped style sheets in the Viewfly framework。",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": [],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@viewfly/core": "^0.0.
|
|
15
|
+
"@viewfly/core": "^0.0.27"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@rollup/plugin-commonjs": "^25.0.3",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94"
|
|
36
36
|
}
|