@builder.io/mitosis 0.3.13 → 0.3.15
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.
|
@@ -332,16 +332,13 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
332
332
|
if ((0, context_1.hasContext)(json) && options.contextType !== 'prop-drill') {
|
|
333
333
|
reactLibImports.add('useContext');
|
|
334
334
|
}
|
|
335
|
-
if (allRefs.length) {
|
|
335
|
+
if (allRefs.length || ((_c = json.hooks.onInit) === null || _c === void 0 ? void 0 : _c.code)) {
|
|
336
336
|
reactLibImports.add('useRef');
|
|
337
337
|
}
|
|
338
338
|
if (!options.preact && hasPropRef) {
|
|
339
339
|
reactLibImports.add('forwardRef');
|
|
340
340
|
}
|
|
341
|
-
if (json.hooks.onMount.length ||
|
|
342
|
-
((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code) ||
|
|
343
|
-
((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length) ||
|
|
344
|
-
((_e = json.hooks.onInit) === null || _e === void 0 ? void 0 : _e.code)) {
|
|
341
|
+
if (json.hooks.onMount.length || ((_d = json.hooks.onUnMount) === null || _d === void 0 ? void 0 : _d.code) || ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)) {
|
|
345
342
|
reactLibImports.add('useEffect');
|
|
346
343
|
}
|
|
347
344
|
var hasCustomStyles = !!((_f = json.style) === null || _f === void 0 ? void 0 : _f.length);
|
|
@@ -388,10 +385,10 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
388
385
|
})
|
|
389
386
|
: "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
390
387
|
: '', hasStateArgument ? refsString : '', getContextString(json, options), ((_g = json.hooks.init) === null || _g === void 0 ? void 0 : _g.code) ? (0, state_2.processHookCode)({ str: (_h = json.hooks.init) === null || _h === void 0 ? void 0 : _h.code, options: options }) : '', contextStr || '', ((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code)
|
|
391
|
-
? "\n
|
|
388
|
+
? "\n const hasInitialized = useRef(false);\n if (!hasInitialized.current) {\n ".concat((0, state_2.processHookCode)({
|
|
392
389
|
str: json.hooks.onInit.code,
|
|
393
390
|
options: options,
|
|
394
|
-
}), "\n }
|
|
391
|
+
}), "\n hasInitialized.current = true;\n }\n ")
|
|
395
392
|
: '', json.hooks.onEvent
|
|
396
393
|
.map(function (hook) {
|
|
397
394
|
var eventName = "\"".concat(hook.eventName, "\"");
|
|
@@ -167,29 +167,44 @@ var TWRNC_STYLES_PLUGIN = function () { return ({
|
|
|
167
167
|
post: function (json) {
|
|
168
168
|
(0, legacy_1.default)(json).forEach(function (node) {
|
|
169
169
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
170
|
-
var
|
|
171
|
-
node.properties.class,
|
|
172
|
-
node.properties.className,
|
|
173
|
-
node.bindings.class,
|
|
174
|
-
node.bindings.className,
|
|
175
|
-
]
|
|
170
|
+
var staticClasses = [node.properties.class, node.properties.className]
|
|
176
171
|
.filter(Boolean)
|
|
177
172
|
.join(' ');
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
173
|
+
var dynamicClasses = [node.bindings.class, node.bindings.className].filter(Boolean);
|
|
174
|
+
if (staticClasses || dynamicClasses.length) {
|
|
175
|
+
var styleCode = '';
|
|
176
|
+
if (staticClasses) {
|
|
177
|
+
styleCode = "tw`".concat(staticClasses, "`");
|
|
178
|
+
}
|
|
179
|
+
if (dynamicClasses.length) {
|
|
180
|
+
var dynamicCode = dynamicClasses
|
|
181
|
+
.map(function (dc) { return (dc && dc.code ? dc.code : null); })
|
|
182
|
+
.filter(Boolean)
|
|
183
|
+
.join(', ');
|
|
184
|
+
if (dynamicCode) {
|
|
185
|
+
if (styleCode) {
|
|
186
|
+
// If we have both static and dynamic classes
|
|
187
|
+
styleCode = "tw.style(".concat(styleCode, ", ").concat(dynamicCode, ")");
|
|
188
|
+
}
|
|
189
|
+
else if (dynamicClasses.length > 1) {
|
|
190
|
+
// If we have multiple dynamic classes
|
|
191
|
+
styleCode = "tw.style([".concat(dynamicCode, "])");
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
// If we have a single dynamic class
|
|
195
|
+
styleCode = "tw.style(".concat(dynamicCode, ")");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (styleCode) {
|
|
200
|
+
node.bindings.style = (0, bindings_1.createSingleBinding)({ code: styleCode });
|
|
201
|
+
}
|
|
192
202
|
}
|
|
203
|
+
// Clean up original class and className properties/bindings
|
|
204
|
+
delete node.properties.class;
|
|
205
|
+
delete node.properties.className;
|
|
206
|
+
delete node.bindings.class;
|
|
207
|
+
delete node.bindings.className;
|
|
193
208
|
}
|
|
194
209
|
});
|
|
195
210
|
},
|
|
@@ -132,7 +132,7 @@ var DEFAULT_OPTIONS = {
|
|
|
132
132
|
};
|
|
133
133
|
var componentToSolid = function (passedOptions) {
|
|
134
134
|
return function (_a) {
|
|
135
|
-
var _b, _c, _d, _e, _f;
|
|
135
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
136
136
|
var component = _a.component;
|
|
137
137
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
138
138
|
var options = (0, merge_options_1.initializeOptions)({
|
|
@@ -193,13 +193,13 @@ var componentToSolid = function (passedOptions) {
|
|
|
193
193
|
var storeImports = (_e = state === null || state === void 0 ? void 0 : state.import.store) !== null && _e !== void 0 ? _e : [];
|
|
194
194
|
var propType = json.propsTypeRef || 'any';
|
|
195
195
|
var propsArgs = "props".concat(options.typescript ? ":".concat(propType) : '');
|
|
196
|
-
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), solidJSImports.length > 0 ? "import { ".concat(solidJSImports.join(', '), " } from 'solid-js';") : '', !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", storeImports.length > 0 ? "import { ".concat(storeImports.join(', '), " } from 'solid-js/store';") : '', componentHasStyles && options.stylesType === 'styled-components'
|
|
196
|
+
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), solidJSImports.length > 0 ? "import { ".concat(solidJSImports.join(', '), " } from 'solid-js';") : '', !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", storeImports.length > 0 ? "import { ".concat(storeImports.join(', '), " } from 'solid-js/store';") : '', componentHasStyles && options.stylesType === 'styled-components'
|
|
197
197
|
? 'import { css } from "solid-styled-components";'
|
|
198
198
|
: "", json.types && options.typescript ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
199
199
|
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
200
200
|
component: json,
|
|
201
201
|
target: 'solid',
|
|
202
|
-
}), json.name, propsArgs, (_f = state === null || state === void 0 ? void 0 : state.str) !== null && _f !== void 0 ? _f : '', getRefsString(json, options), getContextString(json, options), json.hooks.onMount.map(function (hook) { return "onMount(() => { ".concat(hook.code, " })"); }).join('\n'), json.hooks.onUpdate
|
|
202
|
+
}), json.name, propsArgs, (_f = state === null || state === void 0 ? void 0 : state.str) !== null && _f !== void 0 ? _f : '', getRefsString(json, options), getContextString(json, options), (_h = (_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code) !== null && _h !== void 0 ? _h : '', json.hooks.onMount.map(function (hook) { return "onMount(() => { ".concat(hook.code, " })"); }).join('\n'), json.hooks.onUpdate
|
|
203
203
|
? json.hooks.onUpdate
|
|
204
204
|
.map(function (hook, index) {
|
|
205
205
|
// TO-DO: support `onUpdate` without `deps`
|