@builder.io/mitosis 0.5.2 → 0.5.4
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.
|
@@ -121,7 +121,7 @@ const componentToLit = (_options = {}) => ({ component }) => {
|
|
|
121
121
|
const props = (0, get_props_1.getProps)(component);
|
|
122
122
|
let css = (0, collect_css_1.collectCss)(json);
|
|
123
123
|
const domRefs = (0, get_refs_1.getRefs)(json);
|
|
124
|
-
(0, map_refs_1.mapRefs)(
|
|
124
|
+
(0, map_refs_1.mapRefs)(json, (refName) => `this.${(0, lodash_1.camelCase)(refName)}`);
|
|
125
125
|
if (options.plugins) {
|
|
126
126
|
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
127
127
|
}
|
|
@@ -250,20 +250,23 @@ const getPropsDefinition = ({ json }) => {
|
|
|
250
250
|
.join(',');
|
|
251
251
|
return `${json.name}.defaultProps = {${defaultPropsString}};`;
|
|
252
252
|
};
|
|
253
|
-
const
|
|
253
|
+
const isRSC = (json, options) => {
|
|
254
254
|
var _a, _b;
|
|
255
|
+
// When using RSC generator, we check `componentType` field in metadata to determine if it's a server component
|
|
256
|
+
const componentType = (_b = (_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.rsc) === null || _b === void 0 ? void 0 : _b.componentType;
|
|
257
|
+
if (options.rsc && (0, nullable_1.checkIsDefined)(componentType)) {
|
|
258
|
+
return componentType === 'server';
|
|
259
|
+
}
|
|
260
|
+
return !(0, rsc_1.checkIfIsClientComponent)(json);
|
|
261
|
+
};
|
|
262
|
+
const checkShouldAddUseClientDirective = (json, options) => {
|
|
255
263
|
if (!options.addUseClientDirectiveIfNeeded)
|
|
256
264
|
return false;
|
|
257
265
|
if (options.type === 'native')
|
|
258
266
|
return false;
|
|
259
267
|
if (options.preact)
|
|
260
268
|
return false;
|
|
261
|
-
|
|
262
|
-
const componentType = (_b = (_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.rsc) === null || _b === void 0 ? void 0 : _b.componentType;
|
|
263
|
-
if (options.rsc && (0, nullable_1.checkIsDefined)(componentType)) {
|
|
264
|
-
return componentType === 'client';
|
|
265
|
-
}
|
|
266
|
-
return (0, rsc_1.checkIfIsClientComponent)(json);
|
|
269
|
+
return !isRSC(json, options);
|
|
267
270
|
};
|
|
268
271
|
const _componentToReact = (json, options, isSubComponent = false) => {
|
|
269
272
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
@@ -320,7 +323,9 @@ const _componentToReact = (json, options, isSubComponent = false) => {
|
|
|
320
323
|
if ((0, context_1.hasContext)(json) && options.contextType !== 'prop-drill') {
|
|
321
324
|
reactLibImports.add('useContext');
|
|
322
325
|
}
|
|
323
|
-
|
|
326
|
+
const shouldAddUseClientDirective = checkShouldAddUseClientDirective(json, options);
|
|
327
|
+
const shouldInlineOnInitHook = !shouldAddUseClientDirective && options.rsc && isRSC(json, options);
|
|
328
|
+
if (allRefs.length || (((_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code) && !shouldInlineOnInitHook)) {
|
|
324
329
|
reactLibImports.add('useRef');
|
|
325
330
|
}
|
|
326
331
|
if (!options.preact && hasPropRef) {
|
|
@@ -382,13 +387,15 @@ const _componentToReact = (json, options, isSubComponent = false) => {
|
|
|
382
387
|
${contextStr || ''}
|
|
383
388
|
|
|
384
389
|
${((_o = json.hooks.onInit) === null || _o === void 0 ? void 0 : _o.code)
|
|
385
|
-
?
|
|
390
|
+
? shouldInlineOnInitHook
|
|
391
|
+
? (0, state_2.processHookCode)({ str: json.hooks.onInit.code, options })
|
|
392
|
+
: `
|
|
386
393
|
const hasInitialized = useRef(false);
|
|
387
394
|
if (!hasInitialized.current) {
|
|
388
395
|
${(0, state_2.processHookCode)({
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
396
|
+
str: json.hooks.onInit.code,
|
|
397
|
+
options,
|
|
398
|
+
})}
|
|
392
399
|
hasInitialized.current = true;
|
|
393
400
|
}
|
|
394
401
|
`
|
|
@@ -445,7 +452,6 @@ const _componentToReact = (json, options, isSubComponent = false) => {
|
|
|
445
452
|
${wrap ? (0, helpers_2.closeFrag)(options) : ''}
|
|
446
453
|
);
|
|
447
454
|
`;
|
|
448
|
-
const shouldAddUseClientDirective = checkShouldAddUseClientDirective(json, options);
|
|
449
455
|
const str = (0, dedent_1.dedent) `
|
|
450
456
|
${shouldAddUseClientDirective ? `'use client';` : ''}
|
|
451
457
|
${getDefaultImport(json, options)}
|