@builder.io/mitosis 0.0.56-0 → 0.0.56-3

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;
@@ -1 +1,3 @@
1
- export default function ComponentWithContext(): JSX.Element;
1
+ export default function ComponentWithContext(props: {
2
+ content: string;
3
+ }): JSX.Element;
@@ -6,9 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var _1_1 = __importDefault(require("@dummy/1"));
7
7
  var _2_1 = __importDefault(require("@dummy/2"));
8
8
  var mitosis_1 = require("@builder.io/mitosis");
9
- function ComponentWithContext() {
9
+ function ComponentWithContext(props) {
10
10
  var foo = (0, mitosis_1.useContext)(_1_1.default);
11
- (0, mitosis_1.setContext)(_1_1.default, { foo: 'bar' });
11
+ (0, mitosis_1.setContext)(_1_1.default, {
12
+ foo: 'bar',
13
+ content: function () {
14
+ return props.content;
15
+ },
16
+ });
12
17
  return (<_2_1.default.Provider value={{ bar: 'baz' }}>
13
18
  <>{foo.value}</>
14
19
  </_2_1.default.Provider>);
@@ -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
  });
@@ -1,36 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var svelte_1 = require("../generators/svelte");
3
+ var svelte_1 = require("../generators/context/svelte");
4
+ var context_1 = require("../parsers/context");
5
+ var svelte_2 = require("../generators/svelte");
4
6
  var jsx_1 = require("../parsers/jsx");
5
7
  var onUpdate = require('./data/blocks/onUpdate.raw');
6
8
  var multipleOUpdate = require('./data/blocks/multiple-onUpdate.raw');
7
9
  var selfReferencingComponent = require('./data/blocks/self-referencing-component.raw');
8
10
  var selfReferencingComponentWithChildren = require('./data/blocks/self-referencing-component-with-children.raw');
9
11
  var builderRenderBlock = require('./data/blocks/builder-render-block.raw');
12
+ var rootShow = require('./data/blocks/rootShow.raw');
13
+ var simpleExample = require('./data/context/simple.context.lite');
14
+ var componentWithContext = require('./data/context/component-with-context.lite');
15
+ var renderBlock = require('./data/blocks/builder-render-block.raw');
10
16
  describe('Svelte', function () {
11
17
  test('onUpdate', function () {
12
18
  var component = (0, jsx_1.parseJsx)(onUpdate);
13
- var output = (0, svelte_1.componentToSvelte)()({ component: component });
19
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
14
20
  expect(output).toMatchSnapshot();
15
21
  });
16
22
  test('multipleOnUpdate', function () {
17
23
  var component = (0, jsx_1.parseJsx)(multipleOUpdate);
18
- var output = (0, svelte_1.componentToSvelte)()({ component: component });
24
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
19
25
  expect(output).toMatchSnapshot();
20
26
  });
21
27
  test('selfReferencingComponent', function () {
22
28
  var component = (0, jsx_1.parseJsx)(selfReferencingComponent);
23
- var output = (0, svelte_1.componentToSvelte)()({ component: component });
29
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
24
30
  expect(output).toMatchSnapshot();
25
31
  });
26
32
  test('selfReferencingComponentWithChildren', function () {
27
33
  var component = (0, jsx_1.parseJsx)(selfReferencingComponentWithChildren);
28
- var output = (0, svelte_1.componentToSvelte)()({ component: component });
34
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
29
35
  expect(output).toMatchSnapshot();
30
36
  });
31
37
  test('BuilderRenderBlock', function () {
32
38
  var component = (0, jsx_1.parseJsx)(builderRenderBlock);
33
- var output = (0, svelte_1.componentToSvelte)()({ component: component });
39
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
34
40
  expect(output).toMatchSnapshot();
35
41
  });
42
+ test('rootShow', function () {
43
+ var component = (0, jsx_1.parseJsx)(rootShow);
44
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
45
+ expect(output).toMatchSnapshot();
46
+ });
47
+ describe('Context', function () {
48
+ test('Parse context', function () {
49
+ var component = (0, context_1.parseContext)(simpleExample, { name: 'SimpleExample' });
50
+ if (!component) {
51
+ throw new Error('No parseable context found for simple.context.lite.ts');
52
+ }
53
+ expect(component).toMatchSnapshot();
54
+ var context = (0, svelte_1.contextToSvelte)()({ context: component });
55
+ expect(context).toMatchSnapshot();
56
+ });
57
+ test('Use and set context in components', function () {
58
+ var component = (0, jsx_1.parseJsx)(componentWithContext);
59
+ expect(component).toMatchSnapshot();
60
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
61
+ expect(output).toMatchSnapshot();
62
+ });
63
+ test('Use and set context in complex components', function () {
64
+ var component = (0, jsx_1.parseJsx)(renderBlock);
65
+ expect(component).toMatchSnapshot();
66
+ var output = (0, svelte_2.componentToSvelte)()({ component: component });
67
+ expect(output).toMatchSnapshot();
68
+ });
69
+ });
36
70
  });
@@ -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);
@@ -69,7 +69,13 @@ var mappers = {
69
69
  includeState: options.stateType === 'variables',
70
70
  }), " }\n").concat(json.children
71
71
  .map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
72
- .join('\n'), "\n{/if}");
72
+ .join('\n'), "\n\n ").concat(json.meta.else
73
+ ? "\n {:else}\n ".concat((0, exports.blockToSvelte)({
74
+ json: json.meta.else,
75
+ options: options,
76
+ parentComponent: parentComponent,
77
+ }), "\n ")
78
+ : '', "\n{/if}");
73
79
  },
74
80
  };
75
81
  var getContextCode = function (json) {
@@ -83,7 +89,9 @@ var setContextCode = function (json) {
83
89
  return Object.keys(contextSetters)
84
90
  .map(function (key) {
85
91
  var _a = contextSetters[key], value = _a.value, name = _a.name;
86
- return "setContext(".concat(name, ".key, ").concat(value ? (0, get_state_object_string_1.getMemberObjectString)(value) : 'undefined', ");");
92
+ return "setContext(".concat(name, ".key, ").concat(value
93
+ ? (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, get_state_object_string_1.getMemberObjectString)(value))
94
+ : 'undefined', ");");
87
95
  })
88
96
  .join('\n');
89
97
  };
@@ -196,9 +196,9 @@ var blockToVue = function (node, options) {
196
196
  }
197
197
  if (node.name === 'style') {
198
198
  // Vue doesn't allow <style>...</style> in templates, but does support the synonymous
199
- // <component is="style">...</component>
199
+ // <component is="'style'">...</component>
200
200
  node.name = 'component';
201
- node.bindings.is = 'style';
201
+ node.bindings.is = "'style'";
202
202
  }
203
203
  if (node.properties._text) {
204
204
  return "".concat(node.properties._text);
@@ -1,9 +1,15 @@
1
1
  import { MitosisComponent } from '..';
2
2
  import { Plugin } from './plugins';
3
+ export declare type Format = 'esm' | 'cjs';
4
+ export interface TranspilerOptions {
5
+ format?: Format;
6
+ }
3
7
  declare type Targets = typeof import('../targets').targets;
4
8
  export declare type Target = keyof Targets;
5
9
  export declare type GeneratorOptions = {
6
- [K in keyof Targets]: NonNullable<Parameters<Targets[K]>[0]>;
10
+ [K in keyof Targets]: NonNullable<Parameters<Targets[K]>[0]> & {
11
+ transpiler?: TranspilerOptions;
12
+ };
7
13
  };
8
14
  export interface TranspilerArgs {
9
15
  path?: 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
  };