@builder.io/mitosis 0.3.17 → 0.3.18
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.
|
@@ -144,6 +144,7 @@ var NATIVE_EVENT_MAPPER = {
|
|
|
144
144
|
var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
145
145
|
var _a, _b, _c, _d;
|
|
146
146
|
if (parentSlots === void 0) { parentSlots = []; }
|
|
147
|
+
var needsToRenderSlots = [];
|
|
147
148
|
if (NODE_MAPPERS[json.name]) {
|
|
148
149
|
return NODE_MAPPERS[json.name](json, options, component, insideJsx, parentSlots);
|
|
149
150
|
}
|
|
@@ -167,6 +168,31 @@ var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
|
167
168
|
str += "<".concat(json.name, " ");
|
|
168
169
|
for (var key in json.properties) {
|
|
169
170
|
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
171
|
+
// Handle src for Image
|
|
172
|
+
// Handle src for Image
|
|
173
|
+
if (json.name === 'Image' && key === 'src') {
|
|
174
|
+
var src = void 0;
|
|
175
|
+
var imageSource = json.properties.src;
|
|
176
|
+
if (imageSource) {
|
|
177
|
+
var isUrl = /^(http|https):\/\/[^ "]+$/.test(imageSource);
|
|
178
|
+
src = isUrl ? "{ uri: '".concat(imageSource, "' }") : "require('".concat(imageSource, "')");
|
|
179
|
+
str += "source={".concat(src, "} ");
|
|
180
|
+
continue; // Skip further processing for 'src' in Image
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Handle href for TouchableOpacity
|
|
184
|
+
if (json.name === 'TouchableOpacity' && key === 'href') {
|
|
185
|
+
var hrefValue = (0, helpers_1.processBinding)(value, options);
|
|
186
|
+
if (hrefValue) {
|
|
187
|
+
var onPress = "() => Linking.openURL(".concat(JSON.stringify(hrefValue), ")");
|
|
188
|
+
str += " onPress={".concat(onPress, "} ");
|
|
189
|
+
}
|
|
190
|
+
continue; // Skip further processing for 'href' in TouchableOpacity
|
|
191
|
+
}
|
|
192
|
+
// Ignore target for TouchableOpacity
|
|
193
|
+
if (json.name === 'TouchableOpacity' && key === 'target') {
|
|
194
|
+
continue; // Skip further processing for 'target' in TouchableOpacity
|
|
195
|
+
}
|
|
170
196
|
if (key === 'class') {
|
|
171
197
|
str = "".concat(str.trim(), " className=\"").concat(value, "\" ");
|
|
172
198
|
}
|
|
@@ -196,6 +222,28 @@ var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
|
196
222
|
continue;
|
|
197
223
|
}
|
|
198
224
|
var useBindingValue = (0, helpers_1.processBinding)(value, options);
|
|
225
|
+
if (json.name === 'Image' && key === 'src') {
|
|
226
|
+
var src = void 0;
|
|
227
|
+
var imageSource = (0, helpers_1.processBinding)(value, options);
|
|
228
|
+
if (imageSource) {
|
|
229
|
+
src = "{ uri: ".concat(imageSource, " }");
|
|
230
|
+
str += "source={".concat(src, "} ");
|
|
231
|
+
continue; // Skip further processing for 'src' in Image
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Handle href for TouchableOpacity
|
|
235
|
+
if (json.name === 'TouchableOpacity' && key === 'href') {
|
|
236
|
+
var hrefValue = (0, helpers_1.processBinding)(value, options);
|
|
237
|
+
if (hrefValue) {
|
|
238
|
+
var onPress = "() => Linking.openURL(".concat(hrefValue, ")");
|
|
239
|
+
str += " onPress={".concat(onPress, "} ");
|
|
240
|
+
continue; // Skip further processing for 'href' in TouchableOpacity
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Ignore target for TouchableOpacity
|
|
244
|
+
if (json.name === 'TouchableOpacity' && key === 'target') {
|
|
245
|
+
continue; // Skip further processing for 'target' in TouchableOpacity
|
|
246
|
+
}
|
|
199
247
|
if (((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) === 'spread') {
|
|
200
248
|
str += " {...(".concat(value, ")} ");
|
|
201
249
|
}
|
|
@@ -261,7 +309,6 @@ var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
|
261
309
|
return str;
|
|
262
310
|
}
|
|
263
311
|
// TODO: update MitosisNode for simple code
|
|
264
|
-
var needsToRenderSlots = [];
|
|
265
312
|
var childrenNodes = '';
|
|
266
313
|
if (json.children) {
|
|
267
314
|
childrenNodes = json.children
|
|
@@ -241,7 +241,7 @@ var getDefaultImport = function (json, options) {
|
|
|
241
241
|
return "\n /** @jsx h */\n import { h, Fragment } from 'preact';\n ";
|
|
242
242
|
}
|
|
243
243
|
if (type === 'native') {
|
|
244
|
-
return "\n import * as React from 'react';\n import { FlatList, ScrollView, View, StyleSheet, Image, Text, Pressable, TextInput } from 'react-native';\n ";
|
|
244
|
+
return "\n import * as React from 'react';\n import { FlatList, ScrollView, View, StyleSheet, Image, Text, Pressable, TextInput, TouchableOpacity, Button, Linking, Pressable } from 'react-native';\n ";
|
|
245
245
|
}
|
|
246
246
|
if (type === 'taro') {
|
|
247
247
|
return "\n import * as React from 'react';\n ";
|
|
@@ -118,6 +118,16 @@ var PROCESS_REACT_NATIVE_PLUGIN = function () { return ({
|
|
|
118
118
|
if (node.name === 'input') {
|
|
119
119
|
node.name = 'TextInput';
|
|
120
120
|
}
|
|
121
|
+
else if (node.name === 'img') {
|
|
122
|
+
node.name = 'Image';
|
|
123
|
+
}
|
|
124
|
+
else if (node.name === 'a') {
|
|
125
|
+
node.name = 'TouchableOpacity';
|
|
126
|
+
}
|
|
127
|
+
else if (node.name === 'button') {
|
|
128
|
+
node.name = 'Button';
|
|
129
|
+
}
|
|
130
|
+
// if node is not button or a and still has onClick it needs to pressable
|
|
121
131
|
else if (node.bindings.onClick) {
|
|
122
132
|
node.name = 'Pressable';
|
|
123
133
|
}
|