@builder.io/mitosis 0.0.85 → 0.0.87
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/generators/angular.js +1 -1
- package/dist/src/generators/qwik/jsx.js +19 -21
- package/dist/src/generators/react/generator.js +5 -6
- package/dist/src/generators/react/state.js +12 -5
- package/dist/src/generators/react-native.js +2 -1
- package/dist/src/generators/rsc.js +3 -2
- package/dist/src/generators/solid/index.js +3 -2
- package/dist/src/generators/svelte/blocks.js +3 -2
- package/dist/src/generators/vue/blocks.js +59 -50
- package/dist/src/generators/vue/compositionApi.js +1 -1
- package/dist/src/generators/vue/optionsApi.js +1 -1
- package/dist/src/generators/vue/vue.js +2 -1
- package/dist/src/helpers/bindings.d.ts +2 -0
- package/dist/src/helpers/bindings.js +16 -0
- package/dist/src/helpers/get-styles.js +2 -1
- package/dist/src/parsers/angular.js +8 -7
- package/dist/src/parsers/builder/builder.js +30 -26
- package/dist/src/parsers/jsx/element-parser.js +18 -15
- package/dist/src/parsers/jsx/state.js +1 -12
- package/dist/src/parsers/svelte/helpers/bindings.js +5 -4
- package/dist/src/parsers/svelte/helpers/post-process.js +5 -8
- package/dist/src/parsers/svelte/html/each.d.ts +2 -33
- package/dist/src/parsers/svelte/html/each.js +3 -2
- package/dist/src/parsers/svelte/html/element.js +17 -23
- package/dist/src/parsers/svelte/html/if-else.js +3 -2
- package/dist/src/parsers/svelte/html/mustache-tag.js +5 -4
- package/dist/src/plugins/compile-away-builder-components.js +21 -20
- package/dist/src/types/mitosis-node.d.ts +9 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -381,7 +381,7 @@ var componentToAngular = function (userOptions) {
|
|
|
381
381
|
var _a;
|
|
382
382
|
var value = json.defaultProps.hasOwnProperty(prop)
|
|
383
383
|
? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
384
|
-
: '
|
|
384
|
+
: 'undefined';
|
|
385
385
|
return "".concat(prop, ": ").concat(value);
|
|
386
386
|
})
|
|
387
387
|
.join(',');
|
|
@@ -183,32 +183,30 @@ function isSlotProjection(child) {
|
|
|
183
183
|
* @returns
|
|
184
184
|
*/
|
|
185
185
|
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
186
|
-
var _a, _b;
|
|
187
186
|
var outBindings = {};
|
|
188
187
|
for (var key in bindings) {
|
|
189
188
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
190
|
-
var
|
|
189
|
+
var bindingValue = bindings[key];
|
|
190
|
+
var bindingExpr = bindingValue.code;
|
|
191
191
|
var handlerBlock = void 0;
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
key = (0, src_generator_1.lastProperty)(key);
|
|
209
|
-
}
|
|
210
|
-
outBindings[key] = { code: bindingExpr, type: (_b = bindings === null || bindings === void 0 ? void 0 : bindings[key]) === null || _b === void 0 ? void 0 : _b.type };
|
|
192
|
+
if (key == 'css') {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
else if ((handlerBlock = handlers.get(bindingExpr))) {
|
|
196
|
+
key = "".concat(key, "$");
|
|
197
|
+
bindingExpr = (0, src_generator_1.invoke)(file.import(file.qwikModule, 'qrl'), [
|
|
198
|
+
(0, src_generator_1.quote)(file.qrlPrefix + 'high.js'),
|
|
199
|
+
(0, src_generator_1.quote)(handlerBlock),
|
|
200
|
+
'[state]',
|
|
201
|
+
]);
|
|
202
|
+
}
|
|
203
|
+
else if (symbolBindings && key.startsWith('symbol.data.')) {
|
|
204
|
+
symbolBindings[(0, src_generator_1.lastProperty)(key)] = bindingExpr;
|
|
205
|
+
}
|
|
206
|
+
else if (key.startsWith('component.options.')) {
|
|
207
|
+
key = (0, src_generator_1.lastProperty)(key);
|
|
211
208
|
}
|
|
209
|
+
outBindings[key] = __assign(__assign({}, bindingValue), { code: bindingExpr });
|
|
212
210
|
}
|
|
213
211
|
}
|
|
214
212
|
return outBindings;
|
|
@@ -50,6 +50,7 @@ var state_2 = require("./state");
|
|
|
50
50
|
var helpers_2 = require("./helpers");
|
|
51
51
|
var hash_sum_1 = __importDefault(require("hash-sum"));
|
|
52
52
|
var for_1 = require("../../helpers/nodes/for");
|
|
53
|
+
var bindings_1 = require("../../helpers/bindings");
|
|
53
54
|
exports.contextPropDrillingKey = '_context';
|
|
54
55
|
var openFrag = function (options) { return getFragment('open', options); };
|
|
55
56
|
var closeFrag = function (options) { return getFragment('close', options); };
|
|
@@ -310,9 +311,9 @@ function provideContext(json, options) {
|
|
|
310
311
|
json.children = [
|
|
311
312
|
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: "".concat(name_2, ".Provider"), children: json.children }, (value && {
|
|
312
313
|
bindings: {
|
|
313
|
-
value: {
|
|
314
|
+
value: (0, bindings_1.createSingleBinding)({
|
|
314
315
|
code: (0, get_state_object_string_1.stringifyContextValue)(value),
|
|
315
|
-
},
|
|
316
|
+
}),
|
|
316
317
|
},
|
|
317
318
|
}))),
|
|
318
319
|
];
|
|
@@ -321,9 +322,7 @@ function provideContext(json, options) {
|
|
|
321
322
|
json.children = [
|
|
322
323
|
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: 'Context.Provider', children: json.children }, (ref && {
|
|
323
324
|
bindings: {
|
|
324
|
-
value: {
|
|
325
|
-
code: ref,
|
|
326
|
-
},
|
|
325
|
+
value: (0, bindings_1.createSingleBinding)({ code: ref }),
|
|
327
326
|
},
|
|
328
327
|
}))),
|
|
329
328
|
];
|
|
@@ -477,7 +476,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
477
476
|
var _a;
|
|
478
477
|
var value = json.defaultProps.hasOwnProperty(prop)
|
|
479
478
|
? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
480
|
-
: '
|
|
479
|
+
: 'undefined';
|
|
481
480
|
return "".concat(prop, ": ").concat(value);
|
|
482
481
|
})
|
|
483
482
|
.join(',');
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -76,11 +87,7 @@ var updateStateSetters = function (json, options) {
|
|
|
76
87
|
var values = item.bindings[key];
|
|
77
88
|
var newValue = (0, exports.updateStateSettersInCode)(values === null || values === void 0 ? void 0 : values.code, options);
|
|
78
89
|
if (newValue !== (values === null || values === void 0 ? void 0 : values.code)) {
|
|
79
|
-
item.bindings[key] = {
|
|
80
|
-
code: newValue,
|
|
81
|
-
arguments: values === null || values === void 0 ? void 0 : values.arguments,
|
|
82
|
-
type: values === null || values === void 0 ? void 0 : values.type,
|
|
83
|
-
};
|
|
90
|
+
item.bindings[key] = __assign(__assign({}, values), { code: newValue });
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
93
|
}
|
|
@@ -30,6 +30,7 @@ var fast_clone_1 = require("../helpers/fast-clone");
|
|
|
30
30
|
var traverse_1 = __importDefault(require("traverse"));
|
|
31
31
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
32
32
|
var react_1 = require("./react");
|
|
33
|
+
var bindings_1 = require("../helpers/bindings");
|
|
33
34
|
var stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
|
|
34
35
|
var MEDIA_QUERY_KEY_REGEX = /^@media.*/;
|
|
35
36
|
var collectReactNativeStyles = function (json) {
|
|
@@ -69,7 +70,7 @@ var collectReactNativeStyles = function (json) {
|
|
|
69
70
|
var componentName = (0, lodash_1.camelCase)(item.name || 'view');
|
|
70
71
|
var index = (componentIndexes[componentName] = (componentIndexes[componentName] || 0) + 1);
|
|
71
72
|
var className = "".concat(componentName).concat(index);
|
|
72
|
-
item.bindings.style = { code: "styles.".concat(className) };
|
|
73
|
+
item.bindings.style = (0, bindings_1.createSingleBinding)({ code: "styles.".concat(className) });
|
|
73
74
|
styleMap[className] = value;
|
|
74
75
|
});
|
|
75
76
|
return styleMap;
|
|
@@ -24,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.componentToRsc = void 0;
|
|
27
|
+
var bindings_1 = require("../helpers/bindings");
|
|
27
28
|
var traverse_1 = __importDefault(require("traverse"));
|
|
28
29
|
var fast_clone_1 = require("../helpers/fast-clone");
|
|
29
30
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
@@ -57,9 +58,9 @@ var RSC_TRANSFORM_PLUGIN = function () { return ({
|
|
|
57
58
|
// Drill context down, aka
|
|
58
59
|
// function (props) { return <Component _context{props._context} /> }
|
|
59
60
|
if (!node.bindings[react_1.contextPropDrillingKey]) {
|
|
60
|
-
node.bindings[react_1.contextPropDrillingKey] = {
|
|
61
|
+
node.bindings[react_1.contextPropDrillingKey] = (0, bindings_1.createSingleBinding)({
|
|
61
62
|
code: react_1.contextPropDrillingKey,
|
|
62
|
-
};
|
|
63
|
+
});
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
if (node.bindings.ref) {
|
|
@@ -76,13 +76,14 @@ var merge_options_1 = require("../../helpers/merge-options");
|
|
|
76
76
|
var process_code_1 = require("../../helpers/plugins/process-code");
|
|
77
77
|
var context_1 = require("../helpers/context");
|
|
78
78
|
var blocks_1 = require("./blocks");
|
|
79
|
+
var bindings_1 = require("../../helpers/bindings");
|
|
79
80
|
// Transform <foo.bar key={value} /> to <Dynamic compnent={foo.bar} key={value} />
|
|
80
81
|
function processDynamicComponents(json, options) {
|
|
81
82
|
var found = false;
|
|
82
83
|
(0, traverse_1.default)(json).forEach(function (node) {
|
|
83
84
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
84
85
|
if (node.name.includes('.') && !node.name.endsWith('.Provider')) {
|
|
85
|
-
node.bindings.component = { code: node.name };
|
|
86
|
+
node.bindings.component = (0, bindings_1.createSingleBinding)({ code: node.name });
|
|
86
87
|
node.name = 'Dynamic';
|
|
87
88
|
found = true;
|
|
88
89
|
}
|
|
@@ -112,7 +113,7 @@ function addProviderComponents(json, options) {
|
|
|
112
113
|
json.children = [
|
|
113
114
|
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: "".concat(name_1, ".Provider"), children: json.children }, (value && {
|
|
114
115
|
bindings: {
|
|
115
|
-
value: { code: (0, get_state_object_string_1.stringifyContextValue)(value) },
|
|
116
|
+
value: (0, bindings_1.createSingleBinding)({ code: (0, get_state_object_string_1.stringifyContextValue)(value) }),
|
|
116
117
|
},
|
|
117
118
|
}))),
|
|
118
119
|
];
|
|
@@ -12,6 +12,7 @@ var html_tags_1 = require("../../constants/html_tags");
|
|
|
12
12
|
var is_upper_case_1 = require("../../helpers/is-upper-case");
|
|
13
13
|
var for_1 = require("../../helpers/nodes/for");
|
|
14
14
|
var helpers_1 = require("./helpers");
|
|
15
|
+
var bindings_1 = require("../../helpers/bindings");
|
|
15
16
|
var mappers = {
|
|
16
17
|
Fragment: function (_a) {
|
|
17
18
|
var _b;
|
|
@@ -96,9 +97,9 @@ var getTagName = function (_a) {
|
|
|
96
97
|
// TO-DO: no way to decide between <svelte:component> and <svelte:element>...need to do that through metadata
|
|
97
98
|
// overrides for now
|
|
98
99
|
if (!isValidHtmlTag && !isSpecialSvelteTag && !hasMatchingImport) {
|
|
99
|
-
json.bindings.this = {
|
|
100
|
+
json.bindings.this = (0, bindings_1.createSingleBinding)({
|
|
100
101
|
code: (0, helpers_1.stripStateAndProps)({ json: parentComponent, options: options })(json.name),
|
|
101
|
-
};
|
|
102
|
+
});
|
|
102
103
|
return SVELTE_SPECIAL_TAGS.COMPONENT;
|
|
103
104
|
}
|
|
104
105
|
return json.name;
|
|
@@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.blockToVue = void 0;
|
|
18
18
|
var function_1 = require("fp-ts/lib/function");
|
|
19
|
-
var lodash_1 = require("lodash");
|
|
20
19
|
var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
21
20
|
var is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
22
21
|
var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
@@ -25,11 +24,15 @@ var replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
|
25
24
|
var slots_1 = require("../../helpers/slots");
|
|
26
25
|
var jsx_1 = require("../../parsers/jsx");
|
|
27
26
|
var helpers_1 = require("./helpers");
|
|
27
|
+
var nullable_1 = require("../../helpers/nullable");
|
|
28
28
|
var SPECIAL_PROPERTIES = {
|
|
29
29
|
V_IF: 'v-if',
|
|
30
30
|
V_FOR: 'v-for',
|
|
31
31
|
V_ELSE: 'v-else',
|
|
32
32
|
V_ELSE_IF: 'v-else-if',
|
|
33
|
+
V_ON: 'v-on',
|
|
34
|
+
V_ON_AT: '@',
|
|
35
|
+
V_BIND: 'v-bind',
|
|
33
36
|
};
|
|
34
37
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
35
38
|
var BINDING_MAPPERS = {
|
|
@@ -37,16 +40,17 @@ var BINDING_MAPPERS = {
|
|
|
37
40
|
};
|
|
38
41
|
var NODE_MAPPERS = {
|
|
39
42
|
Fragment: function (json, options, scope) {
|
|
40
|
-
|
|
43
|
+
var children = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
44
|
+
if (options.vueVersion === 2 && (scope === null || scope === void 0 ? void 0 : scope.isRootNode) && children.length > 1) {
|
|
41
45
|
throw new Error('Vue 2 template should have a single root element');
|
|
42
46
|
}
|
|
43
|
-
return
|
|
47
|
+
return children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n');
|
|
44
48
|
},
|
|
45
49
|
For: function (_json, options) {
|
|
46
50
|
var _a, _b;
|
|
47
51
|
var _c;
|
|
48
52
|
var json = _json;
|
|
49
|
-
var keyValue = json.bindings.key || { code: 'index' };
|
|
53
|
+
var keyValue = json.bindings.key || { code: 'index', type: 'single' };
|
|
50
54
|
var forValue = "(".concat(json.scope.forName, ", index) in ").concat((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code);
|
|
51
55
|
if (options.vueVersion >= 3) {
|
|
52
56
|
// TODO: tmk key goes on different element (parent vs child) based on Vue 2 vs Vue 3
|
|
@@ -191,13 +195,12 @@ var NODE_MAPPERS = {
|
|
|
191
195
|
};
|
|
192
196
|
var stringifyBinding = function (node) {
|
|
193
197
|
return function (_a) {
|
|
194
|
-
var _b;
|
|
195
198
|
var key = _a[0], value = _a[1];
|
|
196
|
-
if (
|
|
199
|
+
if (value.type === 'spread') {
|
|
197
200
|
return ''; // we handle this after
|
|
198
201
|
}
|
|
199
202
|
else if (key === 'class') {
|
|
200
|
-
return "
|
|
203
|
+
return ":class=\"_classStringToObject(".concat(value === null || value === void 0 ? void 0 : value.code, ")\"");
|
|
201
204
|
// TODO: support dynamic classes as objects somehow like Vue requires
|
|
202
205
|
// https://vuejs.org/v2/guide/class-and-style.html
|
|
203
206
|
}
|
|
@@ -205,37 +208,70 @@ var stringifyBinding = function (node) {
|
|
|
205
208
|
// TODO: proper babel transform to replace. Util for this
|
|
206
209
|
var useValue = (value === null || value === void 0 ? void 0 : value.code) || '';
|
|
207
210
|
if (key.startsWith('on')) {
|
|
208
|
-
var
|
|
211
|
+
var _b = value.arguments, cusArgs = _b === void 0 ? ['event'] : _b;
|
|
209
212
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
210
213
|
if (event_1 === 'change' && node.name === 'input') {
|
|
211
214
|
event_1 = 'input';
|
|
212
215
|
}
|
|
213
216
|
var isAssignmentExpression = useValue.includes('=');
|
|
214
|
-
var
|
|
217
|
+
var eventHandlerValue = (0, function_1.pipe)((0, replace_identifiers_1.replaceIdentifiers)({
|
|
215
218
|
code: useValue,
|
|
216
219
|
from: cusArgs[0],
|
|
217
220
|
to: '$event',
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return " @".concat(event_1, "=\"").concat((0, helpers_1.encodeQuotes)((0, remove_surrounding_block_1.removeSurroundingBlock)(valueWRenamedEvent)), "\" ");
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
return " @".concat(event_1, "=\"").concat((0, helpers_1.encodeQuotes)((0, remove_surrounding_block_1.removeSurroundingBlock)((0, remove_surrounding_block_1.removeSurroundingBlock)(valueWRenamedEvent))), "\" ");
|
|
225
|
-
}
|
|
221
|
+
}), isAssignmentExpression ? function_1.identity : remove_surrounding_block_1.removeSurroundingBlock, remove_surrounding_block_1.removeSurroundingBlock, helpers_1.encodeQuotes);
|
|
222
|
+
var eventHandlerKey = "".concat(SPECIAL_PROPERTIES.V_ON_AT).concat(event_1);
|
|
223
|
+
return "".concat(eventHandlerKey, "=\"").concat(eventHandlerValue, "\"");
|
|
226
224
|
}
|
|
227
225
|
else if (key === 'ref') {
|
|
228
|
-
return "
|
|
226
|
+
return "ref=\"".concat((0, helpers_1.encodeQuotes)(useValue), "\"");
|
|
229
227
|
}
|
|
230
228
|
else if (BINDING_MAPPERS[key]) {
|
|
231
|
-
return "
|
|
229
|
+
return "".concat(BINDING_MAPPERS[key], "=\"").concat((0, helpers_1.encodeQuotes)(useValue.replace(/"/g, "\\'")), "\"");
|
|
232
230
|
}
|
|
233
231
|
else {
|
|
234
|
-
return "
|
|
232
|
+
return ":".concat(key, "=\"").concat((0, helpers_1.encodeQuotes)(useValue), "\"");
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
};
|
|
238
236
|
};
|
|
237
|
+
var stringifySpreads = function (_a) {
|
|
238
|
+
var node = _a.node, spreadType = _a.spreadType;
|
|
239
|
+
var spreads = Object.values(node.bindings)
|
|
240
|
+
.filter(nullable_1.checkIsDefined)
|
|
241
|
+
.filter(function (binding) { return binding.type === 'spread' && binding.spreadType === spreadType; })
|
|
242
|
+
.map(function (value) { return (value.code === 'props' ? '$props' : value.code); });
|
|
243
|
+
if (spreads.length === 0) {
|
|
244
|
+
return '';
|
|
245
|
+
}
|
|
246
|
+
var stringifiedValue = spreads.length > 1 ? "{".concat(spreads.map(function (spread) { return "...".concat(spread); }).join(', '), "}") : spreads[0];
|
|
247
|
+
var key = spreadType === 'normal' ? SPECIAL_PROPERTIES.V_BIND : SPECIAL_PROPERTIES.V_ON;
|
|
248
|
+
return " ".concat(key, "=\"").concat((0, helpers_1.encodeQuotes)(stringifiedValue), "\" ");
|
|
249
|
+
};
|
|
250
|
+
var getBlockBindings = function (node) {
|
|
251
|
+
var stringifiedProperties = Object.entries(node.properties)
|
|
252
|
+
.map(function (_a) {
|
|
253
|
+
var key = _a[0], value = _a[1];
|
|
254
|
+
if (key === 'className') {
|
|
255
|
+
return '';
|
|
256
|
+
}
|
|
257
|
+
else if (key === SPECIAL_PROPERTIES.V_ELSE) {
|
|
258
|
+
return "".concat(key);
|
|
259
|
+
}
|
|
260
|
+
else if (typeof value === 'string') {
|
|
261
|
+
return "".concat(key, "=\"").concat((0, helpers_1.encodeQuotes)(value), "\"");
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
.join(' ');
|
|
265
|
+
var stringifiedBindings = Object.entries(node.bindings)
|
|
266
|
+
.map(stringifyBinding(node))
|
|
267
|
+
.join(' ');
|
|
268
|
+
return [
|
|
269
|
+
stringifiedProperties,
|
|
270
|
+
stringifiedBindings,
|
|
271
|
+
stringifySpreads({ node: node, spreadType: 'normal' }),
|
|
272
|
+
stringifySpreads({ node: node, spreadType: 'event-handlers' }),
|
|
273
|
+
].join(' ');
|
|
274
|
+
};
|
|
239
275
|
var blockToVue = function (node, options, scope) {
|
|
240
276
|
var _a;
|
|
241
277
|
var nodeMapper = NODE_MAPPERS[node.name];
|
|
@@ -249,7 +285,7 @@ var blockToVue = function (node, options, scope) {
|
|
|
249
285
|
// Vue doesn't allow <style>...</style> in templates, but does support the synonymous
|
|
250
286
|
// <component is="'style'">...</component>
|
|
251
287
|
node.name = 'component';
|
|
252
|
-
node.bindings.is = { code: "'style'" };
|
|
288
|
+
node.bindings.is = { code: "'style'", type: 'single' };
|
|
253
289
|
}
|
|
254
290
|
if (node.properties._text) {
|
|
255
291
|
return "".concat(node.properties._text);
|
|
@@ -261,35 +297,8 @@ var blockToVue = function (node, options, scope) {
|
|
|
261
297
|
}
|
|
262
298
|
return "{{".concat(textCode, "}}");
|
|
263
299
|
}
|
|
264
|
-
var str =
|
|
265
|
-
str +=
|
|
266
|
-
for (var key in node.properties) {
|
|
267
|
-
var value = node.properties[key];
|
|
268
|
-
if (key === 'className') {
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
else if (key === SPECIAL_PROPERTIES.V_ELSE) {
|
|
272
|
-
str += " ".concat(key, " ");
|
|
273
|
-
}
|
|
274
|
-
else if (typeof value === 'string') {
|
|
275
|
-
str += " ".concat(key, "=\"").concat((0, helpers_1.encodeQuotes)(value), "\" ");
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
var stringifiedBindings = Object.entries(node.bindings).map(stringifyBinding(node)).join('');
|
|
279
|
-
str += stringifiedBindings;
|
|
280
|
-
// spreads
|
|
281
|
-
var spreads = (0, lodash_1.filter)(node.bindings, function (binding) { return (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread'; }).map(function (value) {
|
|
282
|
-
return (value === null || value === void 0 ? void 0 : value.code) === 'props' ? '$props' : value === null || value === void 0 ? void 0 : value.code;
|
|
283
|
-
});
|
|
284
|
-
if (spreads === null || spreads === void 0 ? void 0 : spreads.length) {
|
|
285
|
-
if (spreads.length > 1) {
|
|
286
|
-
var spreadsString = "{...".concat(spreads.join(', ...'), "}");
|
|
287
|
-
str += " v-bind=\"".concat((0, helpers_1.encodeQuotes)(spreadsString), "\"");
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
str += " v-bind=\"".concat((0, helpers_1.encodeQuotes)(spreads.join('')), "\"");
|
|
291
|
-
}
|
|
292
|
-
}
|
|
300
|
+
var str = "<".concat(node.name, " ");
|
|
301
|
+
str += getBlockBindings(node);
|
|
293
302
|
if (jsx_1.selfClosingTags.has(node.name)) {
|
|
294
303
|
return str + ' />';
|
|
295
304
|
}
|
|
@@ -25,7 +25,7 @@ var getCompositionPropDefinition = function (_a) {
|
|
|
25
25
|
var _a;
|
|
26
26
|
var value = component.defaultProps.hasOwnProperty(prop)
|
|
27
27
|
? (_a = component.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
28
|
-
: '
|
|
28
|
+
: 'undefined';
|
|
29
29
|
return "".concat(prop, ": ").concat(value);
|
|
30
30
|
})
|
|
31
31
|
.join(',');
|
|
@@ -132,7 +132,7 @@ function generateOptionsApiScript(component, options, path, template, props, onU
|
|
|
132
132
|
var _a;
|
|
133
133
|
var value = component.defaultProps.hasOwnProperty(prop)
|
|
134
134
|
? (_a = component.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
135
|
-
: '
|
|
135
|
+
: 'undefined';
|
|
136
136
|
return "".concat(prop, ": { default: ").concat(value, " }");
|
|
137
137
|
})
|
|
138
138
|
.join(',');
|
|
@@ -42,12 +42,13 @@ var blocks_1 = require("./blocks");
|
|
|
42
42
|
var merge_options_1 = require("../../helpers/merge-options");
|
|
43
43
|
var process_code_1 = require("../../helpers/plugins/process-code");
|
|
44
44
|
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
45
|
+
var bindings_1 = require("../../helpers/bindings");
|
|
45
46
|
// Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
|
|
46
47
|
function processDynamicComponents(json, _options) {
|
|
47
48
|
(0, traverse_1.default)(json).forEach(function (node) {
|
|
48
49
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
49
50
|
if (node.name.includes('.')) {
|
|
50
|
-
node.bindings.is = { code: node.name };
|
|
51
|
+
node.bindings.is = (0, bindings_1.createSingleBinding)({ code: node.name });
|
|
51
52
|
node.name = 'component';
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createSingleBinding = void 0;
|
|
15
|
+
var createSingleBinding = function (args) { return (__assign(__assign({}, args), { type: 'single' })); };
|
|
16
|
+
exports.createSingleBinding = createSingleBinding;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.setStyles = exports.getStyles = void 0;
|
|
7
7
|
var json5_1 = __importDefault(require("json5"));
|
|
8
8
|
var lodash_1 = require("lodash");
|
|
9
|
+
var bindings_1 = require("./bindings");
|
|
9
10
|
var getStyles = function (json) {
|
|
10
11
|
var _a;
|
|
11
12
|
if (!json.bindings.css) {
|
|
@@ -27,7 +28,7 @@ var setStyles = function (json, styles) {
|
|
|
27
28
|
delete json.bindings.css;
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
json.bindings.css = { code: json5_1.default.stringify(styles) };
|
|
31
|
+
json.bindings.css = (0, bindings_1.createSingleBinding)({ code: json5_1.default.stringify(styles) });
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
exports.setStyles = setStyles;
|
|
@@ -12,6 +12,7 @@ var lodash_1 = require("lodash");
|
|
|
12
12
|
var babel_transform_1 = require("../helpers/babel-transform");
|
|
13
13
|
var core_1 = require("@babel/core");
|
|
14
14
|
var capitalize_1 = require("../helpers/capitalize");
|
|
15
|
+
var bindings_1 = require("../helpers/bindings");
|
|
15
16
|
var getTsAST = function (code) {
|
|
16
17
|
return typescript_1.default.createSourceFile('code.ts', code, typescript_1.default.ScriptTarget.Latest, true);
|
|
17
18
|
};
|
|
@@ -46,9 +47,9 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
46
47
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
47
48
|
name: 'Show',
|
|
48
49
|
bindings: {
|
|
49
|
-
when: {
|
|
50
|
+
when: (0, bindings_1.createSingleBinding)({
|
|
50
51
|
code: transformBinding(ngIf.value.source, options),
|
|
51
|
-
},
|
|
52
|
+
}),
|
|
52
53
|
},
|
|
53
54
|
children: [angularTemplateNodeToMitosisNode((0, lodash_1.omit)(node, 'templateAttrs'), options)],
|
|
54
55
|
});
|
|
@@ -61,7 +62,7 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
61
62
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
62
63
|
name: 'For',
|
|
63
64
|
bindings: {
|
|
64
|
-
each: { code: transformBinding(expression, options) },
|
|
65
|
+
each: (0, bindings_1.createSingleBinding)({ code: transformBinding(expression, options) }),
|
|
65
66
|
},
|
|
66
67
|
scope: {
|
|
67
68
|
forName: itemName,
|
|
@@ -75,17 +76,17 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
75
76
|
var bindings = {};
|
|
76
77
|
for (var _i = 0, _a = node.inputs; _i < _a.length; _i++) {
|
|
77
78
|
var input = _a[_i];
|
|
78
|
-
bindings[input.name] = {
|
|
79
|
+
bindings[input.name] = (0, bindings_1.createSingleBinding)({
|
|
79
80
|
code: transformBinding(input.value.source, options),
|
|
80
|
-
};
|
|
81
|
+
});
|
|
81
82
|
}
|
|
82
83
|
for (var _b = 0, _c = node.outputs; _b < _c.length; _b++) {
|
|
83
84
|
var output = _c[_b];
|
|
84
|
-
bindings['on' + (0, capitalize_1.capitalize)(output.name)] = {
|
|
85
|
+
bindings['on' + (0, capitalize_1.capitalize)(output.name)] = (0, bindings_1.createSingleBinding)({
|
|
85
86
|
code: transformBinding(output.handler
|
|
86
87
|
.source // TODO: proper reference replace
|
|
87
88
|
.replace(/\$event/g, 'event'), options),
|
|
88
|
-
};
|
|
89
|
+
});
|
|
89
90
|
}
|
|
90
91
|
for (var _d = 0, _e = node.attributes; _d < _e.length; _d++) {
|
|
91
92
|
var attribute = _e[_d];
|