@builder.io/mitosis 0.3.17 → 0.3.19

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.
@@ -576,7 +576,9 @@ var classPropertiesPlugin = function () { return ({
576
576
  // if any state "property" is trying to access state.* or props.*
577
577
  // then we need to move them to onInit where they can be accessed
578
578
  var transformState = function (json) {
579
- Object.entries(json.state).forEach(function (_a) {
579
+ Object.entries(json.state)
580
+ .reverse()
581
+ .forEach(function (_a) {
580
582
  var _b;
581
583
  var key = _a[0], value = _a[1];
582
584
  if ((value === null || value === void 0 ? void 0 : value.type) === 'property') {
@@ -586,7 +588,7 @@ var transformState = function (json) {
586
588
  if (!((_b = json.hooks.onInit) === null || _b === void 0 ? void 0 : _b.code)) {
587
589
  json.hooks.onInit = { code: '' };
588
590
  }
589
- json.hooks.onInit.code += "\nthis.".concat(key, " = ").concat(code, ";\n");
591
+ json.hooks.onInit.code = "\nthis.".concat(key, " = ").concat(code, ";\n").concat(json.hooks.onInit.code);
590
592
  }
591
593
  }
592
594
  });
@@ -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, '&quot;').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
  }
@@ -10,7 +10,7 @@ var lodash_1 = require("lodash");
10
10
  var html_tags_1 = require("../../constants/html_tags");
11
11
  var styles_1 = require("./helpers/styles");
12
12
  var ATTTRIBUTE_MAPPERS = {
13
- for: 'htmlFor',
13
+ // for: 'htmlFor',
14
14
  };
15
15
  var transformAttributeName = function (name) {
16
16
  if ((0, typescript_1.objectHasKey)(ATTTRIBUTE_MAPPERS, name))
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.3.17",
25
+ "version": "0.3.19",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {