@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
|
@@ -20,32 +20,32 @@ var is_children_1 = __importDefault(require("../helpers/is-children"));
|
|
|
20
20
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
21
21
|
var scrolls = function (json) {
|
|
22
22
|
var _a;
|
|
23
|
-
return ((_a = get_styles_1.getStyles(json)) === null || _a === void 0 ? void 0 : _a.overflow) === 'auto';
|
|
23
|
+
return ((_a = (0, get_styles_1.getStyles)(json)) === null || _a === void 0 ? void 0 : _a.overflow) === 'auto';
|
|
24
24
|
};
|
|
25
25
|
var mappers = {
|
|
26
26
|
Fragment: function (json, options) {
|
|
27
|
-
return ""
|
|
27
|
+
return "".concat(json.children
|
|
28
28
|
.map(function (item) { return blockToSwift(item, options); })
|
|
29
|
-
.join('\n');
|
|
29
|
+
.join('\n'));
|
|
30
30
|
},
|
|
31
31
|
link: function () { return ''; },
|
|
32
32
|
Image: function (json, options) {
|
|
33
|
-
return ("Image("
|
|
34
|
-
"\""
|
|
33
|
+
return ("Image(".concat(processBinding(json.bindings.image, options) ||
|
|
34
|
+
"\"".concat(json.properties.image, "\""), ")") +
|
|
35
35
|
getStyleString(json, options) +
|
|
36
36
|
getActionsString(json, options));
|
|
37
37
|
},
|
|
38
38
|
input: function (json, options) {
|
|
39
39
|
var name = json.properties.$name;
|
|
40
|
-
var str = "TextField("
|
|
40
|
+
var str = "TextField(".concat(json.bindings.placeholder
|
|
41
41
|
? processBinding(json.bindings.placeholder, options)
|
|
42
42
|
: json.properties.placeholder
|
|
43
43
|
? JSON.stringify(json.bindings.placeholder)
|
|
44
|
-
: '""'
|
|
44
|
+
: '""', ", text: $").concat(name, ")") +
|
|
45
45
|
getStyleString(json, options) +
|
|
46
46
|
getActionsString(json, options);
|
|
47
47
|
if (json.bindings.onChange) {
|
|
48
|
-
str += "\n .onChange(of: "
|
|
48
|
+
str += "\n .onChange(of: ".concat(name, ") { ").concat(name, " in \n ").concat(processBinding(wrapAction("var event = { target: { value: \"\\(".concat(name, ")\" } };\n ").concat(json.bindings.onChange)), options), " \n }");
|
|
49
49
|
}
|
|
50
50
|
return str;
|
|
51
51
|
},
|
|
@@ -57,21 +57,21 @@ var blockToSwift = function (json, options) {
|
|
|
57
57
|
// TODO: Add support for `{props.children}` bindings
|
|
58
58
|
// Right now we return an empty string because the generated code
|
|
59
59
|
// is very likely wrong.
|
|
60
|
-
if (is_children_1.default(json)) {
|
|
60
|
+
if ((0, is_children_1.default)(json)) {
|
|
61
61
|
return '/* `props.children` is not supported yet for SwiftUI */';
|
|
62
62
|
}
|
|
63
63
|
if (json.properties._text) {
|
|
64
64
|
if (!json.properties._text.trim().length) {
|
|
65
65
|
return '';
|
|
66
66
|
}
|
|
67
|
-
return "Text(\""
|
|
67
|
+
return "Text(\"".concat(json.properties._text.trim().replace(/\s+/g, ' '), "\")");
|
|
68
68
|
}
|
|
69
69
|
if (json.bindings._text) {
|
|
70
|
-
return "Text("
|
|
70
|
+
return "Text(".concat(processBinding(json.bindings._text, options), ".toString())");
|
|
71
71
|
}
|
|
72
72
|
var str = '';
|
|
73
73
|
var children = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
74
|
-
var style = get_styles_1.getStyles(json);
|
|
74
|
+
var style = (0, get_styles_1.getStyles)(json);
|
|
75
75
|
// TODO: do as preprocess step and do more mappings of dom attributes to special
|
|
76
76
|
// Image, TextField, etc component props
|
|
77
77
|
var name = json.name === 'input'
|
|
@@ -91,15 +91,15 @@ var blockToSwift = function (json, options) {
|
|
|
91
91
|
json.properties._ = placeholder || '';
|
|
92
92
|
}
|
|
93
93
|
if (json.name === 'For') {
|
|
94
|
-
str += "ForEach("
|
|
94
|
+
str += "ForEach(".concat(processBinding(json.bindings.each, options), ", id: \\.self) { ").concat(json.properties._forName, " in ").concat(children
|
|
95
95
|
.map(function (item) { return blockToSwift(item, options); })
|
|
96
|
-
.join('\n')
|
|
96
|
+
.join('\n'), " }");
|
|
97
97
|
}
|
|
98
98
|
else if (json.name === 'Show') {
|
|
99
|
-
str += "if "
|
|
99
|
+
str += "if ".concat(processBinding(json.bindings.when, options), " {\n ").concat(children.map(function (item) { return blockToSwift(item, options); }).join('\n'), "\n }");
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
|
-
str += name
|
|
102
|
+
str += "".concat(name, "(");
|
|
103
103
|
for (var key in json.properties) {
|
|
104
104
|
if (key === 'class' || key === 'className') {
|
|
105
105
|
continue;
|
|
@@ -107,7 +107,7 @@ var blockToSwift = function (json, options) {
|
|
|
107
107
|
// TODO: binding mappings
|
|
108
108
|
// const value = json.properties[key];
|
|
109
109
|
// str += ` ${key}: "${(value as string).replace(/"/g, '"')}", `;
|
|
110
|
-
console.warn("Unsupported property \""
|
|
110
|
+
console.warn("Unsupported property \"".concat(key, "\""));
|
|
111
111
|
}
|
|
112
112
|
for (var key in json.bindings) {
|
|
113
113
|
if (
|
|
@@ -125,11 +125,11 @@ var blockToSwift = function (json, options) {
|
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
127
|
// TODO: other event mappings
|
|
128
|
-
console.warn("Unsupported event binding \""
|
|
128
|
+
console.warn("Unsupported event binding \"".concat(key, "\""));
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
|
-
console.warn("Unsupported binding \""
|
|
132
|
+
console.warn("Unsupported binding \"".concat(key, "\""));
|
|
133
133
|
// TODO: need binding mappings
|
|
134
134
|
// str += ` ${key}: ${processBinding(value, options)}, `;
|
|
135
135
|
}
|
|
@@ -147,52 +147,52 @@ var blockToSwift = function (json, options) {
|
|
|
147
147
|
}
|
|
148
148
|
return str;
|
|
149
149
|
};
|
|
150
|
-
var wrapAction = function (str) { return "(() => { "
|
|
150
|
+
var wrapAction = function (str) { return "(() => { ".concat(str, " })()"); };
|
|
151
151
|
function getActionsString(json, options) {
|
|
152
152
|
var str = '';
|
|
153
153
|
if (json.bindings.onClick) {
|
|
154
|
-
str += "\n.onTapGesture {\n "
|
|
154
|
+
str += "\n.onTapGesture {\n ".concat(processBinding(wrapAction(json.bindings.onClick), options), "\n }");
|
|
155
155
|
}
|
|
156
156
|
return str;
|
|
157
157
|
}
|
|
158
158
|
function getStyleString(node, options) {
|
|
159
|
-
var style = get_styles_1.getStyles(node);
|
|
159
|
+
var style = (0, get_styles_1.getStyles)(node);
|
|
160
160
|
var str = '';
|
|
161
161
|
for (var key in style) {
|
|
162
162
|
var useKey = key;
|
|
163
163
|
var rawValue = style[key];
|
|
164
|
-
var value = "\""
|
|
164
|
+
var value = "\"".concat(rawValue, "\"");
|
|
165
165
|
if (['padding', 'margin'].includes(key)) {
|
|
166
166
|
// TODO: throw error if calc()
|
|
167
167
|
value = parseFloat(rawValue);
|
|
168
|
-
str += "\n."
|
|
168
|
+
str += "\n.".concat(useKey, "(").concat(value, ")");
|
|
169
169
|
}
|
|
170
170
|
else if (key === 'color') {
|
|
171
171
|
useKey = 'foregroundColor';
|
|
172
172
|
// TODO: convert to RBG and use Color(red: ..., ....)
|
|
173
173
|
}
|
|
174
174
|
else {
|
|
175
|
-
console.warn("Styling key \""
|
|
175
|
+
console.warn("Styling key \"".concat(key, "\" is not supported"));
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
return str;
|
|
179
179
|
}
|
|
180
180
|
function getJsSource(json, options) {
|
|
181
|
-
var str = "const state = new Proxy("
|
|
181
|
+
var str = "const state = new Proxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ", {\n set: (target, key, value) => {\n const returnVal = Reflect.set(target, key, value);\n update();\n return returnVal;\n }\n });");
|
|
182
182
|
if (options.prettier === false) {
|
|
183
183
|
return str.trim();
|
|
184
184
|
}
|
|
185
185
|
else {
|
|
186
|
-
return try_prettier_format_1.tryPrettierFormat(str, 'typescript').trim();
|
|
186
|
+
return (0, try_prettier_format_1.tryPrettierFormat)(str, 'typescript').trim();
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
var processBinding = function (str, options) {
|
|
190
190
|
// Use triple quotes for multiline strings or strings including '"'
|
|
191
191
|
if (str.includes('\n') || str.includes('"')) {
|
|
192
|
-
return "eval(code: \"\"\"\n "
|
|
192
|
+
return "eval(code: \"\"\"\n ".concat(str, "\n \"\"\")");
|
|
193
193
|
}
|
|
194
194
|
// Use double quotes for simple strings
|
|
195
|
-
return "eval(code: \""
|
|
195
|
+
return "eval(code: \"".concat(str, "\")");
|
|
196
196
|
};
|
|
197
197
|
function componentHasDynamicData(json) {
|
|
198
198
|
var hasState = Object.keys(json.state).length > 0;
|
|
@@ -200,8 +200,8 @@ function componentHasDynamicData(json) {
|
|
|
200
200
|
return true;
|
|
201
201
|
}
|
|
202
202
|
var found = false;
|
|
203
|
-
traverse_1.default(json).forEach(function (node) {
|
|
204
|
-
if (is_mitosis_node_1.isMitosisNode(node)) {
|
|
203
|
+
(0, traverse_1.default)(json).forEach(function (node) {
|
|
204
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
205
205
|
if (Object.keys(node.bindings).filter(function (item) { return item !== 'css'; }).length) {
|
|
206
206
|
found = true;
|
|
207
207
|
this.stop();
|
|
@@ -213,14 +213,14 @@ function componentHasDynamicData(json) {
|
|
|
213
213
|
function mapDataForSwiftCompatability(json) {
|
|
214
214
|
var inputIndex = 0;
|
|
215
215
|
json.meta.inputNames = json.meta.inputNames || [];
|
|
216
|
-
traverse_1.default(json).forEach(function (node) {
|
|
217
|
-
if (is_mitosis_node_1.isMitosisNode(node)) {
|
|
216
|
+
(0, traverse_1.default)(json).forEach(function (node) {
|
|
217
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
218
218
|
if (node.name === 'input') {
|
|
219
219
|
if (!Object.keys(node.bindings).filter(function (item) { return item !== 'css'; }).length) {
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
if (!node.properties.$name) {
|
|
223
|
-
node.properties.$name = "input"
|
|
223
|
+
node.properties.$name = "input".concat(++inputIndex);
|
|
224
224
|
}
|
|
225
225
|
json.meta.inputNames[node.properties.$name] = node.bindings.value || '';
|
|
226
226
|
}
|
|
@@ -234,39 +234,39 @@ function getInputBindings(json, options) {
|
|
|
234
234
|
return str;
|
|
235
235
|
}
|
|
236
236
|
for (var item in inputNames) {
|
|
237
|
-
str += "\n@State private var "
|
|
237
|
+
str += "\n@State private var ".concat(item, ": String = \"\"");
|
|
238
238
|
}
|
|
239
239
|
return str;
|
|
240
240
|
}
|
|
241
|
-
var componentToSwift = function (
|
|
241
|
+
var componentToSwift = function (options) {
|
|
242
242
|
if (options === void 0) { options = {}; }
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
"\n\n var body: some View {\n VStack {\n ", "\n }",
|
|
253
|
-
"\n }\n }\n "])), !hasDyanmicData
|
|
254
|
-
? ''
|
|
255
|
-
: "import JavaScriptCore\n \n final class UpdateTracker: ObservableObject {\n @Published var value = 0;\n \n func update() {\n value += 1\n }\n }\n ", componentJson.name, !hasDyanmicData
|
|
256
|
-
? ''
|
|
257
|
-
: ("\n @ObservedObject var updateTracker = UpdateTracker()\n private var jsContext = JSContext()\n " + getInputBindings(json, options) + "\n\n func eval(code: String) -> JSValue! {\n return jsContext?.evaluateScript(code)\n }\n\n " + (!hasInputNames
|
|
243
|
+
return function (_a) {
|
|
244
|
+
var component = _a.component;
|
|
245
|
+
var json = (0, fast_clone_1.fastClone)(component);
|
|
246
|
+
mapDataForSwiftCompatability(json);
|
|
247
|
+
var hasDyanmicData = componentHasDynamicData(json);
|
|
248
|
+
var children = json.children
|
|
249
|
+
.map(function (item) { return blockToSwift(item, options); })
|
|
250
|
+
.join('\n');
|
|
251
|
+
var hasInputNames = Object.keys(json.meta.inputNames || {}).length > 0;
|
|
252
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import SwiftUI\n ", "\n\n struct ", ": View {\n ", "\n\n var body: some View {\n VStack {\n ", "\n }", "\n }\n }\n "], ["\n import SwiftUI\n ", "\n\n struct ", ": View {\n ", "\n\n var body: some View {\n VStack {\n ", "\n }", "\n }\n }\n "])), !hasDyanmicData
|
|
258
253
|
? ''
|
|
259
|
-
: "\n func
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
254
|
+
: "import JavaScriptCore\n \n final class UpdateTracker: ObservableObject {\n @Published var value = 0;\n \n func update() {\n value += 1\n }\n }\n ", component.name, !hasDyanmicData
|
|
255
|
+
? ''
|
|
256
|
+
: "\n @ObservedObject var updateTracker = UpdateTracker()\n private var jsContext = JSContext()\n ".concat(getInputBindings(json, options), "\n\n func eval(code: String) -> JSValue! {\n return jsContext?.evaluateScript(code)\n }\n\n ").concat(!hasInputNames
|
|
257
|
+
? ''
|
|
258
|
+
: "\n func setComputedState() {\n ".concat(Object.keys(json.meta.inputNames || {})
|
|
259
|
+
.map(function (item) {
|
|
260
|
+
return "".concat(item, " = ").concat(processBinding(json.meta.inputNames[item], options), ".toString()!");
|
|
261
|
+
})
|
|
262
|
+
.join('\n'), "\n }"), "\n\n init() {\n let jsSource = \"\"\"\n ").concat(getJsSource(json, options), "\n \"\"\"\n jsContext?.exceptionHandler = { context, exception in\n print(\"JS Error: \\(exception!)\") \n }\n\n let updateRef = updateTracker.update\n let updateFn : @convention(block) () -> Void = { updateRef() }\n jsContext?.setObject(updateFn, forKeyedSubscript: \"update\" as NSString)\n\n jsContext?.evaluateScript(jsSource)\n }\n ").trim(), children, !hasInputNames
|
|
263
|
+
? ''
|
|
264
|
+
: "\n .onAppear {\n setComputedState()\n }\n ");
|
|
265
|
+
if (options.prettier !== false) {
|
|
266
|
+
str = (0, generic_format_1.format)(str);
|
|
267
|
+
}
|
|
268
|
+
return str;
|
|
269
|
+
};
|
|
270
270
|
};
|
|
271
271
|
exports.componentToSwift = componentToSwift;
|
|
272
272
|
var templateObject_1;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
plugins?: Plugin[];
|
|
6
|
-
};
|
|
7
|
-
export declare const componentToTemplate: (componentJson: MitosisComponent, options?: ToTemplateOptions) => string;
|
|
8
|
-
export {};
|
|
1
|
+
import { BaseTranspilerOptions, Transpiler } from '../types/config';
|
|
2
|
+
export interface ToTemplateOptions extends BaseTranspilerOptions {
|
|
3
|
+
}
|
|
4
|
+
export declare const componentToTemplate: (options?: ToTemplateOptions) => Transpiler;
|
|
@@ -17,9 +17,9 @@ var dedent_1 = __importDefault(require("dedent"));
|
|
|
17
17
|
var get_state_object_string_1 = require("../helpers/get-state-object-string");
|
|
18
18
|
var mappers = {
|
|
19
19
|
Fragment: function (json, options) {
|
|
20
|
-
return "<div>"
|
|
20
|
+
return "<div>".concat(json.children
|
|
21
21
|
.map(function (item) { return blockToTemplate(item, options); })
|
|
22
|
-
.join('\n')
|
|
22
|
+
.join('\n'), "</div>");
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
// TODO: spread support
|
|
@@ -32,11 +32,11 @@ var blockToTemplate = function (json, options) {
|
|
|
32
32
|
return json.properties._text;
|
|
33
33
|
}
|
|
34
34
|
if (json.bindings._text) {
|
|
35
|
-
return "${"
|
|
35
|
+
return "${".concat(json.bindings._text, "}");
|
|
36
36
|
}
|
|
37
37
|
var str = '';
|
|
38
38
|
if (json.name === 'For') {
|
|
39
|
-
str += "${"
|
|
39
|
+
str += "${".concat(json.bindings.each, "?.map(").concat(json.properties._forName, " => `");
|
|
40
40
|
if (json.children) {
|
|
41
41
|
str += json.children
|
|
42
42
|
.map(function (item) { return blockToTemplate(item, options); })
|
|
@@ -45,7 +45,7 @@ var blockToTemplate = function (json, options) {
|
|
|
45
45
|
str += '`).join("")}';
|
|
46
46
|
}
|
|
47
47
|
else if (json.name === 'Show') {
|
|
48
|
-
str += "${!("
|
|
48
|
+
str += "${!(".concat(json.bindings.when, ") ? '' : `");
|
|
49
49
|
if (json.children) {
|
|
50
50
|
str += json.children
|
|
51
51
|
.map(function (item) { return blockToTemplate(item, options); })
|
|
@@ -54,7 +54,7 @@ var blockToTemplate = function (json, options) {
|
|
|
54
54
|
str += '`}';
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
str += "<"
|
|
57
|
+
str += "<".concat(json.name, " ");
|
|
58
58
|
// TODO: JS iteration or with helper
|
|
59
59
|
// if (json.bindings._spread === '_spread') {
|
|
60
60
|
// str += `
|
|
@@ -65,7 +65,7 @@ var blockToTemplate = function (json, options) {
|
|
|
65
65
|
// }
|
|
66
66
|
for (var key in json.properties) {
|
|
67
67
|
var value = json.properties[key];
|
|
68
|
-
str += " "
|
|
68
|
+
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
69
69
|
}
|
|
70
70
|
for (var key in json.bindings) {
|
|
71
71
|
if (key === '_spread' || key === 'ref' || key === 'css') {
|
|
@@ -78,7 +78,7 @@ var blockToTemplate = function (json, options) {
|
|
|
78
78
|
// Do nothing
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
str += " "
|
|
81
|
+
str += " ".concat(key, "=\"${").concat(useValue, "}\" ");
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (jsx_1.selfClosingTags.has(json.name)) {
|
|
@@ -90,50 +90,53 @@ var blockToTemplate = function (json, options) {
|
|
|
90
90
|
.map(function (item) { return blockToTemplate(item, options); })
|
|
91
91
|
.join('\n');
|
|
92
92
|
}
|
|
93
|
-
str += "</"
|
|
93
|
+
str += "</".concat(json.name, ">");
|
|
94
94
|
}
|
|
95
95
|
return str;
|
|
96
96
|
};
|
|
97
97
|
// TODO: add JS support similar to componentToHtml()
|
|
98
|
-
var componentToTemplate = function (
|
|
98
|
+
var componentToTemplate = function (options) {
|
|
99
99
|
if (options === void 0) { options = {}; }
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
json =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (options.plugins) {
|
|
106
|
-
json = plugins_1.runPostJsonPlugins(json, options.plugins);
|
|
107
|
-
}
|
|
108
|
-
var str = json.children.map(function (item) { return blockToTemplate(item); }).join('\n');
|
|
109
|
-
if (css.trim().length) {
|
|
110
|
-
str += "<style>" + css + "</style>";
|
|
111
|
-
}
|
|
112
|
-
str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n export default function template(props) {\n let state = ", "\n\n return `", "`\n }\n \n "], ["\n export default function template(props) {\n let state = ", "\n\n return \\`", "\\`\n }\n \n "])), get_state_object_string_1.getStateObjectStringFromComponent(json), str.replace(/\s+/g, ' '));
|
|
113
|
-
if (options.plugins) {
|
|
114
|
-
str = plugins_1.runPreCodePlugins(str, options.plugins);
|
|
115
|
-
}
|
|
116
|
-
if (options.prettier !== false) {
|
|
117
|
-
try {
|
|
118
|
-
str = standalone_1.format(str, {
|
|
119
|
-
parser: 'typescript',
|
|
120
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
121
|
-
plugins: [
|
|
122
|
-
// To support running in browsers
|
|
123
|
-
require('prettier/parser-typescript'),
|
|
124
|
-
require('prettier/parser-postcss'),
|
|
125
|
-
require('prettier/parser-babel'),
|
|
126
|
-
],
|
|
127
|
-
});
|
|
100
|
+
return function (_a) {
|
|
101
|
+
var component = _a.component;
|
|
102
|
+
var json = (0, fast_clone_1.fastClone)(component);
|
|
103
|
+
if (options.plugins) {
|
|
104
|
+
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
128
105
|
}
|
|
129
|
-
|
|
130
|
-
|
|
106
|
+
var css = (0, collect_styles_1.collectCss)(json);
|
|
107
|
+
if (options.plugins) {
|
|
108
|
+
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
131
109
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return str;
|
|
110
|
+
var str = json.children.map(function (item) { return blockToTemplate(item); }).join('\n');
|
|
111
|
+
if (css.trim().length) {
|
|
112
|
+
str += "<style>".concat(css, "</style>");
|
|
113
|
+
}
|
|
114
|
+
str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n export default function template(props) {\n let state = ", "\n\n return `", "`\n }\n \n "], ["\n export default function template(props) {\n let state = ", "\n\n return \\`", "\\`\n }\n \n "])), (0, get_state_object_string_1.getStateObjectStringFromComponent)(json), str.replace(/\s+/g, ' '));
|
|
115
|
+
if (options.plugins) {
|
|
116
|
+
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
117
|
+
}
|
|
118
|
+
if (options.prettier !== false) {
|
|
119
|
+
try {
|
|
120
|
+
str = (0, standalone_1.format)(str, {
|
|
121
|
+
parser: 'typescript',
|
|
122
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
123
|
+
plugins: [
|
|
124
|
+
// To support running in browsers
|
|
125
|
+
require('prettier/parser-typescript'),
|
|
126
|
+
require('prettier/parser-postcss'),
|
|
127
|
+
require('prettier/parser-babel'),
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (options.plugins) {
|
|
136
|
+
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
137
|
+
}
|
|
138
|
+
return str;
|
|
139
|
+
};
|
|
137
140
|
};
|
|
138
141
|
exports.componentToTemplate = componentToTemplate;
|
|
139
142
|
var templateObject_1;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { MitosisComponent } from '../types/mitosis-component';
|
|
2
1
|
import { MitosisNode } from '../types/mitosis-node';
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
prettier?: boolean;
|
|
6
|
-
plugins?: Plugin[];
|
|
2
|
+
import { BaseTranspilerOptions, TranspilerArgs } from '../types/config';
|
|
3
|
+
export interface ToVueOptions extends BaseTranspilerOptions {
|
|
7
4
|
vueVersion?: 2 | 3;
|
|
8
|
-
cssNamespace?: string;
|
|
9
|
-
namePrefix?: string;
|
|
5
|
+
cssNamespace?: () => string;
|
|
6
|
+
namePrefix?: (path: string) => string;
|
|
10
7
|
builderRegister?: boolean;
|
|
11
|
-
|
|
8
|
+
registerComponentPrepend?: string;
|
|
9
|
+
}
|
|
12
10
|
export declare const blockToVue: (node: MitosisNode, options: ToVueOptions) => string;
|
|
13
|
-
export declare const componentToVue: (
|
|
11
|
+
export declare const componentToVue: (options?: ToVueOptions) => ({ component, path }: TranspilerArgs & {
|
|
12
|
+
path: string;
|
|
13
|
+
}) => string;
|