@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.
@@ -0,0 +1,3 @@
1
+ export default function RenderStyles(props: {
2
+ foo: string;
3
+ }): JSX.Element;
@@ -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, "el.style.display = ".concat(json.bindings.when.replace(/;$/, ''), " ? 'inline' : 'none'"));
171
- str += "<span data-name=\"".concat(elId, "\">");
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 += '</span>';
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) || (componentHasStyles && stylesType === 'styled-jsx');
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?: "react" | "template" | "angular" | "builder" | "customElement" | "html" | "mitosis" | "liquid" | "reactNative" | "solid" | "svelte" | "swift" | "webcomponent" | "vue" | undefined) => string;
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
  };