@builder.io/mitosis 0.0.115-0 → 0.0.115-2
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/alpine/generate.js +4 -4
- package/dist/src/generators/angular.js +4 -4
- package/dist/src/generators/html.js +8 -8
- package/dist/src/generators/liquid.js +4 -4
- package/dist/src/generators/lit/generate.js +4 -4
- package/dist/src/generators/marko/generate.js +4 -4
- package/dist/src/generators/qwik/component-generator.js +18 -7
- package/dist/src/generators/react/generator.js +53 -10
- package/dist/src/generators/rsc.js +31 -25
- package/dist/src/generators/solid/index.js +4 -4
- package/dist/src/generators/stencil/generate.js +4 -4
- package/dist/src/generators/svelte/svelte.js +4 -4
- package/dist/src/generators/template.js +4 -4
- package/dist/src/generators/vue/vue.js +9 -4
- package/dist/src/helpers/get-state-object-string.d.ts +1 -1
- package/dist/src/helpers/get-state-object-string.js +3 -3
- package/dist/src/helpers/render-imports.js +1 -1
- package/dist/src/helpers/replace-identifiers.d.ts +1 -0
- package/dist/src/helpers/replace-identifiers.js +7 -7
- package/dist/src/modules/plugins.d.ts +22 -4
- package/dist/src/modules/plugins.js +18 -14
- package/dist/src/parsers/jsx/hooks/use-target.js +0 -2
- package/dist/src/types/metadata.d.ts +4 -0
- package/dist/src/types/plugins.d.ts +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -166,12 +166,12 @@ var componentToAlpine = function (_options) {
|
|
|
166
166
|
var options = (0, merge_options_1.initializeOptions)({ target: 'alpine', component: component, defaults: _options });
|
|
167
167
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
168
168
|
if (options.plugins) {
|
|
169
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
169
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
170
170
|
}
|
|
171
171
|
var css = (0, collect_css_1.collectCss)(json);
|
|
172
172
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
173
173
|
if (options.plugins) {
|
|
174
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
174
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
175
175
|
}
|
|
176
176
|
var componentName = (0, lodash_1.camelCase)(json.name) || 'MyComponent';
|
|
177
177
|
var stateObjectString = getStateObjectString(json);
|
|
@@ -188,7 +188,7 @@ var componentToAlpine = function (_options) {
|
|
|
188
188
|
str += "<script>\n ".concat((0, babel_transform_1.babelTransformCode)("document.addEventListener('alpine:init', () => {\n Alpine.data('".concat(componentName, "', () => (").concat(stateObjectString, "))\n })")), "\n </script>");
|
|
189
189
|
}
|
|
190
190
|
if (options.plugins) {
|
|
191
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
191
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
192
192
|
}
|
|
193
193
|
if (options.prettier !== false) {
|
|
194
194
|
try {
|
|
@@ -208,7 +208,7 @@ var componentToAlpine = function (_options) {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
if (options.plugins) {
|
|
211
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
211
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
212
212
|
}
|
|
213
213
|
return str;
|
|
214
214
|
};
|
|
@@ -281,7 +281,7 @@ var componentToAngular = function (userOptions) {
|
|
|
281
281
|
}),
|
|
282
282
|
], false);
|
|
283
283
|
if (options.plugins) {
|
|
284
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
284
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
285
285
|
}
|
|
286
286
|
var _o = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _o[0], hasPropRef = _o[1];
|
|
287
287
|
var childComponents = [];
|
|
@@ -339,7 +339,7 @@ var componentToAngular = function (userOptions) {
|
|
|
339
339
|
return "this.".concat(isDomRef ? '' : '_').concat(refName).concat(isDomRef ? '.nativeElement' : '');
|
|
340
340
|
});
|
|
341
341
|
if (options.plugins) {
|
|
342
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
342
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
343
343
|
}
|
|
344
344
|
var css = (0, collect_css_1.collectCss)(json);
|
|
345
345
|
if (options.prettier !== false) {
|
|
@@ -452,13 +452,13 @@ var componentToAngular = function (userOptions) {
|
|
|
452
452
|
str = generateNgModule(str, json.name, componentsUsed, json, options.bootstrapMapper);
|
|
453
453
|
}
|
|
454
454
|
if (options.plugins) {
|
|
455
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
455
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
456
456
|
}
|
|
457
457
|
if (options.prettier !== false) {
|
|
458
458
|
str = tryFormat(str, 'typescript');
|
|
459
459
|
}
|
|
460
460
|
if (options.plugins) {
|
|
461
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
461
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
462
462
|
}
|
|
463
463
|
return str;
|
|
464
464
|
};
|
|
@@ -426,7 +426,7 @@ var componentToHtml = function (_options) {
|
|
|
426
426
|
});
|
|
427
427
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
428
428
|
if (options.plugins) {
|
|
429
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
429
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
430
430
|
}
|
|
431
431
|
addUpdateAfterSet(json, options);
|
|
432
432
|
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
@@ -434,7 +434,7 @@ var componentToHtml = function (_options) {
|
|
|
434
434
|
var hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
435
435
|
var hasTextBinding = (0, has_bindings_text_1.hasBindingsText)(json);
|
|
436
436
|
if (options.plugins) {
|
|
437
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
437
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
438
438
|
}
|
|
439
439
|
var css = (0, collect_css_1.collectCss)(json, {
|
|
440
440
|
prefix: options.prefix,
|
|
@@ -480,7 +480,7 @@ var componentToHtml = function (_options) {
|
|
|
480
480
|
: "\n // Helper to render loops\n function renderLoop(template, array, itemName, itemIndex, collectionName) {\n const collection = [];\n for (let [index, value] of array.entries()) {\n const elementFragment = template.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n const localScope = {};\n let scope = localScope;\n if (template?.scope) {\n const getParent = {\n get(target, prop, receiver) {\n if (prop in target) {\n return target[prop];\n }\n if (prop in template.scope) {\n return template.scope[prop];\n }\n return target[prop];\n }\n };\n scope = new Proxy(localScope, getParent);\n }\n children.forEach((child) => {\n if (itemName !== undefined) {\n scope[itemName] = value;\n }\n if (itemIndex !== undefined) {\n scope[itemIndex] = index;\n }\n if (collectionName !== undefined) {\n scope[collectionName] = array;\n }\n child.scope = scope;\n if (template.context) {\n child.context = template.context;\n }\n this.nodesToDestroy.push(child);\n collection.unshift(child);\n });\n collection.forEach(child => template.after(child));\n }\n }\n\n function getScope(el, name) {\n do {\n let value = el?.scope?.[name]\n if (value !== undefined) {\n return value\n }\n } while ((el = el.parentNode));\n }\n ", "\n })()\n </script>\n ");
|
|
481
481
|
}
|
|
482
482
|
if (options.plugins) {
|
|
483
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
483
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
484
484
|
}
|
|
485
485
|
if (options.prettier !== false) {
|
|
486
486
|
try {
|
|
@@ -500,7 +500,7 @@ var componentToHtml = function (_options) {
|
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
if (options.plugins) {
|
|
503
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
503
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
504
504
|
}
|
|
505
505
|
return str;
|
|
506
506
|
};
|
|
@@ -521,7 +521,7 @@ var componentToCustomElement = function (_options) {
|
|
|
521
521
|
});
|
|
522
522
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
523
523
|
if (options.plugins) {
|
|
524
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
524
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
525
525
|
}
|
|
526
526
|
var _15 = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _15[0], hasPropRef = _15[1];
|
|
527
527
|
var contextVars = Object.keys(((_b = json === null || json === void 0 ? void 0 : json.context) === null || _b === void 0 ? void 0 : _b.get) || {});
|
|
@@ -556,7 +556,7 @@ var componentToCustomElement = function (_options) {
|
|
|
556
556
|
var hasScope = hasLoop;
|
|
557
557
|
var hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
558
558
|
if (options.plugins) {
|
|
559
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
559
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
560
560
|
}
|
|
561
561
|
var css = '';
|
|
562
562
|
if ((_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.css) {
|
|
@@ -740,7 +740,7 @@ var componentToCustomElement = function (_options) {
|
|
|
740
740
|
? (_14 = options === null || options === void 0 ? void 0 : options.experimental) === null || _14 === void 0 ? void 0 : _14.customElementsDefine(kebabName, component, options)
|
|
741
741
|
: "customElements.define('".concat(kebabName, "', ").concat(ComponentName, ");"), "\n ");
|
|
742
742
|
if (options.plugins) {
|
|
743
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
743
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
744
744
|
}
|
|
745
745
|
if (options.prettier !== false) {
|
|
746
746
|
try {
|
|
@@ -760,7 +760,7 @@ var componentToCustomElement = function (_options) {
|
|
|
760
760
|
}
|
|
761
761
|
}
|
|
762
762
|
if (options.plugins) {
|
|
763
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
763
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
764
764
|
}
|
|
765
765
|
return str;
|
|
766
766
|
};
|
|
@@ -112,12 +112,12 @@ var componentToLiquid = function (options) {
|
|
|
112
112
|
var component = _a.component;
|
|
113
113
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
114
114
|
if (options.plugins) {
|
|
115
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
115
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
116
116
|
}
|
|
117
117
|
var css = (0, collect_css_1.collectCss)(json);
|
|
118
118
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
119
119
|
if (options.plugins) {
|
|
120
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
120
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
121
121
|
}
|
|
122
122
|
var str = json.children.map(function (item) { return blockToLiquid(item); }).join('\n');
|
|
123
123
|
if (css.trim().length) {
|
|
@@ -130,7 +130,7 @@ var componentToLiquid = function (options) {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
if (options.plugins) {
|
|
133
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
133
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
134
134
|
}
|
|
135
135
|
if (options.prettier !== false) {
|
|
136
136
|
try {
|
|
@@ -150,7 +150,7 @@ var componentToLiquid = function (options) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
if (options.plugins) {
|
|
153
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
153
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
154
154
|
}
|
|
155
155
|
return str;
|
|
156
156
|
};
|
|
@@ -119,14 +119,14 @@ var componentToLit = function (_options) {
|
|
|
119
119
|
var options = (0, merge_options_1.initializeOptions)({ target: 'lit', component: component, defaults: _options });
|
|
120
120
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
121
121
|
if (options.plugins) {
|
|
122
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
122
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
123
123
|
}
|
|
124
124
|
var props = (0, get_props_1.getProps)(component);
|
|
125
125
|
var css = (0, collect_css_1.collectCss)(json);
|
|
126
126
|
var domRefs = (0, get_refs_1.getRefs)(json);
|
|
127
127
|
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.".concat((0, lodash_1.camelCase)(refName)); });
|
|
128
128
|
if (options.plugins) {
|
|
129
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
129
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
130
130
|
}
|
|
131
131
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
132
132
|
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
@@ -197,7 +197,7 @@ var componentToLit = function (_options) {
|
|
|
197
197
|
? ''
|
|
198
198
|
: "updated() { \n ".concat(json.hooks.onUpdate.map(function (hook) { return processBinding(hook.code); }).join('\n\n'), " \n }"), options.useShadowDom || !css.length ? '' : "<style>".concat(css, "</style>"), (0, indent_1.indent)(html, 8));
|
|
199
199
|
if (options.plugins) {
|
|
200
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
200
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
201
201
|
}
|
|
202
202
|
if (options.prettier !== false) {
|
|
203
203
|
try {
|
|
@@ -211,7 +211,7 @@ var componentToLit = function (_options) {
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
if (options.plugins) {
|
|
214
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
214
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
215
215
|
}
|
|
216
216
|
return str;
|
|
217
217
|
};
|
|
@@ -143,7 +143,7 @@ var componentToMarko = function (userOptions) {
|
|
|
143
143
|
defaults: __assign(__assign({}, userOptions), { component: json }),
|
|
144
144
|
});
|
|
145
145
|
if (options.plugins) {
|
|
146
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
146
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
147
147
|
}
|
|
148
148
|
var css = (0, collect_css_1.collectCss)(json, {
|
|
149
149
|
prefix: (0, hash_sum_1.default)(json),
|
|
@@ -151,7 +151,7 @@ var componentToMarko = function (userOptions) {
|
|
|
151
151
|
var domRefs = (0, get_refs_1.getRefs)(json);
|
|
152
152
|
(0, map_refs_1.mapRefs)(json, function (refName) { return "this.".concat((0, lodash_1.camelCase)(refName)); });
|
|
153
153
|
if (options.plugins) {
|
|
154
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
154
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
155
155
|
}
|
|
156
156
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
157
157
|
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
@@ -224,7 +224,7 @@ var componentToMarko = function (userOptions) {
|
|
|
224
224
|
.replace(/\n{3,}/g, '\n\n')
|
|
225
225
|
.trim();
|
|
226
226
|
if (options.plugins) {
|
|
227
|
-
finalStr = (0, plugins_1.runPreCodePlugins)(finalStr, options.plugins);
|
|
227
|
+
finalStr = (0, plugins_1.runPreCodePlugins)({ json: json, code: finalStr, plugins: options.plugins });
|
|
228
228
|
}
|
|
229
229
|
if (USE_MARKO_PRETTIER && options.prettier !== false) {
|
|
230
230
|
// Commented out for now as there are strange module import issues as
|
|
@@ -235,7 +235,7 @@ var componentToMarko = function (userOptions) {
|
|
|
235
235
|
// });
|
|
236
236
|
}
|
|
237
237
|
if (options.plugins) {
|
|
238
|
-
finalStr = (0, plugins_1.runPostCodePlugins)(finalStr, options.plugins);
|
|
238
|
+
finalStr = (0, plugins_1.runPostCodePlugins)({ json: json, code: finalStr, plugins: options.plugins });
|
|
239
239
|
}
|
|
240
240
|
return finalStr;
|
|
241
241
|
};
|
|
@@ -83,8 +83,8 @@ var componentToQwik = function (userOptions) {
|
|
|
83
83
|
defaults: DEFAULT_OPTIONS,
|
|
84
84
|
userOptions: userOptions,
|
|
85
85
|
});
|
|
86
|
-
component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
|
|
87
|
-
component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
|
|
86
|
+
component = (0, plugins_1.runPreJsonPlugins)({ json: component, plugins: options.plugins });
|
|
87
|
+
component = (0, plugins_1.runPostJsonPlugins)({ json: component, plugins: options.plugins });
|
|
88
88
|
var isTypeScript = !!options.typescript;
|
|
89
89
|
var file = new src_generator_1.File(component.name + (isTypeScript ? '.ts' : '.js'), {
|
|
90
90
|
isPretty: true,
|
|
@@ -105,15 +105,18 @@ var componentToQwik = function (userOptions) {
|
|
|
105
105
|
var state_3 = (0, state_2.emitStateMethodsAndRewriteBindings)(file, component, metadata_1);
|
|
106
106
|
var hasState_1 = (0, state_1.checkHasState)(component);
|
|
107
107
|
var css_1 = null;
|
|
108
|
+
var emitStore_1 = function () { var _a; return hasState_1 && (0, state_2.emitUseStore)({ file: file, stateInit: state_3, isDeep: (_a = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _a === void 0 ? void 0 : _a.hasDeepStore }); };
|
|
108
109
|
var componentFn = (0, src_generator_1.arrowFnBlock)(['props'], [
|
|
109
110
|
function () {
|
|
110
|
-
var _a;
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if ((_a = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _a === void 0 ? void 0 : _a.setUseStoreFirst)
|
|
113
|
+
emitStore_1();
|
|
111
114
|
css_1 = emitUseStyles(file, component);
|
|
112
115
|
emitUseComputed(file, component);
|
|
113
116
|
emitUseContext(file, component);
|
|
114
117
|
emitUseRef(file, component);
|
|
115
|
-
|
|
116
|
-
(
|
|
118
|
+
if (!((_b = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _b === void 0 ? void 0 : _b.setUseStoreFirst))
|
|
119
|
+
emitStore_1();
|
|
117
120
|
emitUseContextProvider(file, component);
|
|
118
121
|
emitUseClientEffect(file, component);
|
|
119
122
|
emitUseMount(file, component);
|
|
@@ -128,8 +131,16 @@ var componentToQwik = function (userOptions) {
|
|
|
128
131
|
emitStyles(file, css_1);
|
|
129
132
|
DEBUG && file.exportConst('COMPONENT', JSON.stringify(component));
|
|
130
133
|
var sourceFile = file.toString();
|
|
131
|
-
sourceFile = (0, plugins_1.runPreCodePlugins)(
|
|
132
|
-
|
|
134
|
+
sourceFile = (0, plugins_1.runPreCodePlugins)({
|
|
135
|
+
json: component,
|
|
136
|
+
code: sourceFile,
|
|
137
|
+
plugins: options.plugins,
|
|
138
|
+
});
|
|
139
|
+
sourceFile = (0, plugins_1.runPostCodePlugins)({
|
|
140
|
+
json: component,
|
|
141
|
+
code: sourceFile,
|
|
142
|
+
plugins: options.plugins,
|
|
143
|
+
});
|
|
133
144
|
return sourceFile;
|
|
134
145
|
}
|
|
135
146
|
catch (e) {
|
|
@@ -19,6 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.componentToReact = exports.componentToPreact = exports.contextPropDrillingKey = void 0;
|
|
22
|
+
var core_1 = require("@babel/core");
|
|
22
23
|
var hash_sum_1 = __importDefault(require("hash-sum"));
|
|
23
24
|
var json5_1 = __importDefault(require("json5"));
|
|
24
25
|
var standalone_1 = require("prettier/standalone");
|
|
@@ -34,8 +35,10 @@ var handle_missing_state_1 = require("../../helpers/handle-missing-state");
|
|
|
34
35
|
var is_root_text_node_1 = require("../../helpers/is-root-text-node");
|
|
35
36
|
var map_refs_1 = require("../../helpers/map-refs");
|
|
36
37
|
var merge_options_1 = require("../../helpers/merge-options");
|
|
38
|
+
var process_code_1 = require("../../helpers/plugins/process-code");
|
|
37
39
|
var process_http_requests_1 = require("../../helpers/process-http-requests");
|
|
38
40
|
var render_imports_1 = require("../../helpers/render-imports");
|
|
41
|
+
var replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
39
42
|
var replace_new_lines_in_strings_1 = require("../../helpers/replace-new-lines-in-strings");
|
|
40
43
|
var state_1 = require("../../helpers/state");
|
|
41
44
|
var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
@@ -124,11 +127,6 @@ function getContextString(component, options) {
|
|
|
124
127
|
}
|
|
125
128
|
return str;
|
|
126
129
|
}
|
|
127
|
-
var DEFAULT_OPTIONS = {
|
|
128
|
-
stateType: 'useState',
|
|
129
|
-
stylesType: 'styled-jsx',
|
|
130
|
-
type: 'dom',
|
|
131
|
-
};
|
|
132
130
|
var componentToPreact = function (reactOptions) {
|
|
133
131
|
if (reactOptions === void 0) { reactOptions = {}; }
|
|
134
132
|
return (0, exports.componentToReact)(__assign(__assign({}, reactOptions), { preact: true }));
|
|
@@ -137,6 +135,7 @@ exports.componentToPreact = componentToPreact;
|
|
|
137
135
|
var componentToReact = function (reactOptions) {
|
|
138
136
|
if (reactOptions === void 0) { reactOptions = {}; }
|
|
139
137
|
return function (_a) {
|
|
138
|
+
var _b, _c;
|
|
140
139
|
var component = _a.component, path = _a.path;
|
|
141
140
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
142
141
|
var target = reactOptions.preact
|
|
@@ -148,6 +147,40 @@ var componentToReact = function (reactOptions) {
|
|
|
148
147
|
: reactOptions.rsc
|
|
149
148
|
? 'rsc'
|
|
150
149
|
: 'react';
|
|
150
|
+
var isRsc = (_c = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.rsc) === null || _c === void 0 ? void 0 : _c.isRSC;
|
|
151
|
+
var stateType = isRsc
|
|
152
|
+
? 'variables'
|
|
153
|
+
: reactOptions.stateType || 'useState';
|
|
154
|
+
var DEFAULT_OPTIONS = {
|
|
155
|
+
stateType: stateType,
|
|
156
|
+
stylesType: 'styled-jsx',
|
|
157
|
+
type: 'dom',
|
|
158
|
+
plugins: stateType === 'variables'
|
|
159
|
+
? [
|
|
160
|
+
(0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType, json) { return function (code, hookType) {
|
|
161
|
+
code = (0, replace_identifiers_1.replaceNodes)({
|
|
162
|
+
code: code,
|
|
163
|
+
nodeMaps: Object.entries(json.state)
|
|
164
|
+
.filter(function (_a) {
|
|
165
|
+
var key = _a[0], value = _a[1];
|
|
166
|
+
return (value === null || value === void 0 ? void 0 : value.type) === 'getter';
|
|
167
|
+
})
|
|
168
|
+
.map(function (_a) {
|
|
169
|
+
var key = _a[0], value = _a[1];
|
|
170
|
+
var expr = core_1.types.memberExpression(core_1.types.identifier('state'), core_1.types.identifier(key));
|
|
171
|
+
return {
|
|
172
|
+
from: expr,
|
|
173
|
+
// condition: (path) => !types.isObjectMethod(path.parent),
|
|
174
|
+
to: core_1.types.callExpression(expr, []),
|
|
175
|
+
};
|
|
176
|
+
}),
|
|
177
|
+
});
|
|
178
|
+
code = (0, replace_identifiers_1.replaceStateIdentifier)(null)(code);
|
|
179
|
+
return code;
|
|
180
|
+
}; }),
|
|
181
|
+
]
|
|
182
|
+
: [],
|
|
183
|
+
};
|
|
151
184
|
var options = (0, merge_options_1.initializeOptions)({
|
|
152
185
|
target: target,
|
|
153
186
|
component: component,
|
|
@@ -155,14 +188,14 @@ var componentToReact = function (reactOptions) {
|
|
|
155
188
|
userOptions: reactOptions,
|
|
156
189
|
});
|
|
157
190
|
if (options.plugins) {
|
|
158
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
191
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
159
192
|
}
|
|
160
193
|
var str = _componentToReact(json, options);
|
|
161
194
|
str +=
|
|
162
195
|
'\n\n\n' +
|
|
163
196
|
json.subComponents.map(function (item) { return _componentToReact(item, options, true); }).join('\n\n\n');
|
|
164
197
|
if (options.plugins) {
|
|
165
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
198
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
166
199
|
}
|
|
167
200
|
if (options.prettier !== false) {
|
|
168
201
|
try {
|
|
@@ -182,7 +215,7 @@ var componentToReact = function (reactOptions) {
|
|
|
182
215
|
}
|
|
183
216
|
}
|
|
184
217
|
if (options.plugins) {
|
|
185
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
218
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
186
219
|
}
|
|
187
220
|
return str;
|
|
188
221
|
};
|
|
@@ -251,7 +284,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
251
284
|
}
|
|
252
285
|
var useStateCode = options.stateType === 'useState' ? (0, state_2.getUseStateCode)(json, options) : '';
|
|
253
286
|
if (options.plugins) {
|
|
254
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
287
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
255
288
|
}
|
|
256
289
|
var css = options.stylesType === 'styled-jsx'
|
|
257
290
|
? (0, collect_css_1.collectCss)(json)
|
|
@@ -317,7 +350,17 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
317
350
|
: options.stateType === 'builder'
|
|
318
351
|
? "const state = useBuilderState(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
319
352
|
: options.stateType === 'variables'
|
|
320
|
-
?
|
|
353
|
+
? (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
354
|
+
format: 'variables',
|
|
355
|
+
keyPrefix: 'const',
|
|
356
|
+
valueMapper: function (code, type, _, key) {
|
|
357
|
+
if (type === 'getter')
|
|
358
|
+
return "".concat(key, " = function ").concat(code.replace('get ', ''));
|
|
359
|
+
if (type === 'function')
|
|
360
|
+
return "".concat(key, " = function ").concat(code);
|
|
361
|
+
return code;
|
|
362
|
+
},
|
|
363
|
+
})
|
|
321
364
|
: "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
322
365
|
: '', hasStateArgument ? refsString : '', getContextString(json, options), (0, helpers_2.getCode)((_h = json.hooks.init) === null || _h === void 0 ? void 0 : _h.code, options), contextStr || '', ((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code)
|
|
323
366
|
? "\n useEffect(() => {\n ".concat((0, state_2.processHookCode)({
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
17
|
exports.componentToRsc = void 0;
|
|
7
18
|
var traverse_1 = __importDefault(require("traverse"));
|
|
8
|
-
var bindings_1 = require("../helpers/bindings");
|
|
9
|
-
var fast_clone_1 = require("../helpers/fast-clone");
|
|
10
19
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
11
20
|
var merge_options_1 = require("../helpers/merge-options");
|
|
12
21
|
var react_1 = require("./react");
|
|
@@ -35,43 +44,40 @@ var RSC_TRANSFORM_PLUGIN = function () { return ({
|
|
|
35
44
|
(0, traverse_1.default)(json).forEach(function (node) {
|
|
36
45
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
37
46
|
var isComponent = node.name.match(/[A-Z]/);
|
|
38
|
-
if (isComponent) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
+
// if (isComponent) {
|
|
48
|
+
// // Drill context down, aka
|
|
49
|
+
// // function (props) { return <Component _context{props._context} /> }
|
|
50
|
+
// if (!node.bindings[contextPropDrillingKey]) {
|
|
51
|
+
// node.bindings[contextPropDrillingKey] = createSingleBinding({
|
|
52
|
+
// code: contextPropDrillingKey,
|
|
53
|
+
// });
|
|
54
|
+
// }
|
|
55
|
+
// }
|
|
47
56
|
if (node.bindings.ref) {
|
|
48
57
|
delete node.bindings.ref;
|
|
49
58
|
}
|
|
50
|
-
for (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
59
|
+
// for (const key in node.bindings) {
|
|
60
|
+
// if (key.match(/^on[A-Z]/)) {
|
|
61
|
+
// delete node.bindings[key];
|
|
62
|
+
// }
|
|
63
|
+
// }
|
|
55
64
|
}
|
|
56
65
|
});
|
|
57
66
|
},
|
|
58
67
|
},
|
|
59
68
|
}); };
|
|
60
|
-
var
|
|
69
|
+
var RscOptions = {
|
|
61
70
|
plugins: [RSC_TRANSFORM_PLUGIN],
|
|
71
|
+
stateType: 'variables',
|
|
62
72
|
};
|
|
63
73
|
var componentToRsc = function (_options) {
|
|
64
74
|
if (_options === void 0) { _options = {}; }
|
|
65
75
|
return function (_a) {
|
|
76
|
+
var _b, _c;
|
|
66
77
|
var component = _a.component, path = _a.path;
|
|
67
|
-
var
|
|
68
|
-
var options = (0, merge_options_1.mergeOptions)(
|
|
69
|
-
|
|
70
|
-
stateType: 'variables',
|
|
71
|
-
contextType: 'prop-drill',
|
|
72
|
-
rsc: true,
|
|
73
|
-
});
|
|
74
|
-
return (0, react_1.componentToReact)(options)({ component: json, path: path });
|
|
78
|
+
var isRSC = (_c = (_b = component.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.rsc) === null || _c === void 0 ? void 0 : _c.isRSC;
|
|
79
|
+
var options = (0, merge_options_1.mergeOptions)(__assign({ rsc: true }, (isRSC ? RscOptions : {})), _options);
|
|
80
|
+
return (0, react_1.componentToReact)(options)({ component: component, path: path });
|
|
75
81
|
};
|
|
76
82
|
};
|
|
77
83
|
exports.componentToRsc = componentToRsc;
|
|
@@ -158,7 +158,7 @@ var componentToSolid = function (passedOptions) {
|
|
|
158
158
|
}),
|
|
159
159
|
], false);
|
|
160
160
|
if (options.plugins) {
|
|
161
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
161
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
162
162
|
}
|
|
163
163
|
addProviderComponents(json, options);
|
|
164
164
|
var componentHasStyles = (0, helpers_1.hasCss)(json);
|
|
@@ -171,7 +171,7 @@ var componentToSolid = function (passedOptions) {
|
|
|
171
171
|
// we need to run this before we run the code processor plugin, so the dynamic component variables are transformed
|
|
172
172
|
var foundDynamicComponents = processDynamicComponents(json, options);
|
|
173
173
|
if (options.plugins) {
|
|
174
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
174
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
175
175
|
}
|
|
176
176
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
177
177
|
var css = options.stylesType === 'style-tag' && (0, collect_css_1.collectCss)(json, { prefix: (0, hash_sum_1.default)(json) });
|
|
@@ -211,7 +211,7 @@ var componentToSolid = function (passedOptions) {
|
|
|
211
211
|
"<style jsx>{`".concat(css, "`}</style>")
|
|
212
212
|
: '', shouldInjectCustomStyles ? "<style>{`".concat(json.style, "`}</style>") : '', addWrapper ? '</>' : '', json.name);
|
|
213
213
|
if (options.plugins) {
|
|
214
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
214
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
215
215
|
}
|
|
216
216
|
if (options.prettier !== false) {
|
|
217
217
|
str = (0, standalone_1.format)(str, {
|
|
@@ -220,7 +220,7 @@ var componentToSolid = function (passedOptions) {
|
|
|
220
220
|
});
|
|
221
221
|
}
|
|
222
222
|
if (options.plugins) {
|
|
223
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
223
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
224
224
|
}
|
|
225
225
|
return str;
|
|
226
226
|
};
|
|
@@ -95,13 +95,13 @@ var componentToStencil = function (_options) {
|
|
|
95
95
|
var options = (0, merge_options_1.initializeOptions)({ target: 'stencil', component: component, defaults: _options });
|
|
96
96
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
97
97
|
if (options.plugins) {
|
|
98
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
98
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
99
99
|
}
|
|
100
100
|
var props = (0, get_props_1.getProps)(component);
|
|
101
101
|
var css = (0, collect_css_1.collectCss)(json);
|
|
102
102
|
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.".concat(refName); });
|
|
103
103
|
if (options.plugins) {
|
|
104
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
104
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
105
105
|
}
|
|
106
106
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
107
107
|
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
@@ -163,7 +163,7 @@ var componentToStencil = function (_options) {
|
|
|
163
163
|
? ''
|
|
164
164
|
: json.hooks.onUpdate.map(function (hook) { return "componentDidUpdate() { ".concat(processBinding(hook.code), " }"); }), wrap ? '<>' : '', json.children.map(function (item) { return blockToStencil(item, options); }).join('\n'), wrap ? '</>' : '');
|
|
165
165
|
if (options.plugins) {
|
|
166
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
166
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
167
167
|
}
|
|
168
168
|
if (options.prettier !== false) {
|
|
169
169
|
str = (0, standalone_1.format)(str, {
|
|
@@ -172,7 +172,7 @@ var componentToStencil = function (_options) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
if (options.plugins) {
|
|
175
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
175
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
176
176
|
}
|
|
177
177
|
return str;
|
|
178
178
|
};
|
|
@@ -162,7 +162,7 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
162
162
|
], false);
|
|
163
163
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
164
164
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
165
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
165
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
166
166
|
useBindValue(json, options);
|
|
167
167
|
(0, getters_to_functions_1.gettersToFunctions)(json);
|
|
168
168
|
var filteredProps = Array.from((0, get_props_1.getProps)(json))
|
|
@@ -174,7 +174,7 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
174
174
|
var refs = Array.from((0, get_refs_1.getRefs)(json))
|
|
175
175
|
.map((0, helpers_2.stripStateAndProps)({ json: json, options: options }))
|
|
176
176
|
.filter(function (x) { return !props.includes(x); });
|
|
177
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
177
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
178
178
|
var css = (0, collect_css_1.collectCss)(json);
|
|
179
179
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
180
180
|
var usesWritable = false;
|
|
@@ -289,7 +289,7 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
289
289
|
.join('\n'), !css.trim().length
|
|
290
290
|
? ''
|
|
291
291
|
: "<style>\n ".concat(css, "\n </style>"));
|
|
292
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
292
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
293
293
|
if (options.prettier !== false) {
|
|
294
294
|
try {
|
|
295
295
|
str = (0, standalone_1.format)(str, {
|
|
@@ -310,7 +310,7 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
str = str.replace(/<script>\n<\/script>/g, '').trim();
|
|
313
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
313
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
314
314
|
return str;
|
|
315
315
|
};
|
|
316
316
|
};
|