@builder.io/mitosis 0.0.45 → 0.0.46
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__/builder.test.js +71 -68
- package/dist/src/__tests__/context.test.js +13 -10
- package/dist/src/__tests__/data/basic.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/button-with-metadata.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/columns.raw.jsx +2 -2
- package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -3
- package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -3
- package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
- package/dist/src/__tests__/data/blocks/image.raw.jsx +4 -4
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -4
- package/dist/src/__tests__/data/context/component-with-context.lite.jsx +2 -2
- package/dist/src/__tests__/data/context/simple.context.lite.js +1 -1
- package/dist/src/__tests__/html.test.js +2 -2
- package/dist/src/__tests__/liquid.test.js +34 -34
- package/dist/src/__tests__/parse-jsx.test.js +1 -1
- package/dist/src/__tests__/qwik.test.js +36 -36
- package/dist/src/__tests__/react-native.test.js +35 -35
- package/dist/src/__tests__/react.test.js +35 -35
- package/dist/src/__tests__/solid.test.js +32 -32
- package/dist/src/__tests__/vue.test.js +35 -34
- package/dist/src/generators/angular.d.ts +4 -7
- package/dist/src/generators/angular.js +77 -81
- package/dist/src/generators/builder.d.ts +4 -4
- package/dist/src/generators/builder.js +57 -57
- package/dist/src/generators/context/react.d.ts +3 -1
- package/dist/src/generators/context/react.js +20 -17
- package/dist/src/generators/html.d.ts +5 -9
- package/dist/src/generators/html.js +205 -199
- package/dist/src/generators/liquid.d.ts +5 -9
- package/dist/src/generators/liquid.js +62 -59
- package/dist/src/generators/mitosis.d.ts +6 -7
- package/dist/src/generators/mitosis.js +61 -63
- package/dist/src/generators/qwik/component.js +13 -13
- package/dist/src/generators/qwik/handlers.js +12 -8
- package/dist/src/generators/qwik/jsx.js +13 -9
- package/dist/src/generators/qwik/styles.js +11 -7
- package/dist/src/generators/react-native.d.ts +4 -7
- package/dist/src/generators/react-native.js +25 -22
- package/dist/src/generators/react.d.ts +4 -8
- package/dist/src/generators/react.js +103 -112
- package/dist/src/generators/solid.d.ts +4 -8
- package/dist/src/generators/solid.js +55 -54
- package/dist/src/generators/svelte.d.ts +4 -7
- package/dist/src/generators/svelte.js +120 -123
- package/dist/src/generators/swift-ui.d.ts +2 -2
- package/dist/src/generators/swift-ui.js +62 -62
- package/dist/src/generators/template.d.ts +4 -8
- package/dist/src/generators/template.js +48 -45
- package/dist/src/generators/vue.d.ts +9 -9
- package/dist/src/generators/vue.js +169 -169
- package/dist/src/helpers/babel-transform.js +9 -9
- package/dist/src/helpers/collect-styles.js +39 -39
- package/dist/src/helpers/dash-case.js +1 -1
- package/dist/src/helpers/generic-format.test.js +2 -2
- package/dist/src/helpers/get-components-used.js +2 -2
- package/dist/src/helpers/get-components.js +3 -3
- package/dist/src/helpers/get-props.js +1 -1
- package/dist/src/helpers/get-refs.js +2 -2
- package/dist/src/helpers/get-state-object-string.js +5 -5
- package/dist/src/helpers/get-state-used.js +1 -1
- package/dist/src/helpers/get-styles.js +1 -1
- package/dist/src/helpers/getters-to-functions.js +4 -4
- package/dist/src/helpers/handle-missing-state.js +1 -1
- package/dist/src/helpers/has-component.js +2 -2
- package/dist/src/helpers/has-props.js +1 -1
- package/dist/src/helpers/is-children.js +1 -1
- package/dist/src/helpers/json.d.ts +1 -0
- package/dist/src/helpers/json.js +17 -0
- package/dist/src/helpers/map-refs.js +4 -4
- package/dist/src/helpers/map-to-attributes.js +4 -4
- package/dist/src/helpers/map-to-css.js +2 -2
- package/dist/src/helpers/parse-node.js +2 -2
- package/dist/src/helpers/parse-reactive-script.js +4 -4
- package/dist/src/helpers/process-http-requests.js +1 -1
- package/dist/src/helpers/process-tag-references.js +4 -4
- package/dist/src/helpers/remove-surrounding-block.test.js +1 -1
- package/dist/src/helpers/render-imports.js +7 -7
- package/dist/src/helpers/replace-idenifiers.js +1 -1
- package/dist/src/helpers/strip-meta-properties.js +2 -2
- package/dist/src/helpers/trace-reference-to-module-path.js +1 -1
- package/dist/src/helpers/traverse-nodes.js +2 -2
- package/dist/src/helpers/try-prettier-format.js +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/modules/plugins.d.ts +2 -10
- package/dist/src/parsers/angular.js +13 -13
- package/dist/src/parsers/builder.js +54 -58
- package/dist/src/parsers/context.js +2 -2
- package/dist/src/parsers/jsx.js +59 -87
- package/dist/src/parsers/liquid.js +191 -194
- package/dist/src/plugins/compile-away-builder-components.js +49 -45
- package/dist/src/plugins/compile-away-components.js +3 -3
- package/dist/src/plugins/map-styles.js +3 -3
- package/dist/src/targets.d.ts +24 -0
- package/dist/src/targets.js +30 -0
- package/dist/src/types/config.d.ts +31 -0
- package/dist/src/types/{jsx-lite-component.js → config.js} +0 -0
- package/dist/{test/qwik/Todo/Todo.js/low.js → src/types/generators.d.ts} +0 -0
- package/dist/src/types/generators.js +1 -0
- package/dist/src/types/plugins.d.ts +11 -0
- package/dist/src/types/{jsx-lite-context.js → plugins.js} +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.cjs/high.cjs +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.cjs/med.cjs +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.js/high.js +0 -0
- package/dist/test/qwik/{qwik/todo → todo}/Todo.js/low.js +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.js/med.js +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.tsx/high.tsx +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.tsx/med.tsx +0 -0
- package/dist/test/qwik/{Todos → todos}/Todo.tsx/high.tsx +0 -0
- package/dist/test/qwik/{Todos → todos}/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/{Todos → todos}/Todo.tsx/med.tsx +0 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +0 -11
- package/dist/src/__tests__/data/blocks/tabs.raw.jsx +0 -24
- package/dist/src/__tests__/qoot.test.d.ts +0 -1
- package/dist/src/__tests__/qoot.test.js +0 -115
- package/dist/src/generators/jsx-lite.d.ts +0 -10
- package/dist/src/generators/jsx-lite.js +0 -176
- package/dist/src/generators/qoot.d.ts +0 -21
- package/dist/src/generators/qoot.js +0 -442
- package/dist/src/generators/qwik.d.ts +0 -21
- package/dist/src/generators/qwik.js +0 -458
- package/dist/src/helpers/create-jsx-lite-component.d.ts +0 -2
- package/dist/src/helpers/create-jsx-lite-component.js +0 -16
- package/dist/src/helpers/create-jsx-lite-context.d.ts +0 -4
- package/dist/src/helpers/create-jsx-lite-context.js +0 -18
- package/dist/src/helpers/create-jsx-lite-node.d.ts +0 -2
- package/dist/src/helpers/create-jsx-lite-node.js +0 -16
- package/dist/src/helpers/is-jsx-lite-node.d.ts +0 -2
- package/dist/src/helpers/is-jsx-lite-node.js +0 -7
- package/dist/src/types/jsx-lite-component.d.ts +0 -63
- package/dist/src/types/jsx-lite-context.d.ts +0 -6
- package/dist/src/types/jsx-lite-node.d.ts +0 -13
- package/dist/src/types/jsx-lite-node.js +0 -2
- package/dist/src/types/jsx-lite-styles.d.ts +0 -1
- package/dist/src/types/jsx-lite-styles.js +0 -2
- package/dist/test/qoot/Todo/bundle.js +0 -88
- package/dist/test/qoot/Todo/component.ts +0 -17
- package/dist/test/qoot/Todo/onButtonClick.ts +0 -13
- package/dist/test/qoot/Todo/onInput2Blur.ts +0 -11
- package/dist/test/qoot/Todo/onInput2KeyUp.ts +0 -10
- package/dist/test/qoot/Todo/onInputClick.ts +0 -10
- package/dist/test/qoot/Todo/onLabelDblClick.ts +0 -11
- package/dist/test/qoot/Todo/public.ts +0 -4
- package/dist/test/qoot/Todo/template.tsx +0 -46
- package/dist/test/qoot/Todos/component.ts +0 -9
- package/dist/test/qoot/Todos/onInputClick.ts +0 -14
- package/dist/test/qoot/Todos/public.ts +0 -3
- package/dist/test/qoot/Todos/template.tsx +0 -30
- package/dist/test/qwik/Todo/bundle.js +0 -46
- package/dist/test/qwik/Todo/component.ts +0 -17
- package/dist/test/qwik/Todo/onButtonClick.ts +0 -10
- package/dist/test/qwik/Todo/onInput2Blur.ts +0 -14
- package/dist/test/qwik/Todo/onInput2KeyUp.ts +0 -10
- package/dist/test/qwik/Todo/onInputClick.ts +0 -13
- package/dist/test/qwik/Todo/onLabelDblClick.ts +0 -11
- package/dist/test/qwik/Todo/public.ts +0 -3
- package/dist/test/qwik/Todo/template.tsx +0 -46
- package/dist/test/qwik/Todo.ts +0 -4
- package/dist/test/qwik/Todo_component.ts +0 -17
- package/dist/test/qwik/Todo_onButtonClick.ts +0 -13
- package/dist/test/qwik/Todo_onInput2Blur.ts +0 -14
- package/dist/test/qwik/Todo_onInput2KeyUp.ts +0 -10
- package/dist/test/qwik/Todo_onInputClick.ts +0 -13
- package/dist/test/qwik/Todo_onLabelDblClick.ts +0 -14
- package/dist/test/qwik/Todo_template.tsx +0 -46
- package/dist/test/qwik/Todos/component.ts +0 -9
- package/dist/test/qwik/Todos/onInputClick.ts +0 -14
- package/dist/test/qwik/Todos/public.ts +0 -3
- package/dist/test/qwik/Todos/template.tsx +0 -30
- package/dist/test/qwik/Todos.ts +0 -3
- package/dist/test/qwik/Todos_component.ts +0 -9
- package/dist/test/qwik/Todos_onInputClick.ts +0 -14
- package/dist/test/qwik/Todos_template.tsx +0 -30
- package/dist/test/qwik/qwik/Image/high.js +0 -1
- package/dist/test/qwik/qwik/Image/low.js +0 -75
- package/dist/test/qwik/qwik/Image/med.js +0 -9
- package/dist/test/qwik/qwik/Image.slow/high.js +0 -1
- package/dist/test/qwik/qwik/Image.slow/low.js +0 -75
- package/dist/test/qwik/qwik/Image.slow/med.js +0 -9
- package/dist/test/qwik/qwik/button/high.js +0 -8
- package/dist/test/qwik/qwik/button/low.js +0 -34
- package/dist/test/qwik/qwik/button/med.js +0 -9
- package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +0 -1
- package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +0 -24
- package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +0 -9
- package/dist/test/qwik/qwik/page-with-symbol/high.js +0 -1
- package/dist/test/qwik/qwik/page-with-symbol/low.js +0 -49
- package/dist/test/qwik/qwik/page-with-symbol/med.js +0 -9
- package/dist/test/qwik/qwik/svg/high.js +0 -1
- package/dist/test/qwik/qwik/svg/low.js +0 -30
- package/dist/test/qwik/qwik/svg/med.js +0 -9
- package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +0 -31
- package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +0 -1
- package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +0 -59
- package/dist/test/qwik/qwik/todo/Todo.js/high.js +0 -5
- package/dist/test/qwik/qwik/todo/Todo.js/med.js +0 -1
- package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +0 -30
- package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +0 -1
- package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +0 -34
- package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +0 -12
- package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +0 -24
- package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +0 -8
|
@@ -25,12 +25,12 @@ var stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
|
|
|
25
25
|
var collectReactNativeStyles = function (json) {
|
|
26
26
|
var styleMap = {};
|
|
27
27
|
var componentIndexes = {};
|
|
28
|
-
traverse_1.default(json).forEach(function (item) {
|
|
29
|
-
if (is_mitosis_node_1.isMitosisNode(item)) {
|
|
28
|
+
(0, traverse_1.default)(json).forEach(function (item) {
|
|
29
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
30
30
|
if (typeof item.bindings.css === 'string') {
|
|
31
31
|
var value = json5_1.default.parse(item.bindings.css);
|
|
32
32
|
delete item.bindings.css;
|
|
33
|
-
if (!lodash_1.size(value)) {
|
|
33
|
+
if (!(0, lodash_1.size)(value)) {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
// Style properties like `"20px"` need to be numbers like `20` for react native
|
|
@@ -44,15 +44,15 @@ var collectReactNativeStyles = function (json) {
|
|
|
44
44
|
}
|
|
45
45
|
if (stylePropertiesThatMustBeNumber.has(key) &&
|
|
46
46
|
typeof value[key] !== 'number') {
|
|
47
|
-
console.warn("Style key "
|
|
47
|
+
console.warn("Style key ".concat(key, " must be a number, but had value `").concat(value[key], "`"));
|
|
48
48
|
delete value[key];
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
var componentName = lodash_1.camelCase(item.name || 'view');
|
|
51
|
+
var componentName = (0, lodash_1.camelCase)(item.name || 'view');
|
|
52
52
|
var index = (componentIndexes[componentName] =
|
|
53
53
|
(componentIndexes[componentName] || 0) + 1);
|
|
54
|
-
var className = ""
|
|
55
|
-
item.bindings.style = "styles."
|
|
54
|
+
var className = "".concat(componentName).concat(index);
|
|
55
|
+
item.bindings.style = "styles.".concat(className);
|
|
56
56
|
styleMap[className] = value;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -60,22 +60,25 @@ var collectReactNativeStyles = function (json) {
|
|
|
60
60
|
return styleMap;
|
|
61
61
|
};
|
|
62
62
|
exports.collectReactNativeStyles = collectReactNativeStyles;
|
|
63
|
-
var componentToReactNative = function (
|
|
63
|
+
var componentToReactNative = function (options) {
|
|
64
64
|
if (options === void 0) { options = {}; }
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
node.
|
|
65
|
+
return function (_a) {
|
|
66
|
+
var component = _a.component, path = _a.path;
|
|
67
|
+
var json = (0, fast_clone_1.fastClone)(component);
|
|
68
|
+
(0, traverse_1.default)(json).forEach(function (node) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
71
|
+
// TODO: handle TextInput, Image, etc
|
|
72
|
+
if (node.name.toLowerCase() === node.name) {
|
|
73
|
+
node.name = 'View';
|
|
74
|
+
}
|
|
75
|
+
if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) ||
|
|
76
|
+
((_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
77
|
+
node.name = 'Text';
|
|
78
|
+
}
|
|
76
79
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
});
|
|
81
|
+
return (0, react_1.componentToReact)(__assign(__assign({}, options), { stylesType: options.stylesType || 'react-native', type: 'native' }))({ component: json, path: path });
|
|
82
|
+
};
|
|
80
83
|
};
|
|
81
84
|
exports.componentToReactNative = componentToReactNative;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MitosisComponent } from '../types/mitosis-component';
|
|
1
|
+
import { BaseTranspilerOptions, Transpiler } from '../types/config';
|
|
3
2
|
import { MitosisNode } from '../types/mitosis-node';
|
|
4
|
-
|
|
5
|
-
prettier?: boolean;
|
|
3
|
+
export interface ToReactOptions extends BaseTranspilerOptions {
|
|
6
4
|
stylesType?: 'emotion' | 'styled-components' | 'styled-jsx' | 'react-native';
|
|
7
5
|
stateType?: 'useState' | 'mobx' | 'valtio' | 'solid' | 'builder';
|
|
8
6
|
format?: 'lite' | 'safe';
|
|
9
7
|
type?: 'dom' | 'native';
|
|
10
|
-
|
|
11
|
-
};
|
|
8
|
+
}
|
|
12
9
|
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions) => string;
|
|
13
|
-
export declare const componentToReact: (
|
|
14
|
-
export {};
|
|
10
|
+
export declare const componentToReact: (reactOptions?: ToReactOptions) => Transpiler;
|
|
@@ -54,23 +54,23 @@ var wrapInFragment = function (json) {
|
|
|
54
54
|
var NODE_MAPPERS = {
|
|
55
55
|
Fragment: function (json, options) {
|
|
56
56
|
var wrap = wrapInFragment(json);
|
|
57
|
-
return ""
|
|
58
|
-
.map(function (item) { return exports.blockToReact(item, options); })
|
|
59
|
-
.join('\n')
|
|
57
|
+
return "".concat(wrap ? '<>' : '').concat(json.children
|
|
58
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options); })
|
|
59
|
+
.join('\n')).concat(wrap ? '</>' : '');
|
|
60
60
|
},
|
|
61
61
|
For: function (json, options) {
|
|
62
62
|
var wrap = wrapInFragment(json);
|
|
63
|
-
return "{"
|
|
63
|
+
return "{".concat(processBinding(json.bindings.each, options), "?.map(").concat(json.properties._forName, " => (\n ").concat(wrap ? '<>' : '').concat(json.children
|
|
64
64
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
65
|
-
.map(function (item) { return exports.blockToReact(item, options); })
|
|
66
|
-
.join('\n')
|
|
65
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options); })
|
|
66
|
+
.join('\n')).concat(wrap ? '</>' : '', "\n ))}");
|
|
67
67
|
},
|
|
68
68
|
Show: function (json, options) {
|
|
69
69
|
var wrap = wrapInFragment(json);
|
|
70
|
-
return "{"
|
|
70
|
+
return "{".concat(processBinding(json.bindings.when, options), " ? (\n ").concat(wrap ? '<>' : '').concat(json.children
|
|
71
71
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
72
|
-
.map(function (item) { return exports.blockToReact(item, options); })
|
|
73
|
-
.join('\n')
|
|
72
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options); })
|
|
73
|
+
.join('\n')).concat(wrap ? '</>' : '', "\n ) : ").concat(!json.meta.else ? 'null' : (0, exports.blockToReact)(json.meta.else, options), "}");
|
|
74
74
|
},
|
|
75
75
|
};
|
|
76
76
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
@@ -89,42 +89,42 @@ var blockToReact = function (json, options) {
|
|
|
89
89
|
if (json.properties._text) {
|
|
90
90
|
var text = json.properties._text;
|
|
91
91
|
if (options.type === 'native' && text.trim().length) {
|
|
92
|
-
return "<Text>"
|
|
92
|
+
return "<Text>".concat(text, "</Text>");
|
|
93
93
|
}
|
|
94
94
|
return text;
|
|
95
95
|
}
|
|
96
96
|
if (json.bindings._text) {
|
|
97
97
|
var processed = processBinding(json.bindings._text, options);
|
|
98
98
|
if (options.type === 'native') {
|
|
99
|
-
return "<Text>{"
|
|
99
|
+
return "<Text>{".concat(processed, "}</Text>");
|
|
100
100
|
}
|
|
101
|
-
return "{"
|
|
101
|
+
return "{".concat(processed, "}");
|
|
102
102
|
}
|
|
103
103
|
var str = '';
|
|
104
|
-
str += "<"
|
|
104
|
+
str += "<".concat(json.name, " ");
|
|
105
105
|
if (json.bindings._spread) {
|
|
106
|
-
str += " {...("
|
|
106
|
+
str += " {...(".concat(processBinding(json.bindings._spread, options), ")} ");
|
|
107
107
|
}
|
|
108
108
|
for (var key in json.properties) {
|
|
109
109
|
var value = (json.properties[key] || '')
|
|
110
110
|
.replace(/"/g, '"')
|
|
111
111
|
.replace(/\n/g, '\\n');
|
|
112
112
|
if (key === 'class') {
|
|
113
|
-
str += " className=\""
|
|
113
|
+
str += " className=\"".concat(value, "\" ");
|
|
114
114
|
}
|
|
115
115
|
else if (BINDING_MAPPERS[key]) {
|
|
116
116
|
var mapper = BINDING_MAPPERS[key];
|
|
117
117
|
if (typeof mapper === 'function') {
|
|
118
118
|
var _a = mapper(key, value), newKey = _a[0], newValue = _a[1];
|
|
119
|
-
str += " "
|
|
119
|
+
str += " ".concat(newKey, "={").concat(newValue, "} ");
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
|
-
str += " "
|
|
122
|
+
str += " ".concat(BINDING_MAPPERS[key], "=\"").concat(value, "\" ");
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
else {
|
|
126
|
-
if (is_valid_attribute_name_1.isValidAttributeName(key)) {
|
|
127
|
-
str += " "
|
|
126
|
+
if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
|
|
127
|
+
str += " ".concat(key, "=\"").concat(value.replace(/"/g, '"'), "\" ");
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -138,24 +138,24 @@ var blockToReact = function (json, options) {
|
|
|
138
138
|
}
|
|
139
139
|
var useBindingValue = processBinding(value, options);
|
|
140
140
|
if (key.startsWith('on')) {
|
|
141
|
-
str += " "
|
|
141
|
+
str += " ".concat(key, "={event => ").concat(updateStateSettersInCode(useBindingValue, options), " } ");
|
|
142
142
|
}
|
|
143
143
|
else if (key === 'class') {
|
|
144
|
-
str += " className={"
|
|
144
|
+
str += " className={".concat(useBindingValue, "} ");
|
|
145
145
|
}
|
|
146
146
|
else if (BINDING_MAPPERS[key]) {
|
|
147
147
|
var mapper = BINDING_MAPPERS[key];
|
|
148
148
|
if (typeof mapper === 'function') {
|
|
149
149
|
var _b = mapper(key, useBindingValue), newKey = _b[0], newValue = _b[1];
|
|
150
|
-
str += " "
|
|
150
|
+
str += " ".concat(newKey, "={").concat(newValue, "} ");
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
|
-
str += " "
|
|
153
|
+
str += " ".concat(BINDING_MAPPERS[key], "={").concat(useBindingValue, "} ");
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
|
-
if (is_valid_attribute_name_1.isValidAttributeName(key)) {
|
|
158
|
-
str += " "
|
|
157
|
+
if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
|
|
158
|
+
str += " ".concat(key, "={").concat(useBindingValue, "} ");
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -169,17 +169,17 @@ var blockToReact = function (json, options) {
|
|
|
169
169
|
}
|
|
170
170
|
str += '>';
|
|
171
171
|
if (json.children) {
|
|
172
|
-
str += json.children.map(function (item) { return exports.blockToReact(item, options); }).join('\n');
|
|
172
|
+
str += json.children.map(function (item) { return (0, exports.blockToReact)(item, options); }).join('\n');
|
|
173
173
|
}
|
|
174
|
-
return str +
|
|
174
|
+
return str + "</".concat(json.name, ">");
|
|
175
175
|
};
|
|
176
176
|
exports.blockToReact = blockToReact;
|
|
177
177
|
var getRefsString = function (json, refs) {
|
|
178
|
-
if (refs === void 0) { refs = get_refs_1.getRefs(json); }
|
|
178
|
+
if (refs === void 0) { refs = (0, get_refs_1.getRefs)(json); }
|
|
179
179
|
var str = '';
|
|
180
180
|
for (var _i = 0, _a = Array.from(refs); _i < _a.length; _i++) {
|
|
181
181
|
var ref = _a[_i];
|
|
182
|
-
str += "\nconst "
|
|
182
|
+
str += "\nconst ".concat(ref, " = useRef();");
|
|
183
183
|
}
|
|
184
184
|
return str;
|
|
185
185
|
};
|
|
@@ -187,7 +187,7 @@ var processBinding = function (str, options) {
|
|
|
187
187
|
if (options.stateType !== 'useState') {
|
|
188
188
|
return str;
|
|
189
189
|
}
|
|
190
|
-
return strip_state_and_props_refs_1.stripStateAndPropsRefs(str, {
|
|
190
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(str, {
|
|
191
191
|
includeState: true,
|
|
192
192
|
includeProps: false,
|
|
193
193
|
});
|
|
@@ -205,19 +205,19 @@ var getUseStateCode = function (json, options) {
|
|
|
205
205
|
if (typeof value === 'string') {
|
|
206
206
|
if (value.startsWith(function_literal_prefix_1.functionLiteralPrefix)) {
|
|
207
207
|
var useValue = value.replace(function_literal_prefix_1.functionLiteralPrefix, '');
|
|
208
|
-
str += valueMapper(useValue)
|
|
208
|
+
str += "".concat(valueMapper(useValue), " ").concat(lineItemDelimiter);
|
|
209
209
|
}
|
|
210
210
|
else if (value.startsWith(method_literal_prefix_1.methodLiteralPrefix)) {
|
|
211
211
|
var methodValue = value.replace(method_literal_prefix_1.methodLiteralPrefix, '');
|
|
212
212
|
var useValue = methodValue.replace(/^(get )?/, 'function ');
|
|
213
|
-
str += valueMapper(useValue)
|
|
213
|
+
str += "".concat(valueMapper(useValue), " ").concat(lineItemDelimiter);
|
|
214
214
|
}
|
|
215
215
|
else {
|
|
216
|
-
str += "const ["
|
|
216
|
+
str += "const [".concat(key, ", set").concat((0, capitalize_1.capitalize)(key), "] ").concat(keyValueDelimiter, " useState(() => (").concat(valueMapper(json5_1.default.stringify(value)), "))").concat(lineItemDelimiter, " ");
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
else {
|
|
220
|
-
str += "const ["
|
|
220
|
+
str += "const [".concat(key, ", set").concat((0, capitalize_1.capitalize)(key), "] ").concat(keyValueDelimiter, " useState(() => (").concat(valueMapper(json5_1.default.stringify(value)), "))").concat(lineItemDelimiter, " ");
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
return str;
|
|
@@ -226,8 +226,8 @@ var updateStateSetters = function (json, options) {
|
|
|
226
226
|
if (options.stateType !== 'useState') {
|
|
227
227
|
return;
|
|
228
228
|
}
|
|
229
|
-
traverse_1.default(json).forEach(function (item) {
|
|
230
|
-
if (is_mitosis_node_1.isMitosisNode(item)) {
|
|
229
|
+
(0, traverse_1.default)(json).forEach(function (item) {
|
|
230
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
231
231
|
for (var key in item.bindings) {
|
|
232
232
|
var value = item.bindings[key];
|
|
233
233
|
var newValue = updateStateSettersInCode(value, options);
|
|
@@ -242,9 +242,9 @@ function addProviderComponents(json, options) {
|
|
|
242
242
|
for (var key in json.context.set) {
|
|
243
243
|
var _a = json.context.set[key], name_1 = _a.name, value = _a.value;
|
|
244
244
|
json.children = [
|
|
245
|
-
create_mitosis_node_1.createMitosisNode(__assign({ name: name_1
|
|
245
|
+
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: "".concat(name_1, ".Provider"), children: json.children }, (value && {
|
|
246
246
|
bindings: {
|
|
247
|
-
value: get_state_object_string_1.getMemberObjectString(value),
|
|
247
|
+
value: (0, get_state_object_string_1.getMemberObjectString)(value),
|
|
248
248
|
},
|
|
249
249
|
}))),
|
|
250
250
|
];
|
|
@@ -254,7 +254,7 @@ var updateStateSettersInCode = function (value, options) {
|
|
|
254
254
|
if (options.stateType !== 'useState') {
|
|
255
255
|
return value;
|
|
256
256
|
}
|
|
257
|
-
return babel_transform_1.babelTransformExpression(value, {
|
|
257
|
+
return (0, babel_transform_1.babelTransformExpression)(value, {
|
|
258
258
|
AssignmentExpression: function (path) {
|
|
259
259
|
var node = path.node;
|
|
260
260
|
if (core_1.types.isMemberExpression(node.left)) {
|
|
@@ -263,7 +263,7 @@ var updateStateSettersInCode = function (value, options) {
|
|
|
263
263
|
if (node.left.object.name === 'state') {
|
|
264
264
|
// TODO: ultimately support other property access like strings
|
|
265
265
|
var propertyName = node.left.property.name;
|
|
266
|
-
path.replaceWith(core_1.types.callExpression(core_1.types.identifier("set"
|
|
266
|
+
path.replaceWith(core_1.types.callExpression(core_1.types.identifier("set".concat((0, capitalize_1.capitalize)(propertyName))), [node.right]));
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
}
|
|
@@ -273,7 +273,7 @@ var updateStateSettersInCode = function (value, options) {
|
|
|
273
273
|
function getContextString(component, options) {
|
|
274
274
|
var str = '';
|
|
275
275
|
for (var key in component.context.get) {
|
|
276
|
-
str += "\n const "
|
|
276
|
+
str += "\n const ".concat(key, " = useContext(").concat(component.context.get[key].name, ");\n ");
|
|
277
277
|
}
|
|
278
278
|
return str;
|
|
279
279
|
}
|
|
@@ -284,59 +284,62 @@ function hasContext(component) {
|
|
|
284
284
|
var getInitCode = function (json, options) {
|
|
285
285
|
return processBinding(json.hooks.init || '', options);
|
|
286
286
|
};
|
|
287
|
-
var componentToReact = function (
|
|
287
|
+
var componentToReact = function (reactOptions) {
|
|
288
288
|
if (reactOptions === void 0) { reactOptions = {}; }
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
str +=
|
|
296
|
-
'\n\n\n' +
|
|
297
|
-
json.subComponents
|
|
298
|
-
.map(function (item) { return _componentToReact(item, options, true); })
|
|
299
|
-
.join('\n\n\n');
|
|
300
|
-
if (options.plugins) {
|
|
301
|
-
str = plugins_1.runPreCodePlugins(str, options.plugins);
|
|
302
|
-
}
|
|
303
|
-
if (options.prettier !== false) {
|
|
304
|
-
try {
|
|
305
|
-
str = standalone_1.format(str, {
|
|
306
|
-
parser: 'typescript',
|
|
307
|
-
plugins: [
|
|
308
|
-
require('prettier/parser-typescript'),
|
|
309
|
-
require('prettier/parser-postcss'),
|
|
310
|
-
],
|
|
311
|
-
})
|
|
312
|
-
// Remove spaces between imports
|
|
313
|
-
.replace(/;\n\nimport\s/g, ';\nimport ');
|
|
289
|
+
return function (_a) {
|
|
290
|
+
var component = _a.component;
|
|
291
|
+
var json = (0, fast_clone_1.fastClone)(component);
|
|
292
|
+
var options = __assign({ stateType: 'useState', stylesType: 'styled-jsx' }, reactOptions);
|
|
293
|
+
if (options.plugins) {
|
|
294
|
+
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
314
295
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
296
|
+
var str = _componentToReact(json, options);
|
|
297
|
+
str +=
|
|
298
|
+
'\n\n\n' +
|
|
299
|
+
json.subComponents
|
|
300
|
+
.map(function (item) { return _componentToReact(item, options, true); })
|
|
301
|
+
.join('\n\n\n');
|
|
302
|
+
if (options.plugins) {
|
|
303
|
+
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
318
304
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
305
|
+
if (options.prettier !== false) {
|
|
306
|
+
try {
|
|
307
|
+
str = (0, standalone_1.format)(str, {
|
|
308
|
+
parser: 'typescript',
|
|
309
|
+
plugins: [
|
|
310
|
+
require('prettier/parser-typescript'),
|
|
311
|
+
require('prettier/parser-postcss'),
|
|
312
|
+
],
|
|
313
|
+
})
|
|
314
|
+
// Remove spaces between imports
|
|
315
|
+
.replace(/;\n\nimport\s/g, ';\nimport ');
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
console.error('Format error for file:', str, JSON.stringify(json, null, 2));
|
|
319
|
+
throw err;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (options.plugins) {
|
|
323
|
+
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
324
|
+
}
|
|
325
|
+
return str;
|
|
326
|
+
};
|
|
324
327
|
};
|
|
325
328
|
exports.componentToReact = componentToReact;
|
|
326
329
|
var _componentToReact = function (json, options, isSubComponent) {
|
|
327
330
|
if (isSubComponent === void 0) { isSubComponent = false; }
|
|
328
|
-
process_http_requests_1.processHttpRequests(json);
|
|
329
|
-
handle_missing_state_1.handleMissingState(json);
|
|
330
|
-
process_tag_references_1.processTagReferences(json);
|
|
331
|
+
(0, process_http_requests_1.processHttpRequests)(json);
|
|
332
|
+
(0, handle_missing_state_1.handleMissingState)(json);
|
|
333
|
+
(0, process_tag_references_1.processTagReferences)(json);
|
|
331
334
|
addProviderComponents(json, options);
|
|
332
|
-
var componentHasStyles = collect_styles_1.hasStyles(json);
|
|
335
|
+
var componentHasStyles = (0, collect_styles_1.hasStyles)(json);
|
|
333
336
|
if (options.stateType === 'useState') {
|
|
334
|
-
getters_to_functions_1.gettersToFunctions(json);
|
|
337
|
+
(0, getters_to_functions_1.gettersToFunctions)(json);
|
|
335
338
|
updateStateSetters(json, options);
|
|
336
339
|
}
|
|
337
|
-
var refs = get_refs_1.getRefs(json);
|
|
340
|
+
var refs = (0, get_refs_1.getRefs)(json);
|
|
338
341
|
var hasState = Boolean(Object.keys(json.state).length);
|
|
339
|
-
map_refs_1.mapRefs(json, function (refName) { return refName
|
|
342
|
+
(0, map_refs_1.mapRefs)(json, function (refName) { return "".concat(refName, ".current"); });
|
|
340
343
|
var stylesType = options.stylesType || 'emotion';
|
|
341
344
|
var stateType = options.stateType || 'mobx';
|
|
342
345
|
if (stateType === 'builder') {
|
|
@@ -345,14 +348,14 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
345
348
|
}
|
|
346
349
|
var useStateCode = stateType === 'useState' && getUseStateCode(json, options);
|
|
347
350
|
if (options.plugins) {
|
|
348
|
-
json = plugins_1.runPostJsonPlugins(json, options.plugins);
|
|
351
|
+
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
349
352
|
}
|
|
350
|
-
var css = stylesType === 'styled-jsx' && collect_styles_1.collectCss(json, { classProperty: 'class' });
|
|
353
|
+
var css = stylesType === 'styled-jsx' && (0, collect_styles_1.collectCss)(json, { classProperty: 'class' });
|
|
351
354
|
var styledComponentsCode = stylesType === 'styled-components' &&
|
|
352
355
|
componentHasStyles &&
|
|
353
|
-
collect_styles_1.collectStyledComponents(json);
|
|
356
|
+
(0, collect_styles_1.collectStyledComponents)(json);
|
|
354
357
|
if (options.format !== 'lite') {
|
|
355
|
-
strip_meta_properties_1.stripMetaProperties(json);
|
|
358
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
356
359
|
}
|
|
357
360
|
var reactLibImports = new Set();
|
|
358
361
|
if (useStateCode && useStateCode.includes('useState')) {
|
|
@@ -370,23 +373,11 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
370
373
|
var wrap = wrapInFragment(json) || (componentHasStyles && stylesType === 'styled-jsx');
|
|
371
374
|
var nativeStyles = stylesType === 'react-native' &&
|
|
372
375
|
componentHasStyles &&
|
|
373
|
-
react_native_1.collectReactNativeStyles(json);
|
|
374
|
-
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 ",
|
|
375
|
-
"\n ", "\n ",
|
|
376
|
-
"\n ",
|
|
377
|
-
"\n ",
|
|
378
|
-
"\n ",
|
|
379
|
-
"\n ",
|
|
380
|
-
"\n ", "\n\n ", "function ",
|
|
381
|
-
"(props) {\n ",
|
|
382
|
-
"\n ", "\n ", "\n ", "\n\n ",
|
|
383
|
-
"\n\n ",
|
|
384
|
-
"\n\n return (\n ", "\n ", "\n ",
|
|
385
|
-
"\n ", "\n );\n }\n\n ",
|
|
386
|
-
"\n\n ", "\n "])), options.type !== 'native'
|
|
376
|
+
(0, react_native_1.collectReactNativeStyles)(json);
|
|
377
|
+
var str = (0, 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 ", "\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 "])), options.type !== 'native'
|
|
387
378
|
? ''
|
|
388
379
|
: "\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
|
|
389
|
-
? "import { "
|
|
380
|
+
? "import { ".concat(Array.from(reactLibImports).join(', '), " } from 'react'")
|
|
390
381
|
: '', componentHasStyles && stylesType === 'emotion' && options.format !== 'lite'
|
|
391
382
|
? "/** @jsx jsx */\n import { jsx } from '@emotion/react'".trim()
|
|
392
383
|
: '', hasState && stateType === 'valtio'
|
|
@@ -395,27 +386,27 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
395
386
|
? "import { useMutable } from 'react-solid-state';"
|
|
396
387
|
: '', stateType === 'mobx' && hasState
|
|
397
388
|
? "import { useLocalObservable } from 'mobx-react-lite';"
|
|
398
|
-
: '', render_imports_1.renderPreComponent(json), isSubComponent ? '' : 'export default ', json.name ||
|
|
389
|
+
: '', (0, render_imports_1.renderPreComponent)(json), isSubComponent ? '' : 'export default ', json.name ||
|
|
399
390
|
'MyComponent', hasState
|
|
400
391
|
? stateType === 'mobx'
|
|
401
|
-
? "const state = useLocalObservable(() => ("
|
|
392
|
+
? "const state = useLocalObservable(() => (".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), "));")
|
|
402
393
|
: stateType === 'useState'
|
|
403
394
|
? useStateCode
|
|
404
395
|
: stateType === 'solid'
|
|
405
|
-
? "const state = useMutable("
|
|
396
|
+
? "const state = useMutable(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
406
397
|
: stateType === 'builder'
|
|
407
|
-
? "var state = useBuilderState("
|
|
408
|
-
: "const state = useLocalProxy("
|
|
398
|
+
? "var state = useBuilderState(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
399
|
+
: "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
409
400
|
: '', getContextString(json, options), getRefsString(json), getInitCode(json, options), json.hooks.onMount
|
|
410
|
-
? "useEffect(() => {\n "
|
|
401
|
+
? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onMount, options), options), "\n }, [])")
|
|
411
402
|
: '', json.hooks.onUnMount
|
|
412
|
-
? "useEffect(() => {\n "
|
|
413
|
-
: '', wrap ? '<>' : '', json.children.map(function (item) { return exports.blockToReact(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
|
|
414
|
-
? "<style jsx>{`"
|
|
403
|
+
? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onUnMount, options), options), "\n }, [])")
|
|
404
|
+
: '', wrap ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToReact)(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
|
|
405
|
+
? "<style jsx>{`".concat(css, "`}</style>")
|
|
415
406
|
: '', wrap ? '</>' : '', !nativeStyles
|
|
416
407
|
? ''
|
|
417
|
-
: "\n const styles = StyleSheet.create("
|
|
418
|
-
str = replace_new_lines_in_strings_1.stripNewlinesInStrings(str);
|
|
408
|
+
: "\n const styles = StyleSheet.create(".concat(json5_1.default.stringify(nativeStyles), ");\n "), styledComponentsCode ? styledComponentsCode : '');
|
|
409
|
+
str = (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(str);
|
|
419
410
|
return str;
|
|
420
411
|
};
|
|
421
412
|
var templateObject_1;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
plugins?: Plugin[];
|
|
6
|
-
};
|
|
7
|
-
export declare const componentToSolid: (componentJson: MitosisComponent, options?: ToSolidOptions) => string;
|
|
8
|
-
export {};
|
|
1
|
+
import { BaseTranspilerOptions, Transpiler } from '../types/config';
|
|
2
|
+
export interface ToSolidOptions extends BaseTranspilerOptions {
|
|
3
|
+
}
|
|
4
|
+
export declare const componentToSolid: (options?: ToSolidOptions) => Transpiler;
|