@builder.io/mitosis 0.0.55 → 0.0.56-2
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/dist/src/__tests__/data/blocks/rootShow.raw.d.ts +3 -0
- package/dist/src/__tests__/data/blocks/rootShow.raw.jsx +9 -0
- package/dist/src/__tests__/react.test.js +6 -0
- package/dist/src/generators/html.js +3 -3
- package/dist/src/generators/react.js +11 -1
- package/dist/src/helpers/render-imports.d.ts +1 -1
- package/dist/src/types/mitosis-node.d.ts +21 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function RenderStyles(props) {
|
|
5
|
+
return (<mitosis_1.Show when={props.foo === 'bar'} else={<div>Foo</div>}>
|
|
6
|
+
<div>Bar</div>
|
|
7
|
+
</mitosis_1.Show>);
|
|
8
|
+
}
|
|
9
|
+
exports.default = RenderStyles;
|
|
@@ -24,6 +24,7 @@ var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
|
|
|
24
24
|
var multipleOnUpdate = require('./data/blocks/multiple-onUpdate.raw');
|
|
25
25
|
var multipleOnUpdateWithDeps = require('./data/blocks/multiple-onUpdateWithDeps.raw');
|
|
26
26
|
var onMount = require('./data/blocks/onMount.raw');
|
|
27
|
+
var rootShow = require('./data/blocks/rootShow.raw');
|
|
27
28
|
describe('React', function () {
|
|
28
29
|
test('Basic', function () {
|
|
29
30
|
var component = (0, jsx_1.parseJsx)(basic);
|
|
@@ -138,4 +139,9 @@ describe('React', function () {
|
|
|
138
139
|
var output = (0, react_1.componentToReact)()({ component: component });
|
|
139
140
|
expect(output).toMatchSnapshot();
|
|
140
141
|
});
|
|
142
|
+
test('rootShow', function () {
|
|
143
|
+
var component = (0, jsx_1.parseJsx)(rootShow);
|
|
144
|
+
var output = (0, react_1.componentToReact)({ prettier: false })({ component: component });
|
|
145
|
+
expect(output).toMatchSnapshot();
|
|
146
|
+
});
|
|
141
147
|
});
|
|
@@ -167,12 +167,12 @@ var blockToHtml = function (json, options) {
|
|
|
167
167
|
str += '</template>';
|
|
168
168
|
}
|
|
169
169
|
else if (json.name === 'Show') {
|
|
170
|
-
addOnChangeJs(elId, options, "
|
|
171
|
-
str += "<
|
|
170
|
+
addOnChangeJs(elId, options, "\n if(".concat(json.bindings.when.replace(/;$/, ''), ") {\n \tconst clonedElement = el.content.cloneNode(true);\n const endTag = document.createElement('template');\n endTag.setAttribute('data-show', '").concat(elId, "-end');\n\t\t\t\t\n el.after(endTag);\n el.after(clonedElement)\n } else {\n if (this.querySelector(\"[data-show='").concat(elId, "-end']\") === null) {\n \treturn;\n }\n\n let sibling = el.nextSibling;\n const toBeRemoved = [];\n while (sibling) {\n toBeRemoved.push(sibling);\n if (sibling?.dataset?.show === '").concat(elId, "-end') {\n \ttoBeRemoved.forEach(sib => sib.remove());\n return;\n } \n sibling = sibling.nextSibling;\n }\n } \n "));
|
|
171
|
+
str += "<template data-name=\"".concat(elId, "\">");
|
|
172
172
|
if (json.children) {
|
|
173
173
|
str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
|
|
174
174
|
}
|
|
175
|
-
str += '</
|
|
175
|
+
str += '</template>';
|
|
176
176
|
}
|
|
177
177
|
else {
|
|
178
178
|
str += "<".concat(json.name, " ");
|
|
@@ -49,6 +49,14 @@ var plugins_1 = require("../modules/plugins");
|
|
|
49
49
|
var jsx_1 = require("../parsers/jsx");
|
|
50
50
|
var context_1 = require("./helpers/context");
|
|
51
51
|
var react_native_1 = require("./react-native");
|
|
52
|
+
/**
|
|
53
|
+
* If the root Mitosis component only has 1 child, and it is a `Show` node, then we need to wrap it in a fragment.
|
|
54
|
+
* Otherwise, we end up with invalid React render code.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
var isRootShowNode = function (json) {
|
|
58
|
+
return json.children.length === 1 && ['Show'].includes(json.children[0].name);
|
|
59
|
+
};
|
|
52
60
|
var wrapInFragment = function (json) {
|
|
53
61
|
return json.children.length !== 1;
|
|
54
62
|
};
|
|
@@ -387,7 +395,9 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
387
395
|
((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
388
396
|
reactLibImports.add('useEffect');
|
|
389
397
|
}
|
|
390
|
-
var wrap = wrapInFragment(json) ||
|
|
398
|
+
var wrap = wrapInFragment(json) ||
|
|
399
|
+
(componentHasStyles && stylesType === 'styled-jsx') ||
|
|
400
|
+
isRootShowNode(json);
|
|
391
401
|
var nativeStyles = stylesType === 'react-native' &&
|
|
392
402
|
componentHasStyles &&
|
|
393
403
|
(0, react_native_1.collectReactNativeStyles)(json);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { MitosisComponent } from '../types/mitosis-component';
|
|
2
|
-
export declare const renderPreComponent: (component: MitosisComponent, target?: "
|
|
2
|
+
export declare const renderPreComponent: (component: MitosisComponent, target?: "html" | "template" | "angular" | "builder" | "customElement" | "mitosis" | "liquid" | "react" | "reactNative" | "solid" | "svelte" | "swift" | "webcomponent" | "vue" | undefined) => string;
|
|
@@ -3,9 +3,30 @@ export declare type MitosisNode = {
|
|
|
3
3
|
'@type': '@builder.io/mitosis/node';
|
|
4
4
|
name: string;
|
|
5
5
|
meta: JSONObject;
|
|
6
|
+
/**
|
|
7
|
+
* Key-value store of static values for DOM attributes.
|
|
8
|
+
* ```js
|
|
9
|
+
* {
|
|
10
|
+
* disabled: false,
|
|
11
|
+
* defaultValue: 'initial text`,
|
|
12
|
+
* width: 100,
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
6
16
|
properties: {
|
|
7
17
|
[key: string]: string | undefined;
|
|
8
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Key-value store of _dynamic_ values for DOM attributes.
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* {
|
|
24
|
+
* disabled: state.isDisabled,
|
|
25
|
+
* defaultValue: `${props.text} + ' initial'`,
|
|
26
|
+
* width: props.width * 10,
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
9
30
|
bindings: {
|
|
10
31
|
[key: string]: string | undefined;
|
|
11
32
|
};
|