vite-plugin-vanjs 0.0.7 → 0.0.9
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/README.md +3 -0
- package/jsx/jsx.mjs +20 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,9 @@ A mini meta-framework for [VanJS](https://vanjs.org/) developed around the aweso
|
|
|
20
20
|
|
|
21
21
|
The plugin will automatically load the appropriate Van or VanX objects depending on the client/server environment with zero configuration needed. It uses the `mini-van-plate/shared` module to register the required objects in an isomorphic enviroment.
|
|
22
22
|
|
|
23
|
+
Also in _development_ mode, the plugin will load the `van.debug.js` module to help you better troubleshoot your VanJS application.
|
|
24
|
+
|
|
25
|
+
|
|
23
26
|
### Notes
|
|
24
27
|
* The plugin uses `van-ext` along with `mini-van-plate` so you can have everything ready from the start.
|
|
25
28
|
|
package/jsx/jsx.mjs
CHANGED
|
@@ -2,10 +2,29 @@ import van from "../setup/van.mjs";
|
|
|
2
2
|
import setup from "../setup/index.mjs";
|
|
3
3
|
import { setAttribute, styleToString } from "../client/index.mjs";
|
|
4
4
|
|
|
5
|
-
export const jsx = (jsxTag, { children, ref, style, ...
|
|
5
|
+
export const jsx = (jsxTag, { children, ref, style, ...rest }) => {
|
|
6
|
+
// filter props with undefined values
|
|
7
|
+
const props = Object.fromEntries(
|
|
8
|
+
Object.entries(rest).filter(([_, val]) => val !== undefined),
|
|
9
|
+
);
|
|
10
|
+
|
|
6
11
|
if (typeof jsxTag === "string") {
|
|
7
12
|
const newElement = van.tags[jsxTag](props, children);
|
|
8
13
|
|
|
14
|
+
van.derive(() => {
|
|
15
|
+
/* istanbul ignore else */
|
|
16
|
+
if (style) {
|
|
17
|
+
const styleProp = typeof style === "function" ? style() : style;
|
|
18
|
+
const styleValue = styleToString(styleProp);
|
|
19
|
+
|
|
20
|
+
if (setup.isServer) {
|
|
21
|
+
newElement.propsStr += ` style="${styleValue}"`;
|
|
22
|
+
} else {
|
|
23
|
+
newElement.style.cssText = styleValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
9
28
|
// on server it's good enough to return here
|
|
10
29
|
if (setup.isServer) return newElement;
|
|
11
30
|
|
|
@@ -28,13 +47,6 @@ export const jsx = (jsxTag, { children, ref, style, ...props }) => {
|
|
|
28
47
|
|
|
29
48
|
setAttribute(newElement, k, value);
|
|
30
49
|
}
|
|
31
|
-
/* istanbul ignore else */
|
|
32
|
-
van.derive(() => {
|
|
33
|
-
if (style) {
|
|
34
|
-
const styleProp = typeof style === "function" ? style() : style;
|
|
35
|
-
newElement.style.cssText = styleToString(styleProp);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
50
|
|
|
39
51
|
if (ref) ref.val = { current: newElement };
|
|
40
52
|
|