@builder.io/mitosis 0.0.54 → 0.0.56-1
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/generators/solid.js +6 -4
- 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);
|
|
@@ -114,9 +114,11 @@ var blockToSolid = function (json, options) {
|
|
|
114
114
|
}
|
|
115
115
|
if (json.name === 'For') {
|
|
116
116
|
var needsWrapper = json.children.length !== 1;
|
|
117
|
-
|
|
117
|
+
// The SolidJS `<For>` component has a special index() signal function.
|
|
118
|
+
// https://www.solidjs.com/docs/latest#%3Cfor%3E
|
|
119
|
+
return "<For each={".concat(json.bindings.each, "}>\n {(").concat(json.properties._forName, ", _index) => {\n const index = _index();\n return ").concat(needsWrapper ? '<>' : '').concat(json.children
|
|
118
120
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
119
|
-
.map(function (child) { return blockToSolid(child, options); }), "}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
|
|
121
|
+
.map(function (child) { return blockToSolid(child, options); }), "}}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
|
|
120
122
|
}
|
|
121
123
|
var str = '';
|
|
122
124
|
if (json.name === 'Fragment') {
|
|
@@ -236,7 +238,7 @@ var componentToSolid = function (options) {
|
|
|
236
238
|
var componentHasContext = (0, context_1.hasContext)(json);
|
|
237
239
|
var hasShowComponent = componentsUsed.has('Show');
|
|
238
240
|
var hasForComponent = componentsUsed.has('For');
|
|
239
|
-
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n
|
|
241
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(props) {\n ", "\n \n ", "\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(props) {\n ", "\n \n ", "\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), !(hasShowComponent || hasForComponent)
|
|
240
242
|
? ''
|
|
241
243
|
: "import { \n ".concat(!componentHasContext ? '' : 'useContext, ', "\n ").concat(!hasShowComponent ? '' : 'Show, ', "\n ").concat(!hasForComponent ? '' : 'For, ', "\n ").concat(!((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ? '' : 'onMount, ', "\n } from 'solid-js';"), !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", !hasState ? '' : "import { createMutable } from 'solid-js/store';", !componentHasStyles
|
|
242
244
|
? ''
|
|
@@ -245,7 +247,7 @@ var componentToSolid = function (options) {
|
|
|
245
247
|
: "onMount(() => { ".concat(json.hooks.onMount.code, " })"), addWrapper ? '<>' : '', json.children
|
|
246
248
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
247
249
|
.map(function (item) { return blockToSolid(item, options); })
|
|
248
|
-
.join('\n'), addWrapper ? '</>' : '');
|
|
250
|
+
.join('\n'), addWrapper ? '</>' : '', json.name);
|
|
249
251
|
// HACK: for some reason we are generating `state.state.foo` instead of `state.foo`
|
|
250
252
|
// need a full fix, but this unblocks a lot in the short term
|
|
251
253
|
str = str.replace(/state\.state\./g, 'state.');
|
|
@@ -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
|
};
|