@builder.io/mitosis 0.0.72-5 → 0.0.72
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 +3 -3
- package/dist/src/generators/html.js +4 -4
- package/dist/src/generators/lit/generate.js +8 -8
- package/dist/src/generators/marko/generate.js +8 -8
- package/dist/src/generators/mitosis.js +5 -8
- package/dist/src/generators/qwik/jsx.js +2 -2
- package/dist/src/generators/qwik/src-generator.js +1 -1
- package/dist/src/generators/react/generator.d.ts +0 -1
- package/dist/src/generators/react/generator.js +36 -62
- package/dist/src/generators/react/state.js +1 -0
- package/dist/src/generators/react/types.d.ts +1 -6
- package/dist/src/generators/solid/index.js +8 -7
- package/dist/src/generators/stencil/generate.js +7 -7
- package/dist/src/generators/svelte.js +13 -12
- package/dist/src/generators/template.js +3 -3
- package/dist/src/generators/vue/blocks.js +17 -7
- package/dist/src/generators/vue/compositionApi.js +42 -7
- package/dist/src/helpers/has.d.ts +1 -1
- package/dist/src/helpers/has.js +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/parsers/jsx/element-parser.js +3 -1
- package/dist/src/parsers/jsx/function-parser.d.ts +1 -0
- package/dist/src/parsers/jsx/function-parser.js +6 -2
- package/dist/src/parsers/jsx/metadata.js +15 -7
- package/dist/src/parsers/jsx/state.js +4 -1
- package/dist/src/targets.d.ts +0 -1
- package/dist/src/targets.js +0 -2
- package/dist/src/types/mitosis-node.d.ts +6 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/dist/src/generators/context/rsc.d.ts +0 -12
- package/dist/src/generators/context/rsc.js +0 -32
- package/dist/src/generators/rsc.d.ts +0 -4
- package/dist/src/generators/rsc.js +0 -90
|
@@ -85,7 +85,7 @@ var BINDINGS_MAPPER = {
|
|
|
85
85
|
style: 'ngStyle',
|
|
86
86
|
};
|
|
87
87
|
var blockToAngular = function (json, options, blockOptions) {
|
|
88
|
-
var _a, _b, _c, _d, _e, _f;
|
|
88
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
89
89
|
if (options === void 0) { options = {}; }
|
|
90
90
|
if (blockOptions === void 0) { blockOptions = {}; }
|
|
91
91
|
var contextVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.contextVars) || [];
|
|
@@ -153,13 +153,13 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
153
153
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
154
154
|
}
|
|
155
155
|
for (var key in json.bindings) {
|
|
156
|
-
if (key === '
|
|
156
|
+
if (((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.type) === 'spread') {
|
|
157
157
|
continue;
|
|
158
158
|
}
|
|
159
159
|
if (key.startsWith('$')) {
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
|
-
var
|
|
162
|
+
var _h = json.bindings[key], code = _h.code, _j = _h.arguments, cusArgs = _j === void 0 ? ['event'] : _j;
|
|
163
163
|
// TODO: proper babel transform to replace. Util for this
|
|
164
164
|
var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
165
165
|
contextVars: contextVars,
|
|
@@ -191,7 +191,7 @@ var addOnChangeJs = function (id, options, code) {
|
|
|
191
191
|
};
|
|
192
192
|
// TODO: spread support
|
|
193
193
|
var blockToHtml = function (json, options, blockOptions) {
|
|
194
|
-
var _a, _b, _c, _d, _e, _f;
|
|
194
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
195
195
|
if (blockOptions === void 0) { blockOptions = {}; }
|
|
196
196
|
var ComponentName = blockOptions.ComponentName;
|
|
197
197
|
var scopeVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.scopeVars) || [];
|
|
@@ -280,11 +280,11 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
280
280
|
var injectOnce = false;
|
|
281
281
|
var startInjectVar = '%%START_VARS%%';
|
|
282
282
|
for (var key in json.bindings) {
|
|
283
|
-
if (key === '
|
|
283
|
+
if (((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.type) === 'spread' || key === 'css') {
|
|
284
284
|
continue;
|
|
285
285
|
}
|
|
286
|
-
var value = (
|
|
287
|
-
var cusArg = ((
|
|
286
|
+
var value = (_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code;
|
|
287
|
+
var cusArg = ((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.arguments) || ['event'];
|
|
288
288
|
// TODO: proper babel transform to replace. Util for this
|
|
289
289
|
var useValue = value;
|
|
290
290
|
if (key.startsWith('on')) {
|
|
@@ -41,7 +41,7 @@ var getCustomTagName = function (name, options) {
|
|
|
41
41
|
return kebabCaseName;
|
|
42
42
|
};
|
|
43
43
|
var blockToLit = function (json, options) {
|
|
44
|
-
var _a, _b, _c, _d
|
|
44
|
+
var _a, _b, _c, _d;
|
|
45
45
|
if (options === void 0) { options = {}; }
|
|
46
46
|
if (json.properties._text) {
|
|
47
47
|
return json.properties._text;
|
|
@@ -68,19 +68,19 @@ var blockToLit = function (json, options) {
|
|
|
68
68
|
if (classString) {
|
|
69
69
|
str += " class=".concat(classString, " ");
|
|
70
70
|
}
|
|
71
|
-
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
72
|
-
str += " ${spread(".concat(json.bindings._spread.code, ")} ");
|
|
73
|
-
}
|
|
74
71
|
for (var key in json.properties) {
|
|
75
72
|
var value = json.properties[key];
|
|
76
73
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
77
74
|
}
|
|
78
75
|
for (var key in json.bindings) {
|
|
79
|
-
var
|
|
80
|
-
if (key === '
|
|
76
|
+
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
|
|
77
|
+
if (key === '_forName') {
|
|
81
78
|
continue;
|
|
82
79
|
}
|
|
83
|
-
if (
|
|
80
|
+
if (type === 'spread') {
|
|
81
|
+
str += " ${spread(".concat(code, ")} ");
|
|
82
|
+
}
|
|
83
|
+
else if (key === 'ref') {
|
|
84
84
|
// TODO: maybe use ref directive instead
|
|
85
85
|
// https://lit.dev/docs/templates/directives/#ref
|
|
86
86
|
str += " ref=\"".concat(code, "\" ");
|
|
@@ -160,7 +160,7 @@ var componentToLit = function (options) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
var html = json.children.map(function (item) { return blockToLit(item, options); }).join('\n');
|
|
163
|
-
var hasSpread = (0, has_1.has)(json, function (node) { return
|
|
163
|
+
var hasSpread = (0, has_1.has)(json, function (node) { return (0, lodash_1.some)(node.bindings, { type: 'spread' }); });
|
|
164
164
|
if (options.prettier !== false) {
|
|
165
165
|
try {
|
|
166
166
|
css = (0, standalone_1.format)(css, {
|
|
@@ -48,7 +48,7 @@ function getStatePropertyNames(json) {
|
|
|
48
48
|
return Object.keys(json.state).filter(function (key) { var _a; return ((_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; });
|
|
49
49
|
}
|
|
50
50
|
var blockToMarko = function (json, options) {
|
|
51
|
-
var _a, _b, _c, _d, _e
|
|
51
|
+
var _a, _b, _c, _d, _e;
|
|
52
52
|
if (json.properties._text) {
|
|
53
53
|
return json.properties._text;
|
|
54
54
|
}
|
|
@@ -73,19 +73,19 @@ var blockToMarko = function (json, options) {
|
|
|
73
73
|
}
|
|
74
74
|
var str = '';
|
|
75
75
|
str += "<".concat(json.name, " ");
|
|
76
|
-
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
77
|
-
str += " ...(".concat(json.bindings._spread.code, ") ");
|
|
78
|
-
}
|
|
79
76
|
for (var key in json.properties) {
|
|
80
77
|
var value = json.properties[key];
|
|
81
78
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
82
79
|
}
|
|
83
80
|
for (var key in json.bindings) {
|
|
84
|
-
var
|
|
85
|
-
if (key === '
|
|
81
|
+
var _f = json.bindings[key], code = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g, type = _f.type;
|
|
82
|
+
if (key === '_forName') {
|
|
86
83
|
continue;
|
|
87
84
|
}
|
|
88
|
-
if (
|
|
85
|
+
if (type === 'spread') {
|
|
86
|
+
str += " ...(".concat(code, ") ");
|
|
87
|
+
}
|
|
88
|
+
else if (key === 'ref') {
|
|
89
89
|
str += " key=\"".concat((0, lodash_1.camelCase)(code), "\" ");
|
|
90
90
|
}
|
|
91
91
|
else if (key.startsWith('on')) {
|
|
@@ -100,7 +100,7 @@ var blockToMarko = function (json, options) {
|
|
|
100
100
|
return str + ' />';
|
|
101
101
|
}
|
|
102
102
|
str += '>';
|
|
103
|
-
if ((
|
|
103
|
+
if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
|
|
104
104
|
str += "$!{".concat(processBinding(options.component, json.bindings.innerHTML.code), "}");
|
|
105
105
|
}
|
|
106
106
|
if (json.children) {
|
|
@@ -47,7 +47,7 @@ var isValidAttributeName = function (str) {
|
|
|
47
47
|
return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
|
|
48
48
|
};
|
|
49
49
|
var blockToMitosis = function (json, toMitosisOptions) {
|
|
50
|
-
var _a, _b, _c, _d, _e;
|
|
50
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
51
|
if (toMitosisOptions === void 0) { toMitosisOptions = {}; }
|
|
52
52
|
var options = __assign({ format: exports.DEFAULT_FORMAT }, toMitosisOptions);
|
|
53
53
|
if (options.format === 'react') {
|
|
@@ -70,9 +70,6 @@ var blockToMitosis = function (json, toMitosisOptions) {
|
|
|
70
70
|
}
|
|
71
71
|
var str = '';
|
|
72
72
|
str += "<".concat(json.name, " ");
|
|
73
|
-
if ((_d = json.bindings._spread) === null || _d === void 0 ? void 0 : _d.code) {
|
|
74
|
-
str += " {...(".concat(json.bindings._spread.code, ")} ");
|
|
75
|
-
}
|
|
76
73
|
for (var key in json.properties) {
|
|
77
74
|
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
78
75
|
if (!isValidAttributeName(key)) {
|
|
@@ -83,11 +80,11 @@ var blockToMitosis = function (json, toMitosisOptions) {
|
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
for (var key in json.bindings) {
|
|
86
|
-
var value = (
|
|
87
|
-
if (key === '
|
|
88
|
-
|
|
83
|
+
var value = (_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.code;
|
|
84
|
+
if (((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.type) === 'spread') {
|
|
85
|
+
str += " {...(".concat((_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code, ")} ");
|
|
89
86
|
}
|
|
90
|
-
if (key.startsWith('on')) {
|
|
87
|
+
else if (key.startsWith('on')) {
|
|
91
88
|
str += " ".concat(key, "={event => ").concat(value.replace(/\s*;$/, ''), "} ");
|
|
92
89
|
}
|
|
93
90
|
else {
|
|
@@ -183,7 +183,7 @@ function isSlotProjection(child) {
|
|
|
183
183
|
* @returns
|
|
184
184
|
*/
|
|
185
185
|
function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredicate) {
|
|
186
|
-
var _a;
|
|
186
|
+
var _a, _b;
|
|
187
187
|
var outBindings = {};
|
|
188
188
|
for (var key in bindings) {
|
|
189
189
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
@@ -211,7 +211,7 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredic
|
|
|
211
211
|
file.import(file.qwikModule, 'mutable');
|
|
212
212
|
bindingExpr = "mutable(".concat(bindingExpr, ")");
|
|
213
213
|
}
|
|
214
|
-
outBindings[key] = { code: bindingExpr };
|
|
214
|
+
outBindings[key] = { code: bindingExpr, type: (_b = bindings === null || bindings === void 0 ? void 0 : bindings[key]) === null || _b === void 0 ? void 0 : _b.type };
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
@@ -301,7 +301,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
var _loop_1 = function (rawKey) {
|
|
304
|
-
if (rawKey === '
|
|
304
|
+
if (bindings[rawKey].type === 'spread') {
|
|
305
305
|
if (this_1.isJSX) {
|
|
306
306
|
this_1.emit('{...', bindings[rawKey].code, '}');
|
|
307
307
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TranspilerGenerator } from '../../types/transpiler';
|
|
2
2
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
3
3
|
import { ToReactOptions } from './types';
|
|
4
|
-
export declare const contextPropDrillingKey = "_context";
|
|
5
4
|
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, parentSlots?: any[]) => string;
|
|
6
5
|
export declare const componentToPreact: TranspilerGenerator<ToReactOptions>;
|
|
7
6
|
export declare const componentToReact: TranspilerGenerator<ToReactOptions>;
|
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.componentToReact = exports.componentToPreact = exports.blockToReact =
|
|
21
|
+
exports.componentToReact = exports.componentToPreact = exports.blockToReact = void 0;
|
|
22
22
|
var dedent_1 = __importDefault(require("dedent"));
|
|
23
23
|
var json5_1 = __importDefault(require("json5"));
|
|
24
24
|
var lodash_1 = require("lodash");
|
|
@@ -50,7 +50,6 @@ 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
|
-
exports.contextPropDrillingKey = '_context';
|
|
54
53
|
var openFrag = function (options) { return getFragment('open', options); };
|
|
55
54
|
var closeFrag = function (options) { return getFragment('close', options); };
|
|
56
55
|
function getFragment(type, options) {
|
|
@@ -145,9 +144,6 @@ var blockToReact = function (json, options, parentSlots) {
|
|
|
145
144
|
}
|
|
146
145
|
var str = '';
|
|
147
146
|
str += "<".concat(json.name, " ");
|
|
148
|
-
if ((_b = json.bindings._spread) === null || _b === void 0 ? void 0 : _b.code) {
|
|
149
|
-
str += " {...(".concat((0, helpers_2.processBinding)(json.bindings._spread.code, options), ")} ");
|
|
150
|
-
}
|
|
151
147
|
for (var key in json.properties) {
|
|
152
148
|
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
153
149
|
if (key === 'class') {
|
|
@@ -170,15 +166,15 @@ var blockToReact = function (json, options, parentSlots) {
|
|
|
170
166
|
}
|
|
171
167
|
}
|
|
172
168
|
for (var key in json.bindings) {
|
|
173
|
-
var value = String((
|
|
174
|
-
if (key === '_spread') {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
169
|
+
var value = String((_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code);
|
|
177
170
|
if (key === 'css' && value.trim() === '{}') {
|
|
178
171
|
continue;
|
|
179
172
|
}
|
|
180
173
|
var useBindingValue = (0, helpers_2.processBinding)(value, options);
|
|
181
|
-
if (key.
|
|
174
|
+
if (((_c = json.bindings[key]) === null || _c === void 0 ? void 0 : _c.type) === 'spread') {
|
|
175
|
+
str += " {...(".concat(value, ")} ");
|
|
176
|
+
}
|
|
177
|
+
else if (key.startsWith('on')) {
|
|
182
178
|
var _e = json.bindings[key].arguments, cusArgs = _e === void 0 ? ['event'] : _e;
|
|
183
179
|
str += " ".concat(key, "={(").concat(cusArgs.join(','), ") => ").concat((0, state_2.updateStateSettersInCode)(useBindingValue, options), " } ");
|
|
184
180
|
}
|
|
@@ -252,55 +248,37 @@ var getRefsString = function (json, refs, options) {
|
|
|
252
248
|
}
|
|
253
249
|
return [hasStateArgument, code];
|
|
254
250
|
};
|
|
255
|
-
function
|
|
256
|
-
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
return str;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
for (var key in json.context.set) {
|
|
269
|
-
var _b = json.context.set[key], name_2 = _b.name, ref = _b.ref, value = _b.value;
|
|
270
|
-
if (value) {
|
|
271
|
-
json.children = [
|
|
272
|
-
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: "".concat(name_2, ".Provider"), children: json.children }, (value && {
|
|
273
|
-
bindings: {
|
|
274
|
-
value: {
|
|
275
|
-
code: (0, get_state_object_string_1.stringifyContextValue)(value),
|
|
276
|
-
},
|
|
251
|
+
function addProviderComponents(json, options) {
|
|
252
|
+
for (var key in json.context.set) {
|
|
253
|
+
var _a = json.context.set[key], name_1 = _a.name, ref = _a.ref, value = _a.value;
|
|
254
|
+
if (value) {
|
|
255
|
+
json.children = [
|
|
256
|
+
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: "".concat(name_1, ".Provider"), children: json.children }, (value && {
|
|
257
|
+
bindings: {
|
|
258
|
+
value: {
|
|
259
|
+
code: (0, get_state_object_string_1.stringifyContextValue)(value),
|
|
277
260
|
},
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
261
|
+
},
|
|
262
|
+
}))),
|
|
263
|
+
];
|
|
264
|
+
}
|
|
265
|
+
else if (ref) {
|
|
266
|
+
json.children = [
|
|
267
|
+
(0, create_mitosis_node_1.createMitosisNode)(__assign({ name: 'Context.Provider', children: json.children }, (ref && {
|
|
268
|
+
bindings: {
|
|
269
|
+
value: {
|
|
270
|
+
code: ref,
|
|
288
271
|
},
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
272
|
+
},
|
|
273
|
+
}))),
|
|
274
|
+
];
|
|
292
275
|
}
|
|
293
276
|
}
|
|
294
277
|
}
|
|
295
278
|
function getContextString(component, options) {
|
|
296
279
|
var str = '';
|
|
297
280
|
for (var key in component.context.get) {
|
|
298
|
-
|
|
299
|
-
str += "\n const ".concat(key, " = ").concat(exports.contextPropDrillingKey, "['").concat(component.context.get[key].name, "'];\n ");
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
str += "\n const ".concat(key, " = useContext(").concat(component.context.get[key].name, ");\n ");
|
|
303
|
-
}
|
|
281
|
+
str += "\n const ".concat(key, " = useContext(").concat(component.context.get[key].name, ");\n ");
|
|
304
282
|
}
|
|
305
283
|
return str;
|
|
306
284
|
}
|
|
@@ -363,7 +341,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
363
341
|
(0, process_http_requests_1.processHttpRequests)(json);
|
|
364
342
|
(0, handle_missing_state_1.handleMissingState)(json);
|
|
365
343
|
(0, process_tag_references_1.processTagReferences)(json);
|
|
366
|
-
|
|
344
|
+
addProviderComponents(json, options);
|
|
367
345
|
var componentHasStyles = (0, helpers_1.hasCss)(json);
|
|
368
346
|
if (options.stateType === 'useState') {
|
|
369
347
|
(0, getters_to_functions_1.gettersToFunctions)(json);
|
|
@@ -407,7 +385,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
407
385
|
if (useStateCode && useStateCode.includes('useState')) {
|
|
408
386
|
reactLibImports.add('useState');
|
|
409
387
|
}
|
|
410
|
-
if ((0, context_1.hasContext)(json)
|
|
388
|
+
if ((0, context_1.hasContext)(json)) {
|
|
411
389
|
reactLibImports.add('useContext');
|
|
412
390
|
}
|
|
413
391
|
if (allRefs.length) {
|
|
@@ -428,7 +406,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
428
406
|
var _o = getRefsString(json, allRefs, options), hasStateArgument = _o[0], refsString = _o[1];
|
|
429
407
|
var nativeStyles = stylesType === 'react-native' && componentHasStyles && (0, react_native_1.collectReactNativeStyles)(json);
|
|
430
408
|
var propsArgs = "props: ".concat(json.propsTypeRef || 'any');
|
|
431
|
-
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n
|
|
409
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\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 ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n "])), options.preact
|
|
432
410
|
? "\n /** @jsx h */\n import { h, Fragment } from 'preact';\n "
|
|
433
411
|
: options.type !== 'native'
|
|
434
412
|
? "import * as React from 'react';"
|
|
@@ -441,9 +419,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
441
419
|
: '', json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
442
420
|
component: json,
|
|
443
421
|
target: options.type === 'native' ? 'reactNative' : 'react',
|
|
444
|
-
}), isSubComponent ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '',
|
|
445
|
-
? "const ".concat(exports.contextPropDrillingKey, " = { ...props['").concat(exports.contextPropDrillingKey, "'] };")
|
|
446
|
-
: '', hasStateArgument ? '' : refsString, hasState
|
|
422
|
+
}), isSubComponent ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', hasStateArgument ? '' : refsString, hasState
|
|
447
423
|
? stateType === 'mobx'
|
|
448
424
|
? "const state = useLocalObservable(() => (".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), "));")
|
|
449
425
|
: stateType === 'useState'
|
|
@@ -451,11 +427,9 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
451
427
|
: stateType === 'solid'
|
|
452
428
|
? "const state = useMutable(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
453
429
|
: stateType === 'builder'
|
|
454
|
-
? "
|
|
455
|
-
:
|
|
456
|
-
|
|
457
|
-
: "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
458
|
-
: '', hasStateArgument ? refsString : '', getContextString(json, options), getInitCode(json, options), contextStr || '', ((_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code)
|
|
430
|
+
? "var state = useBuilderState(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
431
|
+
: "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
432
|
+
: '', hasStateArgument ? refsString : '', getContextString(json, options), getInitCode(json, options), ((_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code)
|
|
459
433
|
? "\n useEffect(() => {\n ".concat((0, state_2.processHookCode)({
|
|
460
434
|
str: json.hooks.onInit.code,
|
|
461
435
|
options: options,
|
|
@@ -77,6 +77,7 @@ var updateStateSetters = function (json, options) {
|
|
|
77
77
|
item.bindings[key] = {
|
|
78
78
|
code: newValue,
|
|
79
79
|
arguments: values === null || values === void 0 ? void 0 : values.arguments,
|
|
80
|
+
type: values === null || values === void 0 ? void 0 : values.type,
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
2
2
|
export interface ToReactOptions extends BaseTranspilerOptions {
|
|
3
3
|
stylesType?: 'emotion' | 'styled-components' | 'styled-jsx' | 'react-native' | 'style-tag';
|
|
4
|
-
stateType?: 'useState' | 'mobx' | 'valtio' | 'solid' | 'builder'
|
|
4
|
+
stateType?: 'useState' | 'mobx' | 'valtio' | 'solid' | 'builder';
|
|
5
5
|
format?: 'lite' | 'safe';
|
|
6
6
|
type?: 'dom' | 'native';
|
|
7
7
|
preact?: boolean;
|
|
8
8
|
forwardRef?: string;
|
|
9
9
|
experimental?: any;
|
|
10
|
-
/**
|
|
11
|
-
* For RSC, normal React context is currently not supported, so provide a prop drilling
|
|
12
|
-
* option
|
|
13
|
-
*/
|
|
14
|
-
contextType?: 'context' | 'prop-drill';
|
|
15
10
|
}
|
|
@@ -160,12 +160,13 @@ var preProcessBlockCode = function (_a) {
|
|
|
160
160
|
json.bindings[key] = {
|
|
161
161
|
arguments: value.arguments,
|
|
162
162
|
code: (0, helpers_2.updateStateCode)({ options: options, component: component, updateSetters: true })(value.code),
|
|
163
|
+
type: value === null || value === void 0 ? void 0 : value.type,
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
};
|
|
167
168
|
var blockToSolid = function (_a) {
|
|
168
|
-
var _b, _c
|
|
169
|
+
var _b, _c;
|
|
169
170
|
var json = _a.json, options = _a.options, component = _a.component;
|
|
170
171
|
preProcessBlockCode({ json: json, options: options, component: component });
|
|
171
172
|
if (json.properties._text) {
|
|
@@ -196,21 +197,21 @@ var blockToSolid = function (_a) {
|
|
|
196
197
|
if (classString) {
|
|
197
198
|
str += " class=".concat(classString, " ");
|
|
198
199
|
}
|
|
199
|
-
if ((_d = json.bindings._spread) === null || _d === void 0 ? void 0 : _d.code) {
|
|
200
|
-
str += " {...(".concat(json.bindings._spread.code, ")} ");
|
|
201
|
-
}
|
|
202
200
|
for (var key in json.properties) {
|
|
203
201
|
var value = json.properties[key];
|
|
204
202
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
205
203
|
}
|
|
206
204
|
for (var key in json.bindings) {
|
|
207
|
-
var
|
|
208
|
-
if (key === '
|
|
205
|
+
var _d = json.bindings[key], code = _d.code, _e = _d.arguments, cusArg = _e === void 0 ? ['event'] : _e, type = _d.type;
|
|
206
|
+
if (key === '_forName') {
|
|
209
207
|
continue;
|
|
210
208
|
}
|
|
211
209
|
if (!code)
|
|
212
210
|
continue;
|
|
213
|
-
if (
|
|
211
|
+
if (type === 'spread') {
|
|
212
|
+
str += " {...(".concat(code, ")} ");
|
|
213
|
+
}
|
|
214
|
+
else if (key.startsWith('on')) {
|
|
214
215
|
var useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
215
216
|
str += " ".concat(useKey, "={(").concat(cusArg.join(','), ") => ").concat(code, "} ");
|
|
216
217
|
}
|
|
@@ -27,7 +27,7 @@ var indent_1 = require("../../helpers/indent");
|
|
|
27
27
|
var map_refs_1 = require("../../helpers/map-refs");
|
|
28
28
|
var for_1 = require("../../helpers/nodes/for");
|
|
29
29
|
var blockToStencil = function (json, options) {
|
|
30
|
-
var _a, _b, _c, _d
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
31
|
if (options === void 0) { options = {}; }
|
|
32
32
|
if (json.properties._text) {
|
|
33
33
|
return json.properties._text;
|
|
@@ -56,19 +56,19 @@ var blockToStencil = function (json, options) {
|
|
|
56
56
|
if (classString) {
|
|
57
57
|
str += " class=".concat(classString, " ");
|
|
58
58
|
}
|
|
59
|
-
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
60
|
-
str += " {...(".concat(json.bindings._spread.code, ")} ");
|
|
61
|
-
}
|
|
62
59
|
for (var key in json.properties) {
|
|
63
60
|
var value = json.properties[key];
|
|
64
61
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
65
62
|
}
|
|
66
63
|
for (var key in json.bindings) {
|
|
67
|
-
var
|
|
68
|
-
if (key === '
|
|
64
|
+
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
|
|
65
|
+
if (key === '_forName') {
|
|
69
66
|
continue;
|
|
70
67
|
}
|
|
71
|
-
if (
|
|
68
|
+
if (type === 'spread') {
|
|
69
|
+
str += " {...(".concat(code, ")} ");
|
|
70
|
+
}
|
|
71
|
+
else if (key === 'ref') {
|
|
72
72
|
str += " ref={(el) => this.".concat(code, " = el} ");
|
|
73
73
|
}
|
|
74
74
|
else if (key.startsWith('on')) {
|
|
@@ -173,7 +173,7 @@ var stripStateAndProps = function (code, options) {
|
|
|
173
173
|
});
|
|
174
174
|
};
|
|
175
175
|
var blockToSvelte = function (_a) {
|
|
176
|
-
var _b, _c, _d, _e
|
|
176
|
+
var _b, _c, _d, _e;
|
|
177
177
|
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
178
178
|
if (mappers[json.name]) {
|
|
179
179
|
return mappers[json.name]({
|
|
@@ -199,12 +199,9 @@ var blockToSvelte = function (_a) {
|
|
|
199
199
|
}
|
|
200
200
|
var str = '';
|
|
201
201
|
str += "<".concat(tagName, " ");
|
|
202
|
-
if ((_c = json.bindings._spread) === null || _c === void 0 ? void 0 : _c.code) {
|
|
203
|
-
str += "{...".concat(stripStateAndProps(json.bindings._spread.code, options), "}");
|
|
204
|
-
}
|
|
205
202
|
var isComponent = Boolean(tagName[0] && (0, is_upper_case_1.isUpperCase)(tagName[0]));
|
|
206
|
-
if ((((
|
|
207
|
-
var useValue = stripStateAndProps(((
|
|
203
|
+
if ((((_c = json.bindings.style) === null || _c === void 0 ? void 0 : _c.code) || json.properties.style) && !isComponent) {
|
|
204
|
+
var useValue = stripStateAndProps(((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style, options);
|
|
208
205
|
str += "use:mitosis_styling={".concat(useValue, "}");
|
|
209
206
|
delete json.bindings.style;
|
|
210
207
|
delete json.properties.style;
|
|
@@ -217,13 +214,17 @@ var blockToSvelte = function (_a) {
|
|
|
217
214
|
if (key === 'innerHTML') {
|
|
218
215
|
continue;
|
|
219
216
|
}
|
|
220
|
-
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
var _g = json.bindings[key], value = _g.code, _h = _g.arguments, cusArgs = _h === void 0 ? ['event'] : _h;
|
|
217
|
+
var _f = json.bindings[key], value = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g, type = _f.type;
|
|
224
218
|
// TODO: proper babel transform to replace. Util for this
|
|
225
219
|
var useValue = stripStateAndProps(value, options);
|
|
226
|
-
if (
|
|
220
|
+
if (type === 'spread') {
|
|
221
|
+
str += ' {...';
|
|
222
|
+
if (key === 'props') {
|
|
223
|
+
str += "$$";
|
|
224
|
+
}
|
|
225
|
+
str += "".concat(useValue, "}");
|
|
226
|
+
}
|
|
227
|
+
else if (key.startsWith('on')) {
|
|
227
228
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
228
229
|
// TODO: handle quotes in event handler values
|
|
229
230
|
var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
|
|
@@ -243,7 +244,7 @@ var blockToSvelte = function (_a) {
|
|
|
243
244
|
}
|
|
244
245
|
// if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
|
|
245
246
|
// we use the innerHTML content as children and don't render the self-closing tag.
|
|
246
|
-
if ((
|
|
247
|
+
if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
|
|
247
248
|
str += '>';
|
|
248
249
|
str += BINDINGS_MAPPER.innerHTML(json, options);
|
|
249
250
|
str += "</".concat(tagName, ">");
|
|
@@ -23,7 +23,7 @@ var mappers = {
|
|
|
23
23
|
};
|
|
24
24
|
// TODO: spread support
|
|
25
25
|
var blockToTemplate = function (json, options) {
|
|
26
|
-
var _a, _b, _c, _d;
|
|
26
|
+
var _a, _b, _c, _d, _e;
|
|
27
27
|
if (options === void 0) { options = {}; }
|
|
28
28
|
if (mappers[json.name]) {
|
|
29
29
|
return mappers[json.name](json, options);
|
|
@@ -64,10 +64,10 @@ var blockToTemplate = function (json, options) {
|
|
|
64
64
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
65
65
|
}
|
|
66
66
|
for (var key in json.bindings) {
|
|
67
|
-
if (key === '
|
|
67
|
+
if (((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) === 'spread' || key === 'ref' || key === 'css') {
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
|
-
var value = (
|
|
70
|
+
var value = (_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.code;
|
|
71
71
|
// TODO: proper babel transform to replace. Util for this
|
|
72
72
|
var useValue = value;
|
|
73
73
|
if (key.startsWith('on')) {
|