@builder.io/mitosis 0.0.44-21 → 0.0.45-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.
Files changed (42) hide show
  1. package/dist/src/__tests__/builder.test.js +55 -0
  2. package/dist/src/__tests__/context.test.js +7 -0
  3. package/dist/src/__tests__/data/blocks/columns.raw.jsx +0 -2
  4. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +1 -1
  5. package/dist/src/__tests__/react-native.test.d.ts +1 -0
  6. package/dist/src/__tests__/react-native.test.js +110 -0
  7. package/dist/src/flow.d.ts +3 -3
  8. package/dist/src/generators/builder.d.ts +1 -0
  9. package/dist/src/generators/builder.js +4 -2
  10. package/dist/src/generators/context/vue.d.ts +6 -0
  11. package/dist/src/generators/context/vue.js +9 -0
  12. package/dist/src/generators/qwik.js +23 -10
  13. package/dist/src/generators/react-native.d.ts +1 -1
  14. package/dist/src/generators/react-native.js +17 -0
  15. package/dist/src/generators/react.js +30 -19
  16. package/dist/src/generators/template.js +1 -1
  17. package/dist/src/generators/vue.d.ts +4 -0
  18. package/dist/src/generators/vue.js +139 -28
  19. package/dist/src/helpers/babel-transform.js +31 -18
  20. package/dist/src/helpers/collect-styles.js +1 -1
  21. package/dist/src/helpers/get-state-used.d.ts +5 -0
  22. package/dist/src/helpers/get-state-used.js +29 -0
  23. package/dist/src/helpers/handle-missing-state.d.ts +2 -0
  24. package/dist/src/helpers/handle-missing-state.js +13 -0
  25. package/dist/src/helpers/parse-node.js +2 -2
  26. package/dist/src/helpers/process-http-requests.d.ts +2 -0
  27. package/dist/src/helpers/process-http-requests.js +22 -0
  28. package/dist/src/index.d.ts +1 -0
  29. package/dist/src/index.js +1 -0
  30. package/dist/src/jsx-types.d.ts +1 -0
  31. package/dist/src/parsers/builder.js +16 -12
  32. package/dist/src/parsers/context.js +2 -0
  33. package/dist/src/parsers/jsx.js +51 -7
  34. package/dist/src/plugins/compile-away-builder-components.js +2 -2
  35. package/dist/test/qwik/Todo/bundle.js +8 -8
  36. package/dist/test/qwik/Todo_onButtonClick.ts +1 -4
  37. package/dist/test/qwik/Todo_onInput2Blur.ts +1 -1
  38. package/dist/test/qwik/Todo_onLabelDblClick.ts +1 -4
  39. package/dist/test/qwik/Todo_template.tsx +2 -2
  40. package/dist/test/qwik/Todos_template.tsx +3 -3
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +1 -2
@@ -22,6 +22,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
25
61
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
62
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
63
  };
@@ -30,8 +66,10 @@ var dedent_1 = __importDefault(require("dedent"));
30
66
  var fs = __importStar(require("fs"));
31
67
  var builder_1 = require("../generators/builder");
32
68
  var mitosis_1 = require("../generators/mitosis");
69
+ var html_1 = require("../generators/html");
33
70
  var builder_2 = require("../parsers/builder");
34
71
  var jsx_1 = require("../parsers/jsx");
72
+ var compile_away_builder_components_1 = require("../plugins/compile-away-builder-components");
35
73
  /**
36
74
  * Load a file using nodejs resolution as a string.
37
75
  */
@@ -44,6 +82,7 @@ var customCode = fixture('./data/blocks/custom-code.raw');
44
82
  var embed = fixture('./data/blocks/embed.raw');
45
83
  var image = fixture('./data/blocks/image.raw');
46
84
  var columns = fixture('./data/blocks/columns.raw');
85
+ var lazyLoadSection = JSON.parse(fixture('./data/builder/lazy-load-section.json'));
47
86
  describe('Builder', function () {
48
87
  test('extractStateHook', function () {
49
88
  var code = "useState({ foo: 'bar' }); alert('hi');";
@@ -96,6 +135,22 @@ describe('Builder', function () {
96
135
  var mitosis = mitosis_1.componentToMitosis(backToMitosis);
97
136
  expect(mitosis).toMatchSnapshot();
98
137
  });
138
+ test('Section', function () { return __awaiter(void 0, void 0, void 0, function () {
139
+ var mitosisComponent, html;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0:
143
+ mitosisComponent = builder_2.builderContentToMitosisComponent(lazyLoadSection);
144
+ return [4 /*yield*/, html_1.componentToHtml(mitosisComponent, {
145
+ plugins: [compile_away_builder_components_1.compileAwayBuilderComponents()],
146
+ })];
147
+ case 1:
148
+ html = _a.sent();
149
+ expect(html).toMatchSnapshot();
150
+ return [2 /*return*/];
151
+ }
152
+ });
153
+ }); });
99
154
  test('Regenerate Image', function () {
100
155
  var code = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { useState } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"hi\"\n css={{\n display: \"block\",\n }}\n />\n </div>\n );\n }\n "], ["\n import { useState } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"hi\"\n css={{\n display: \"block\",\n }}\n />\n </div>\n );\n }\n "])));
101
156
  var json = jsx_1.parseJsx(code);
@@ -6,6 +6,7 @@ var context_1 = require("../parsers/context");
6
6
  var react_2 = require("../generators/react");
7
7
  var simpleExample = require('./data/context/simple.context.lite');
8
8
  var componentWithContext = require('./data/context/component-with-context.lite');
9
+ var renderBlock = require('./data/blocks/builder-render-block.raw');
9
10
  describe('Context', function () {
10
11
  test('Parse context', function () {
11
12
  var json = context_1.parseContext(simpleExample, { name: 'SimpleExample' });
@@ -22,4 +23,10 @@ describe('Context', function () {
22
23
  var reactComponent = react_2.componentToReact(json);
23
24
  expect(reactComponent).toMatchSnapshot();
24
25
  });
26
+ test('Use and set context in complex components', function () {
27
+ var json = jsx_1.parseJsx(renderBlock);
28
+ expect(json).toMatchSnapshot();
29
+ var reactComponent = react_2.componentToReact(json);
30
+ expect(reactComponent).toMatchSnapshot();
31
+ });
25
32
  });
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var mitosis_1 = require("@builder.io/mitosis");
4
4
  function Column(props) {
5
5
  var state = mitosis_1.useState({
6
- // TODO: These methods are not used right now, but they will be when
7
- // support for dynamic CSS lands
8
6
  getColumns: function () {
9
7
  return props.columns || [];
10
8
  },
@@ -33,7 +33,7 @@ function SmileReviews(props) {
33
33
  </button>
34
34
  </mitosis_1.Show>
35
35
  <mitosis_1.For each={state.reviews}>
36
- {function (review) { return (<div $name="Review" css={{
36
+ {function (review) { return (<div $name="Review" key={review.id} css={{
37
37
  margin: '10px',
38
38
  padding: '10px',
39
39
  background: 'white',
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_native_1 = require("../generators/react-native");
4
+ var jsx_1 = require("../parsers/jsx");
5
+ var basic = require('./data/basic.raw');
6
+ var submitButtonBlock = require('./data/blocks/submit-button.raw');
7
+ var inputBlock = require('./data/blocks/input.raw');
8
+ var selectBlock = require('./data/blocks/select.raw');
9
+ var formBlock = require('./data/blocks/form.raw');
10
+ var button = require('./data/blocks/button.raw');
11
+ var textarea = require('./data/blocks/textarea.raw');
12
+ var img = require('./data/blocks/img.raw');
13
+ var video = require('./data/blocks/video.raw');
14
+ var section = require('./data/blocks/section.raw');
15
+ var text = require('./data/blocks/text.raw');
16
+ var rawText = require('./data/blocks/raw-text.raw');
17
+ var stamped = require('./data/blocks/stamped-io.raw');
18
+ var customCode = require('./data/blocks/custom-code.raw');
19
+ var embed = require('./data/blocks/embed.raw');
20
+ var image = require('./data/blocks/image.raw');
21
+ var columns = require('./data/blocks/columns.raw');
22
+ describe('React', function () {
23
+ test('Basic', function () {
24
+ var json = jsx_1.parseJsx(basic);
25
+ var output = react_native_1.componentToReactNative(json);
26
+ expect(output).toMatchSnapshot();
27
+ });
28
+ test('Input block', function () {
29
+ var json = jsx_1.parseJsx(inputBlock);
30
+ var output = react_native_1.componentToReactNative(json);
31
+ expect(output).toMatchSnapshot();
32
+ });
33
+ test('Submit button block', function () {
34
+ var json = jsx_1.parseJsx(submitButtonBlock);
35
+ var output = react_native_1.componentToReactNative(json);
36
+ expect(output).toMatchSnapshot();
37
+ });
38
+ test('Select block', function () {
39
+ var json = jsx_1.parseJsx(selectBlock);
40
+ var output = react_native_1.componentToReactNative(json);
41
+ expect(output).toMatchSnapshot();
42
+ });
43
+ test('Form block', function () {
44
+ var json = jsx_1.parseJsx(formBlock);
45
+ var output = react_native_1.componentToReactNative(json);
46
+ expect(output).toMatchSnapshot();
47
+ });
48
+ test('Button', function () {
49
+ var json = jsx_1.parseJsx(button);
50
+ var output = react_native_1.componentToReactNative(json);
51
+ expect(output).toMatchSnapshot();
52
+ });
53
+ test('Textarea', function () {
54
+ var json = jsx_1.parseJsx(textarea);
55
+ var output = react_native_1.componentToReactNative(json);
56
+ expect(output).toMatchSnapshot();
57
+ });
58
+ test('Img', function () {
59
+ var json = jsx_1.parseJsx(img);
60
+ var output = react_native_1.componentToReactNative(json);
61
+ expect(output).toMatchSnapshot();
62
+ });
63
+ test('Video', function () {
64
+ var json = jsx_1.parseJsx(video);
65
+ var output = react_native_1.componentToReactNative(json);
66
+ expect(output).toMatchSnapshot();
67
+ });
68
+ test('Section', function () {
69
+ var json = jsx_1.parseJsx(section);
70
+ var output = react_native_1.componentToReactNative(json);
71
+ expect(output).toMatchSnapshot();
72
+ });
73
+ test('Text', function () {
74
+ var json = jsx_1.parseJsx(text);
75
+ var output = react_native_1.componentToReactNative(json);
76
+ expect(output).toMatchSnapshot();
77
+ });
78
+ test('RawText', function () {
79
+ var json = jsx_1.parseJsx(rawText);
80
+ var output = react_native_1.componentToReactNative(json);
81
+ expect(output).toMatchSnapshot();
82
+ });
83
+ test('Stamped.io', function () {
84
+ var json = jsx_1.parseJsx(stamped);
85
+ var output = react_native_1.componentToReactNative(json, {
86
+ stateType: 'useState',
87
+ });
88
+ expect(output).toMatchSnapshot();
89
+ });
90
+ test('CustomCode', function () {
91
+ var json = jsx_1.parseJsx(customCode);
92
+ var output = react_native_1.componentToReactNative(json);
93
+ expect(output).toMatchSnapshot();
94
+ });
95
+ test('Embed', function () {
96
+ var json = jsx_1.parseJsx(customCode);
97
+ var output = react_native_1.componentToReactNative(json);
98
+ expect(output).toMatchSnapshot();
99
+ });
100
+ test('Image', function () {
101
+ var json = jsx_1.parseJsx(image);
102
+ var output = react_native_1.componentToReactNative(json);
103
+ expect(output).toMatchSnapshot();
104
+ });
105
+ test('Columns', function () {
106
+ var json = jsx_1.parseJsx(columns);
107
+ var output = react_native_1.componentToReactNative(json);
108
+ expect(output).toMatchSnapshot();
109
+ });
110
+ });
@@ -9,9 +9,9 @@
9
9
  export declare function For<T, U extends JSX.Element>(props: {
10
10
  each?: readonly T[];
11
11
  children: (item: T, index: number) => U;
12
- }): JSX.Element;
12
+ }): any;
13
13
  export declare function Show<T>(props: {
14
14
  when: T | undefined | null | false;
15
15
  else?: JSX.Element;
16
- children: JSX.Element;
17
- }): JSX.Element;
16
+ children?: JSX.Element | null;
17
+ }): any;
@@ -10,6 +10,7 @@ declare type InternalOptions = {
10
10
  export declare const blockToBuilder: (json: MitosisNode, options?: ToBuilderOptions, _internalOptions?: InternalOptions) => BuilderElement;
11
11
  export declare const componentToBuilder: (componentJson: MitosisComponent, options?: ToBuilderOptions) => {
12
12
  data: {
13
+ httpRequests: any;
13
14
  jsCode: string;
14
15
  tsCode: string;
15
16
  blocks: BuilderElement[];
@@ -236,10 +236,12 @@ var blockToBuilder = function (json, options, _internalOptions) {
236
236
  };
237
237
  exports.blockToBuilder = blockToBuilder;
238
238
  var componentToBuilder = function (componentJson, options) {
239
+ var _a, _b;
239
240
  if (options === void 0) { options = {}; }
240
241
  var hasState = Boolean(Object.keys(componentJson.state).length);
241
242
  var result = fast_clone_1.fastClone({
242
243
  data: {
244
+ httpRequests: (_b = (_a = componentJson === null || componentJson === void 0 ? void 0 : componentJson.meta) === null || _a === void 0 ? void 0 : _a.useMetadata) === null || _b === void 0 ? void 0 : _b.httpRequests,
243
245
  jsCode: tryFormat(dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n ", "\n\n ", "\n "], ["\n ", "\n\n ",
244
246
  "\n\n ", "\n "])), !has_props_1.hasProps(componentJson) ? '' : "var props = state;", !hasState
245
247
  ? ''
@@ -257,8 +259,8 @@ var componentToBuilder = function (componentJson, options) {
257
259
  },
258
260
  });
259
261
  var subComponentMap = {};
260
- for (var _i = 0, _a = componentJson.subComponents; _i < _a.length; _i++) {
261
- var subComponent = _a[_i];
262
+ for (var _i = 0, _c = componentJson.subComponents; _i < _c.length; _i++) {
263
+ var subComponent = _c[_i];
262
264
  var name_1 = subComponent.name;
263
265
  subComponentMap[name_1] = exports.componentToBuilder(subComponent, options);
264
266
  }
@@ -0,0 +1,6 @@
1
+ import { MitosisContext } from '../../types/mitosis-context';
2
+ declare type ContextToVueOptions = {
3
+ format?: boolean;
4
+ };
5
+ export declare function contextToVue(context: MitosisContext, options?: ContextToVueOptions): string;
6
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contextToVue = void 0;
4
+ function contextToVue(context, options) {
5
+ if (options === void 0) { options = {}; }
6
+ var str = "\n // Noop file\n export default {};\n ";
7
+ return str;
8
+ }
9
+ exports.contextToVue = contextToVue;
@@ -153,7 +153,7 @@ var NODE_MAPPERS = {
153
153
  .join('\n') + "</>";
154
154
  },
155
155
  For: function (json, options) {
156
- return "{" + processBinding(json.bindings.each, options) + ".map(" + json.properties._forName + " => (\n <>" + json.children
156
+ return "{" + processBinding(json.bindings.each, options) + "?.map(" + json.properties._forName + " => (\n <>" + json.children
157
157
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
158
158
  .map(function (item) { return blockToQwik(item, options); })
159
159
  .join('\n') + "</>\n ))}";
@@ -167,10 +167,10 @@ var NODE_MAPPERS = {
167
167
  };
168
168
  var getId = function (json, options) {
169
169
  var name = json.properties.$name
170
- ? lodash_1.camelCase(json.properties.$name)
170
+ ? camelCase(json.properties.$name)
171
171
  : /^h\d$/.test(json.name || '') // don't dashcase h1 into h-1
172
172
  ? json.name
173
- : lodash_1.camelCase(json.name || 'div');
173
+ : camelCase(json.name || 'div');
174
174
  var newNameNum = (options.namesMap[name] || 0) + 1;
175
175
  options.namesMap[name] = newNameNum;
176
176
  return capitalize_1.capitalize("" + name + (newNameNum === 1 ? '' : "" + newNameNum));
@@ -248,7 +248,7 @@ var blockToQwik = function (json, options) {
248
248
  return str;
249
249
  };
250
250
  var getComponentName = function (json, options) {
251
- return capitalize_1.capitalize(lodash_1.camelCase(json.name || 'my-component'));
251
+ return capitalize_1.capitalize(camelCase(json.name || 'my-component'));
252
252
  };
253
253
  // TODO
254
254
  var getProvidersString = function (componentJson, options) {
@@ -320,9 +320,9 @@ var componentToQwik = function (componentJson, toQwikOptions) {
320
320
  if (options.plugins) {
321
321
  json = plugins_1.runPostJsonPlugins(json, options.plugins);
322
322
  }
323
- componentName = capitalize_1.capitalize(lodash_1.camelCase(componentJson.name || 'my-component'));
323
+ componentName = capitalize_1.capitalize(camelCase(componentJson.name || 'my-component'));
324
324
  strip_meta_properties_1.stripMetaProperties(json);
325
- str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { injectMethod, QRL, jsxFactory } from '", "';\n import { ", "Component } from './", "_component.js'\n ", "\n\n export ", " injectMethod(", "Component, function (this: ", "Component) {\n return (", "\n ", "\n ", "\n ", ")\n })\n "], ["\n import { injectMethod, QRL, jsxFactory } from '", "';\n import { ", "Component } from './", "_component.js'\n ",
325
+ str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { injectMethod, QRL, h } from '", "';\n import { ", "Component } from './", "_component.js'\n ", "\n\n export ", " injectMethod(", "Component, function (this: ", "Component) {\n return (", "\n ", "\n ", "\n ", ")\n })\n "], ["\n import { injectMethod, QRL, h } from '", "';\n import { ", "Component } from './", "_component.js'\n ",
326
326
  "\n\n export ",
327
327
  " injectMethod(", "Component, function (this: ", "Component) {\n return (", "\n ",
328
328
  "\n ", "\n ", ")\n })\n "])), qwikImport(options), componentName, componentName, render_imports_1.renderPreComponent(__assign(__assign({}, json), { imports: json.imports.map(function (item) {
@@ -333,7 +333,7 @@ var componentToQwik = function (componentJson, toQwikOptions) {
333
333
  // Get the -1 index of array
334
334
  .slice(-2, -1)
335
335
  .pop();
336
- var pascalName = capitalize_1.capitalize(lodash_1.camelCase(name_1));
336
+ var pascalName = capitalize_1.capitalize(camelCase(name_1));
337
337
  clone.path = "../" + pascalName + "/public.js";
338
338
  for (var key in clone.imports) {
339
339
  var value = clone.imports[key];
@@ -400,14 +400,14 @@ var componentToQwik = function (componentJson, toQwikOptions) {
400
400
  jsx: 'react',
401
401
  isTSX: true,
402
402
  allExtensions: true,
403
- jsxFactory: 'jsxFactory',
404
- jsxPragma: 'jsxFactory',
403
+ jsxFactory: 'h',
404
+ jsxPragma: 'h',
405
405
  },
406
406
  ],
407
407
  [
408
408
  require('@babel/plugin-transform-react-jsx'),
409
409
  {
410
- pragma: 'jsxFactory',
410
+ pragma: 'h',
411
411
  pragmaFrag: 'null',
412
412
  throwIfNamespace: false,
413
413
  },
@@ -442,4 +442,17 @@ var componentToQwik = function (componentJson, toQwikOptions) {
442
442
  });
443
443
  };
444
444
  exports.componentToQwik = componentToQwik;
445
+ /**
446
+ * This is a function similar to loadash `camelCase`, but it does not mess with capitalization.
447
+ *
448
+ * loadash: `camelCase('A-BC')` => "ABc"
449
+ * this fn: `camelCase('A-BC')` => "ABC"
450
+ *
451
+ */
452
+ function camelCase(text) {
453
+ if (text === void 0) { text = ''; }
454
+ var parts = text.split('-');
455
+ var first = parts.shift();
456
+ return first + parts.map(capitalize_1.capitalize).join('');
457
+ }
445
458
  var templateObject_1;
@@ -8,5 +8,5 @@ declare type ToReactNativeOptions = {
8
8
  plugins?: Plugin[];
9
9
  };
10
10
  export declare const collectReactNativeStyles: (json: MitosisComponent) => ClassStyleMap;
11
- export declare const componentToReactNative: (componentJson: MitosisComponent, options: ToReactNativeOptions) => string;
11
+ export declare const componentToReactNative: (componentJson: MitosisComponent, options?: ToReactNativeOptions) => string;
12
12
  export {};
@@ -21,6 +21,7 @@ var fast_clone_1 = require("../helpers/fast-clone");
21
21
  var traverse_1 = __importDefault(require("traverse"));
22
22
  var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
23
23
  var react_1 = require("./react");
24
+ var stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
24
25
  var collectReactNativeStyles = function (json) {
25
26
  var styleMap = {};
26
27
  var componentIndexes = {};
@@ -32,6 +33,21 @@ var collectReactNativeStyles = function (json) {
32
33
  if (!lodash_1.size(value)) {
33
34
  return;
34
35
  }
36
+ // Style properties like `"20px"` need to be numbers like `20` for react native
37
+ for (var key in value) {
38
+ var propertyValue = value[key];
39
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\d/)) {
40
+ var newValue = parseFloat(propertyValue);
41
+ if (!isNaN(newValue)) {
42
+ value[key] = newValue;
43
+ }
44
+ }
45
+ if (stylePropertiesThatMustBeNumber.has(key) &&
46
+ typeof value[key] !== 'number') {
47
+ console.warn("Style key " + key + " must be a number, but had value `" + value[key] + "`");
48
+ delete value[key];
49
+ }
50
+ }
35
51
  var componentName = lodash_1.camelCase(item.name || 'view');
36
52
  var index = (componentIndexes[componentName] =
37
53
  (componentIndexes[componentName] || 0) + 1);
@@ -45,6 +61,7 @@ var collectReactNativeStyles = function (json) {
45
61
  };
46
62
  exports.collectReactNativeStyles = collectReactNativeStyles;
47
63
  var componentToReactNative = function (componentJson, options) {
64
+ if (options === void 0) { options = {}; }
48
65
  var json = fast_clone_1.fastClone(componentJson);
49
66
  traverse_1.default(json).forEach(function (node) {
50
67
  var _a, _b, _c;
@@ -23,21 +23,23 @@ var core_1 = require("@babel/core");
23
23
  var dedent_1 = __importDefault(require("dedent"));
24
24
  var json5_1 = __importDefault(require("json5"));
25
25
  var standalone_1 = require("prettier/standalone");
26
- var create_mitosis_node_1 = require("../helpers/create-mitosis-node");
27
26
  var traverse_1 = __importDefault(require("traverse"));
28
27
  var function_literal_prefix_1 = require("../constants/function-literal-prefix");
29
28
  var method_literal_prefix_1 = require("../constants/method-literal-prefix");
30
29
  var babel_transform_1 = require("../helpers/babel-transform");
31
30
  var capitalize_1 = require("../helpers/capitalize");
32
31
  var collect_styles_1 = require("../helpers/collect-styles");
32
+ var create_mitosis_node_1 = require("../helpers/create-mitosis-node");
33
33
  var fast_clone_1 = require("../helpers/fast-clone");
34
34
  var filter_empty_text_nodes_1 = require("../helpers/filter-empty-text-nodes");
35
35
  var get_refs_1 = require("../helpers/get-refs");
36
36
  var get_state_object_string_1 = require("../helpers/get-state-object-string");
37
37
  var getters_to_functions_1 = require("../helpers/getters-to-functions");
38
+ var handle_missing_state_1 = require("../helpers/handle-missing-state");
38
39
  var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
39
40
  var is_valid_attribute_name_1 = require("../helpers/is-valid-attribute-name");
40
41
  var map_refs_1 = require("../helpers/map-refs");
42
+ var process_http_requests_1 = require("../helpers/process-http-requests");
41
43
  var process_tag_references_1 = require("../helpers/process-tag-references");
42
44
  var render_imports_1 = require("../helpers/render-imports");
43
45
  var replace_new_lines_in_strings_1 = require("../helpers/replace-new-lines-in-strings");
@@ -58,17 +60,17 @@ var NODE_MAPPERS = {
58
60
  },
59
61
  For: function (json, options) {
60
62
  var wrap = wrapInFragment(json);
61
- return "{" + processBinding(json.bindings.each, options) + ".map(" + json.properties._forName + " => (\n " + (wrap ? '<>' : '') + json.children
63
+ return "{" + processBinding(json.bindings.each, options) + "?.map(" + json.properties._forName + " => (\n " + (wrap ? '<>' : '') + json.children
62
64
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
63
65
  .map(function (item) { return exports.blockToReact(item, options); })
64
66
  .join('\n') + (wrap ? '</>' : '') + "\n ))}";
65
67
  },
66
68
  Show: function (json, options) {
67
69
  var wrap = wrapInFragment(json);
68
- return "{" + (options.format === 'safe' ? 'Boolean' : '') + "(" + processBinding(json.bindings.when, options) + ") && (\n " + (wrap ? '<>' : '') + json.children
70
+ return "{" + processBinding(json.bindings.when, options) + " ? (\n " + (wrap ? '<>' : '') + json.children
69
71
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
70
72
  .map(function (item) { return exports.blockToReact(item, options); })
71
- .join('\n') + (wrap ? '</>' : '') + "\n )}";
73
+ .join('\n') + (wrap ? '</>' : '') + "\n ) : " + (!json.meta.else ? 'null' : exports.blockToReact(json.meta.else, options)) + "}";
72
74
  },
73
75
  };
74
76
  // TODO: Maybe in the future allow defining `string | function` as values
@@ -85,10 +87,18 @@ var blockToReact = function (json, options) {
85
87
  return NODE_MAPPERS[json.name](json, options);
86
88
  }
87
89
  if (json.properties._text) {
88
- return json.properties._text;
90
+ var text = json.properties._text;
91
+ if (options.type === 'native' && text.trim().length) {
92
+ return "<Text>" + text + "</Text>";
93
+ }
94
+ return text;
89
95
  }
90
96
  if (json.bindings._text) {
91
- return "{" + processBinding(json.bindings._text, options) + "}";
97
+ var processed = processBinding(json.bindings._text, options);
98
+ if (options.type === 'native') {
99
+ return "<Text>{" + processed + "}</Text>";
100
+ }
101
+ return "{" + processed + "}";
92
102
  }
93
103
  var str = '';
94
104
  str += "<" + json.name + " ";
@@ -276,7 +286,7 @@ var getInitCode = function (json, options) {
276
286
  var componentToReact = function (componentJson, reactOptions) {
277
287
  if (reactOptions === void 0) { reactOptions = {}; }
278
288
  var json = fast_clone_1.fastClone(componentJson);
279
- var options = __assign({ stateType: 'useState', stylesType: 'styled-components' }, reactOptions);
289
+ var options = __assign({ stateType: 'useState', stylesType: 'styled-jsx' }, reactOptions);
280
290
  if (options.plugins) {
281
291
  json = plugins_1.runPreJsonPlugins(json, options.plugins);
282
292
  }
@@ -314,6 +324,8 @@ var componentToReact = function (componentJson, reactOptions) {
314
324
  exports.componentToReact = componentToReact;
315
325
  var _componentToReact = function (json, options, isSubComponent) {
316
326
  if (isSubComponent === void 0) { isSubComponent = false; }
327
+ process_http_requests_1.processHttpRequests(json);
328
+ handle_missing_state_1.handleMissingState(json);
317
329
  process_tag_references_1.processTagReferences(json);
318
330
  addProviderComponents(json, options);
319
331
  var componentHasStyles = collect_styles_1.hasStyles(json);
@@ -358,21 +370,21 @@ var _componentToReact = function (json, options, isSubComponent) {
358
370
  var nativeStyles = stylesType === 'react-native' &&
359
371
  componentHasStyles &&
360
372
  react_native_1.collectReactNativeStyles(json);
361
- var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n "], ["\n ",
362
- "\n ",
373
+ var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "], ["\n ",
374
+ "\n ", "\n ",
363
375
  "\n ",
364
376
  "\n ",
365
377
  "\n ",
366
378
  "\n ",
367
- "\n ", "\n ", "\n\n\n ", "function ",
379
+ "\n ", "\n\n ", "function ",
368
380
  "(props) {\n ",
369
381
  "\n ", "\n ", "\n ", "\n\n ",
370
382
  "\n\n ",
371
- "\n\n return (\n ", "\n ",
372
- "\n ", "\n ", "\n );\n }\n\n ",
373
- "\n "])), options.type !== 'native'
383
+ "\n\n return (\n ", "\n ", "\n ",
384
+ "\n ", "\n );\n }\n\n ",
385
+ "\n\n ", "\n "])), options.type !== 'native'
374
386
  ? ''
375
- : "\n import * as React from 'react';\n import { View, StyleSheet, Image, Text } from 'react-native';\n ", reactLibImports.size
387
+ : "\n import * as React from 'react';\n import { View, StyleSheet, Image, Text } from 'react-native';\n ", styledComponentsCode ? "import styled from 'styled-components';\n" : '', reactLibImports.size
376
388
  ? "import { " + Array.from(reactLibImports).join(', ') + " } from 'react'"
377
389
  : '', componentHasStyles && stylesType === 'emotion' && options.format !== 'lite'
378
390
  ? "/** @jsx jsx */\n import { jsx } from '@emotion/react'".trim()
@@ -382,8 +394,7 @@ var _componentToReact = function (json, options, isSubComponent) {
382
394
  ? "import { useMutable } from 'react-solid-state';"
383
395
  : '', stateType === 'mobx' && hasState
384
396
  ? "import { useLocalObservable } from 'mobx-react-lite';"
385
- : '', render_imports_1.renderPreComponent(json), styledComponentsCode ? styledComponentsCode : '', isSubComponent ? '' : 'export default ', json.name ||
386
- 'MyComponent', hasState
397
+ : '', render_imports_1.renderPreComponent(json), isSubComponent ? '' : 'export default ', json.name || 'MyComponent', hasState
387
398
  ? stateType === 'mobx'
388
399
  ? "const state = useLocalObservable(() => (" + get_state_object_string_1.getStateObjectStringFromComponent(json) + "));"
389
400
  : stateType === 'useState'
@@ -397,11 +408,11 @@ var _componentToReact = function (json, options, isSubComponent) {
397
408
  ? "useEffect(() => {\n " + processBinding(updateStateSettersInCode(json.hooks.onMount, options), options) + "\n }, [])"
398
409
  : '', json.hooks.onUnMount
399
410
  ? "useEffect(() => {\n " + processBinding(updateStateSettersInCode(json.hooks.onUnMount, options), options) + "\n }, [])"
400
- : '', wrap ? '<>' : '', componentHasStyles && stylesType === 'styled-jsx'
411
+ : '', wrap ? '<>' : '', json.children.map(function (item) { return exports.blockToReact(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
401
412
  ? "<style jsx>{`" + css + "`}</style>"
402
- : '', json.children.map(function (item) { return exports.blockToReact(item, options); }).join('\n'), wrap ? '</>' : '', !nativeStyles
413
+ : '', wrap ? '</>' : '', !nativeStyles
403
414
  ? ''
404
- : "\n const styles = StyleSheet.create(" + json5_1.default.stringify(nativeStyles) + ");\n ");
415
+ : "\n const styles = StyleSheet.create(" + json5_1.default.stringify(nativeStyles) + ");\n ", styledComponentsCode ? styledComponentsCode : '');
405
416
  str = replace_new_lines_in_strings_1.stripNewlinesInStrings(str);
406
417
  return str;
407
418
  };
@@ -36,7 +36,7 @@ var blockToTemplate = function (json, options) {
36
36
  }
37
37
  var str = '';
38
38
  if (json.name === 'For') {
39
- str += "${" + json.bindings.each + ".map(" + json.properties._forName + " => `";
39
+ str += "${" + json.bindings.each + "?.map(" + json.properties._forName + " => `";
40
40
  if (json.children) {
41
41
  str += json.children
42
42
  .map(function (item) { return blockToTemplate(item, options); })
@@ -4,6 +4,10 @@ import { Plugin } from '../modules/plugins';
4
4
  export declare type ToVueOptions = {
5
5
  prettier?: boolean;
6
6
  plugins?: Plugin[];
7
+ vueVersion?: 2 | 3;
8
+ cssNamespace?: string;
9
+ namePrefix?: string;
10
+ builderRegister?: boolean;
7
11
  };
8
12
  export declare const blockToVue: (node: MitosisNode, options: ToVueOptions) => string;
9
13
  export declare const componentToVue: (component: MitosisComponent, options?: ToVueOptions) => string;