@builder.io/mitosis 0.0.81 → 0.0.83
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 +3 -2
- package/dist/src/generators/angular.js +69 -30
- package/dist/src/generators/context/helpers/context-with-symbol-key.d.ts +5 -0
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +27 -0
- package/dist/src/generators/context/svelte.d.ts +2 -6
- package/dist/src/generators/context/svelte.js +2 -25
- package/dist/src/generators/context/vue.d.ts +3 -6
- package/dist/src/generators/context/vue.js +2 -6
- package/dist/src/generators/html.js +42 -20
- package/dist/src/generators/marko/generate.js +21 -15
- package/dist/src/generators/mitosis.d.ts +2 -1
- package/dist/src/generators/mitosis.js +5 -5
- package/dist/src/generators/qwik/src-generator.js +2 -0
- package/dist/src/generators/react/generator.d.ts +2 -1
- package/dist/src/generators/react/generator.js +73 -20
- package/dist/src/generators/solid/index.js +14 -3
- package/dist/src/generators/svelte/blocks.js +15 -6
- package/dist/src/generators/svelte/svelte.js +4 -4
- package/dist/src/generators/vue/blocks.js +12 -6
- package/dist/src/generators/vue/compositionApi.js +17 -6
- package/dist/src/generators/vue/helpers.d.ts +10 -9
- package/dist/src/generators/vue/helpers.js +74 -36
- package/dist/src/generators/vue/optionsApi.js +36 -16
- package/dist/src/helpers/babel-transform.js +30 -19
- package/dist/src/helpers/patterns.d.ts +1 -0
- package/dist/src/helpers/patterns.js +5 -3
- package/dist/src/helpers/plugins/process-code.d.ts +3 -1
- package/dist/src/helpers/plugins/process-code.js +20 -19
- package/dist/src/helpers/replace-identifiers.d.ts +5 -3
- package/dist/src/helpers/replace-identifiers.js +131 -21
- package/dist/src/helpers/slots.js +3 -1
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +23 -4
- package/dist/src/helpers/strip-state-and-props-refs.js +57 -53
- package/dist/src/helpers/typescript.d.ts +1 -0
- package/dist/src/helpers/typescript.js +3 -0
- package/dist/src/parsers/jsx/element-parser.js +3 -2
- package/dist/src/parsers/jsx/function-parser.js +3 -10
- package/dist/src/parsers/jsx/helpers.d.ts +4 -0
- package/dist/src/parsers/jsx/helpers.js +11 -1
- package/dist/src/parsers/jsx/state.d.ts +1 -1
- package/dist/src/parsers/jsx/state.js +85 -39
- package/dist/src/parsers/svelte/html/slot.js +3 -8
- package/dist/src/types/mitosis-component.d.ts +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -165,18 +165,19 @@ var componentToAlpine = function (options) {
|
|
|
165
165
|
if (options.plugins) {
|
|
166
166
|
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
167
167
|
}
|
|
168
|
+
var componentName = (0, lodash_1.camelCase)(json.name) || 'MyComponent';
|
|
168
169
|
var stateObjectString = getStateObjectString(json);
|
|
169
170
|
// Set x-data on root element
|
|
170
171
|
json.children[0].properties['x-data'] = options.inlineState
|
|
171
172
|
? stateObjectString
|
|
172
|
-
: "".concat(
|
|
173
|
+
: "".concat(componentName, "()");
|
|
173
174
|
if ((0, render_update_hooks_1.hasRootUpdateHook)(json)) {
|
|
174
175
|
json.children[0].properties['x-effect'] = 'onUpdate';
|
|
175
176
|
}
|
|
176
177
|
var str = css.trim().length ? "<style>".concat(css, "</style>") : '';
|
|
177
178
|
str += json.children.map(function (item) { return blockToAlpine(item, options); }).join('\n');
|
|
178
179
|
if (!options.inlineState) {
|
|
179
|
-
str += "<script>\n ".concat((0, babel_transform_1.babelTransformCode)("document.addEventListener('alpine:init', () => {\n Alpine.data('".concat(
|
|
180
|
+
str += "<script>\n ".concat((0, babel_transform_1.babelTransformCode)("document.addEventListener('alpine:init', () => {\n Alpine.data('".concat(componentName, "', () => (").concat(stateObjectString, "))\n })")), "\n </script>");
|
|
180
181
|
}
|
|
181
182
|
if (options.plugins) {
|
|
182
183
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
@@ -29,7 +29,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.componentToAngular = exports.blockToAngular = void 0;
|
|
31
31
|
var dedent_1 = __importDefault(require("dedent"));
|
|
32
|
-
var json5_1 = __importDefault(require("json5"));
|
|
33
32
|
var standalone_1 = require("prettier/standalone");
|
|
34
33
|
var collect_css_1 = require("../helpers/styles/collect-css");
|
|
35
34
|
var fast_clone_1 = require("../helpers/fast-clone");
|
|
@@ -53,11 +52,12 @@ var slots_1 = require("../helpers/slots");
|
|
|
53
52
|
var get_custom_imports_1 = require("../helpers/get-custom-imports");
|
|
54
53
|
var get_components_used_1 = require("../helpers/get-components-used");
|
|
55
54
|
var is_upper_case_1 = require("../helpers/is-upper-case");
|
|
55
|
+
var replace_identifiers_1 = require("../helpers/replace-identifiers");
|
|
56
56
|
var html_tags_1 = require("../constants/html_tags");
|
|
57
57
|
var function_1 = require("fp-ts/lib/function");
|
|
58
58
|
var merge_options_1 = require("../helpers/merge-options");
|
|
59
59
|
var process_code_1 = require("../helpers/plugins/process-code");
|
|
60
|
-
var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment']);
|
|
60
|
+
var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment', 'Slot']);
|
|
61
61
|
var mappers = {
|
|
62
62
|
Fragment: function (json, options) {
|
|
63
63
|
return "<ng-container>".concat(json.children
|
|
@@ -65,11 +65,12 @@ var mappers = {
|
|
|
65
65
|
.join('\n'), "</ng-container>");
|
|
66
66
|
},
|
|
67
67
|
Slot: function (json, options) {
|
|
68
|
-
return
|
|
68
|
+
var renderChildren = function () { var _a; return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (0, exports.blockToAngular)(item, options); }).join('\n'); };
|
|
69
|
+
return "<ng-content ".concat(Object.entries(__assign(__assign({}, json.bindings), json.properties))
|
|
69
70
|
.map(function (_a) {
|
|
70
71
|
var binding = _a[0], value = _a[1];
|
|
71
72
|
if (value && binding === 'name') {
|
|
72
|
-
var selector = (0, function_1.pipe)(value.code, slots_1.stripSlotPrefix, lodash_1.kebabCase);
|
|
73
|
+
var selector = (0, function_1.pipe)((0, lodash_1.isString)(value) ? value : value.code, slots_1.stripSlotPrefix, lodash_1.kebabCase);
|
|
73
74
|
return "select=\"[".concat(selector, "]\"");
|
|
74
75
|
}
|
|
75
76
|
})
|
|
@@ -80,11 +81,11 @@ var mappers = {
|
|
|
80
81
|
return value.code;
|
|
81
82
|
}
|
|
82
83
|
})
|
|
83
|
-
.join('\n'), "</ng-content>");
|
|
84
|
+
.join('\n')).concat(renderChildren(), "</ng-content>");
|
|
84
85
|
},
|
|
85
86
|
};
|
|
86
87
|
var generateNgModule = function (content, name, componentsUsed, component, bootstrapMapper) {
|
|
87
|
-
return "import { NgModule } from \"@angular/core\";\nimport {
|
|
88
|
+
return "import { NgModule } from \"@angular/core\";\nimport { CommonModule } from \"@angular/common\";\n\n".concat(content, "\n\n@NgModule({\n declarations: [").concat(name, "],\n imports: [CommonModule").concat(componentsUsed.length ? ', ' + componentsUsed.map(function (comp) { return "".concat(comp, "Module"); }).join(', ') : '', "],\n exports: [").concat(name, "],\n ").concat(bootstrapMapper ? bootstrapMapper(name, componentsUsed, component) : '', "\n})\nexport class ").concat(name, "Module {}");
|
|
88
89
|
};
|
|
89
90
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
90
91
|
var BINDINGS_MAPPER = {
|
|
@@ -155,7 +156,8 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
155
156
|
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f;
|
|
156
157
|
// TODO: proper babel transform to replace. Util for this
|
|
157
158
|
if (key.startsWith('on')) {
|
|
158
|
-
var event_1 = key.replace('on', '')
|
|
159
|
+
var event_1 = key.replace('on', '');
|
|
160
|
+
event_1 = event_1.charAt(0).toLowerCase() + event_1.slice(1);
|
|
159
161
|
if (event_1 === 'change' && json.name === 'input' /* todo: other tags */) {
|
|
160
162
|
event_1 = 'input';
|
|
161
163
|
}
|
|
@@ -202,6 +204,17 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
202
204
|
return str;
|
|
203
205
|
};
|
|
204
206
|
exports.blockToAngular = blockToAngular;
|
|
207
|
+
var processAngularCode = function (_a) {
|
|
208
|
+
var contextVars = _a.contextVars, outputVars = _a.outputVars, domRefs = _a.domRefs, stateVars = _a.stateVars, replaceWith = _a.replaceWith;
|
|
209
|
+
return function (code) {
|
|
210
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.DO_NOT_USE_VARS_TRANSFORMS)(code, {
|
|
211
|
+
contextVars: contextVars,
|
|
212
|
+
domRefs: domRefs,
|
|
213
|
+
outputVars: outputVars,
|
|
214
|
+
stateVars: stateVars,
|
|
215
|
+
}), function (newCode) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, { replaceWith: replaceWith }); });
|
|
216
|
+
};
|
|
217
|
+
};
|
|
205
218
|
var componentToAngular = function (userOptions) {
|
|
206
219
|
if (userOptions === void 0) { userOptions = {}; }
|
|
207
220
|
return function (_a) {
|
|
@@ -220,25 +233,38 @@ var componentToAngular = function (userOptions) {
|
|
|
220
233
|
var options = (0, merge_options_1.mergeOptions)(__assign(__assign({}, DEFAULT_OPTIONS), userOptions));
|
|
221
234
|
options.plugins = __spreadArray(__spreadArray([], (options.plugins || []), true), [
|
|
222
235
|
(0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
|
|
223
|
-
var domRefs = (0, get_refs_1.getRefs)(json);
|
|
224
236
|
switch (codeType) {
|
|
225
237
|
case 'hooks':
|
|
226
|
-
return
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
238
|
+
return (0, function_1.flow)(processAngularCode({
|
|
239
|
+
replaceWith: 'this',
|
|
240
|
+
contextVars: contextVars,
|
|
241
|
+
outputVars: outputVars,
|
|
242
|
+
domRefs: Array.from((0, get_refs_1.getRefs)(json)),
|
|
243
|
+
stateVars: stateVars,
|
|
244
|
+
}), function (code) {
|
|
245
|
+
var allMethodNames = Object.entries(json.state)
|
|
246
|
+
.filter(function (_a) {
|
|
247
|
+
var _ = _a[0], value = _a[1];
|
|
248
|
+
return (value === null || value === void 0 ? void 0 : value.type) === 'function' || (value === null || value === void 0 ? void 0 : value.type) === 'method';
|
|
249
|
+
})
|
|
250
|
+
.map(function (_a) {
|
|
251
|
+
var key = _a[0];
|
|
252
|
+
return key;
|
|
233
253
|
});
|
|
234
|
-
|
|
254
|
+
return (0, replace_identifiers_1.replaceIdentifiers)({
|
|
255
|
+
code: code,
|
|
256
|
+
from: allMethodNames,
|
|
257
|
+
to: function (name) { return "this.".concat(name); },
|
|
258
|
+
});
|
|
259
|
+
});
|
|
235
260
|
case 'bindings':
|
|
236
261
|
return function (code) {
|
|
237
|
-
|
|
262
|
+
var newLocal = processAngularCode({
|
|
238
263
|
contextVars: [],
|
|
239
264
|
outputVars: outputVars,
|
|
240
265
|
domRefs: [], // the template doesn't need the this keyword.
|
|
241
|
-
})
|
|
266
|
+
})(code);
|
|
267
|
+
return newLocal.replace(/"/g, '"');
|
|
242
268
|
};
|
|
243
269
|
case 'hooks-deps':
|
|
244
270
|
case 'state':
|
|
@@ -321,15 +347,13 @@ var componentToAngular = function (userOptions) {
|
|
|
321
347
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
322
348
|
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
323
349
|
format: 'class',
|
|
324
|
-
valueMapper:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
});
|
|
332
|
-
},
|
|
350
|
+
valueMapper: processAngularCode({
|
|
351
|
+
replaceWith: 'this',
|
|
352
|
+
contextVars: contextVars,
|
|
353
|
+
outputVars: outputVars,
|
|
354
|
+
domRefs: Array.from(domRefs),
|
|
355
|
+
stateVars: stateVars,
|
|
356
|
+
}),
|
|
333
357
|
});
|
|
334
358
|
// Preparing built in component metadata parameters
|
|
335
359
|
var componentMetadata = __assign(__assign({ selector: "'".concat((0, lodash_1.kebabCase)(json.name || 'my-component'), ", ").concat(json.name, "'"), template: "`\n ".concat((0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), "\n `") }, (css.length
|
|
@@ -348,7 +372,22 @@ var componentToAngular = function (userOptions) {
|
|
|
348
372
|
var key = _a[0], value = _a[1];
|
|
349
373
|
componentMetadata[key] = value;
|
|
350
374
|
});
|
|
351
|
-
var
|
|
375
|
+
var getPropsDefinition = function (_a) {
|
|
376
|
+
var json = _a.json;
|
|
377
|
+
if (!json.defaultProps)
|
|
378
|
+
return '';
|
|
379
|
+
var defalutPropsString = Object.keys(json.defaultProps)
|
|
380
|
+
.map(function (prop) {
|
|
381
|
+
var _a;
|
|
382
|
+
var value = json.defaultProps.hasOwnProperty(prop)
|
|
383
|
+
? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
384
|
+
: '{}';
|
|
385
|
+
return "".concat(prop, ": ").concat(value);
|
|
386
|
+
})
|
|
387
|
+
.join(',');
|
|
388
|
+
return "const defaultProps = {".concat(defalutPropsString, "};\n");
|
|
389
|
+
};
|
|
390
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.inject) ? 'Inject, forwardRef,' : '', domRefs.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', getPropsDefinition({ json: json }), (0, render_imports_1.renderPreComponent)({
|
|
352
391
|
component: json,
|
|
353
392
|
target: 'angular',
|
|
354
393
|
excludeMitosisComponents: !options.standalone && !options.preserveImports,
|
|
@@ -377,13 +416,13 @@ var componentToAngular = function (userOptions) {
|
|
|
377
416
|
var argument = json.refs[ref].argument;
|
|
378
417
|
var typeParameter = json.refs[ref].typeParameter;
|
|
379
418
|
return "private _".concat(ref).concat(typeParameter ? ": ".concat(typeParameter) : '').concat(argument
|
|
380
|
-
? " = ".concat((
|
|
419
|
+
? " = ".concat(processAngularCode({
|
|
381
420
|
replaceWith: 'this.',
|
|
382
421
|
contextVars: contextVars,
|
|
383
422
|
outputVars: outputVars,
|
|
384
423
|
domRefs: Array.from(domRefs),
|
|
385
424
|
stateVars: stateVars,
|
|
386
|
-
}))
|
|
425
|
+
})(argument))
|
|
387
426
|
: '', ";");
|
|
388
427
|
})
|
|
389
428
|
.join('\n'), !hasConstructor
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MitosisContext } from '../../../types/mitosis-context';
|
|
2
|
+
import { BaseTranspilerOptions } from '../../../types/transpiler';
|
|
3
|
+
export declare const getContextWithSymbolKey: (options: Pick<BaseTranspilerOptions, 'prettier'>) => ({ context }: {
|
|
4
|
+
context: MitosisContext;
|
|
5
|
+
}) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContextWithSymbolKey = void 0;
|
|
4
|
+
var standalone_1 = require("prettier/standalone");
|
|
5
|
+
var get_state_object_string_1 = require("../../../helpers/get-state-object-string");
|
|
6
|
+
var getContextWithSymbolKey = function (options) {
|
|
7
|
+
return function (_a) {
|
|
8
|
+
var context = _a.context;
|
|
9
|
+
var str = "\n const key = Symbol(); \n\n export default {\n ".concat(context.name, ": ").concat((0, get_state_object_string_1.stringifyContextValue)(context.value), ", \n key \n }\n ");
|
|
10
|
+
if (options.prettier !== false) {
|
|
11
|
+
try {
|
|
12
|
+
str = (0, standalone_1.format)(str, {
|
|
13
|
+
parser: 'typescript',
|
|
14
|
+
plugins: [
|
|
15
|
+
require('prettier/parser-typescript'), // To support running in browsers
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
console.error('Format error for file:', str);
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return str;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.getContextWithSymbolKey = getContextWithSymbolKey;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { MitosisContext } from '../../types/mitosis-context';
|
|
2
1
|
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
3
|
-
interface ContextToSvelteOptions extends Pick<BaseTranspilerOptions, 'prettier'> {
|
|
4
|
-
}
|
|
5
2
|
/**
|
|
6
3
|
* TO-DO: support types
|
|
7
4
|
*/
|
|
8
|
-
export declare const contextToSvelte: (options
|
|
9
|
-
context: MitosisContext;
|
|
5
|
+
export declare const contextToSvelte: (options: Pick<BaseTranspilerOptions, "prettier">) => ({ context }: {
|
|
6
|
+
context: import("../../types/mitosis-context").MitosisContext;
|
|
10
7
|
}) => string;
|
|
11
|
-
export {};
|
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.contextToSvelte = void 0;
|
|
4
|
-
var
|
|
5
|
-
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
4
|
+
var context_with_symbol_key_1 = require("./helpers/context-with-symbol-key");
|
|
6
5
|
/**
|
|
7
6
|
* TO-DO: support types
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
if (options === void 0) { options = {}; }
|
|
11
|
-
return function (_a) {
|
|
12
|
-
var context = _a.context;
|
|
13
|
-
var str = "\n const key = Symbol(); \n\n export default {\n ".concat(context.name, ": ").concat((0, get_state_object_string_1.stringifyContextValue)(context.value), ", \n key \n }\n ");
|
|
14
|
-
if (options.prettier !== false) {
|
|
15
|
-
try {
|
|
16
|
-
str = (0, standalone_1.format)(str, {
|
|
17
|
-
parser: 'typescript',
|
|
18
|
-
plugins: [
|
|
19
|
-
require('prettier/parser-typescript'), // To support running in browsers
|
|
20
|
-
],
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
console.error('Format error for file:', str);
|
|
25
|
-
throw err;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return str;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
exports.contextToSvelte = contextToSvelte;
|
|
8
|
+
exports.contextToSvelte = context_with_symbol_key_1.getContextWithSymbolKey;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export declare function contextToVue(context: MitosisContext, options?: ContextToVueOptions): string;
|
|
6
|
-
export {};
|
|
1
|
+
export declare const contextToVue: (options: Pick<import("../..").BaseTranspilerOptions, "prettier">) => ({ context }: {
|
|
2
|
+
context: import("../../types/mitosis-context").MitosisContext;
|
|
3
|
+
}) => string;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.contextToVue = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var str = "\n // Noop file\n export default {};\n ";
|
|
7
|
-
return str;
|
|
8
|
-
}
|
|
9
|
-
exports.contextToVue = contextToVue;
|
|
4
|
+
var context_with_symbol_key_1 = require("./helpers/context-with-symbol-key");
|
|
5
|
+
exports.contextToVue = context_with_symbol_key_1.getContextWithSymbolKey;
|
|
@@ -55,6 +55,7 @@ var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
|
|
|
55
55
|
var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
|
|
56
56
|
var render_imports_1 = require("../helpers/render-imports");
|
|
57
57
|
var for_1 = require("../helpers/nodes/for");
|
|
58
|
+
var function_1 = require("fp-ts/lib/function");
|
|
58
59
|
var isAttribute = function (key) {
|
|
59
60
|
return /-/.test(key);
|
|
60
61
|
};
|
|
@@ -157,6 +158,22 @@ var createGlobalId = function (name, options) {
|
|
|
157
158
|
options.namesMap[name] = newNameNum;
|
|
158
159
|
return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '', "-").concat(newNameNum);
|
|
159
160
|
};
|
|
161
|
+
var deprecatedStripStateAndPropsRefs = function (code, _a) {
|
|
162
|
+
var context = _a.context, contextVars = _a.contextVars, domRefs = _a.domRefs, includeProps = _a.includeProps, includeState = _a.includeState, outputVars = _a.outputVars, replaceWith = _a.replaceWith, stateVars = _a.stateVars;
|
|
163
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
164
|
+
includeProps: includeProps,
|
|
165
|
+
includeState: includeState,
|
|
166
|
+
replaceWith: replaceWith,
|
|
167
|
+
}), function (newCode) {
|
|
168
|
+
return (0, strip_state_and_props_refs_1.DO_NOT_USE_VARS_TRANSFORMS)(newCode, {
|
|
169
|
+
context: context,
|
|
170
|
+
contextVars: contextVars,
|
|
171
|
+
domRefs: domRefs,
|
|
172
|
+
outputVars: outputVars,
|
|
173
|
+
stateVars: stateVars,
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
160
177
|
// TODO: overloaded function
|
|
161
178
|
var updateReferencesInCode = function (code, options, blockOptions) {
|
|
162
179
|
var _a, _b;
|
|
@@ -165,23 +182,22 @@ var updateReferencesInCode = function (code, options, blockOptions) {
|
|
|
165
182
|
var context = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.context) || 'this.';
|
|
166
183
|
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.updateReferencesInCode) {
|
|
167
184
|
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.updateReferencesInCode(code, options, {
|
|
168
|
-
stripStateAndPropsRefs:
|
|
185
|
+
stripStateAndPropsRefs: deprecatedStripStateAndPropsRefs,
|
|
169
186
|
});
|
|
170
187
|
}
|
|
171
188
|
if (options.format === 'class') {
|
|
172
|
-
return (0,
|
|
189
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
173
190
|
includeProps: false,
|
|
174
191
|
includeState: true,
|
|
175
192
|
replaceWith: context + 'state.',
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
});
|
|
193
|
+
}), function (newCode) {
|
|
194
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, {
|
|
195
|
+
// TODO: replace with `this.` and add setters that call this.update()
|
|
196
|
+
includeProps: true,
|
|
197
|
+
includeState: false,
|
|
198
|
+
replaceWith: context + 'props.',
|
|
199
|
+
});
|
|
200
|
+
}, function (newCode) { return (0, strip_state_and_props_refs_1.DO_NOT_USE_CONTEXT_VARS_TRANSFORMS)({ code: newCode, context: context, contextVars: contextVars }); });
|
|
185
201
|
}
|
|
186
202
|
return code;
|
|
187
203
|
};
|
|
@@ -598,19 +614,25 @@ var componentToCustomElement = function (options) {
|
|
|
598
614
|
? "this.context = ".concat(setContext[0].ref)
|
|
599
615
|
: '', "\n\n ").concat(!((_o = (_m = json.hooks) === null || _m === void 0 ? void 0 : _m.onInit) === null || _o === void 0 ? void 0 : _o.code) ? '' : 'this.onInitOnce = false;', "\n\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
600
616
|
valueMapper: function (value) {
|
|
601
|
-
return (0,
|
|
617
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
|
|
602
618
|
includeProps: false,
|
|
603
619
|
includeState: true,
|
|
604
620
|
// TODO: if it's an arrow function it's this.state.
|
|
605
621
|
replaceWith: 'self.state.',
|
|
606
|
-
}), {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
622
|
+
}), function (newCode) {
|
|
623
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, {
|
|
624
|
+
// TODO: replace with `this.` and add setters that call this.update()
|
|
625
|
+
includeProps: true,
|
|
626
|
+
includeState: false,
|
|
627
|
+
replaceWith: 'self.props.',
|
|
628
|
+
});
|
|
629
|
+
}, function (code) {
|
|
630
|
+
return (0, strip_state_and_props_refs_1.DO_NOT_USE_CONTEXT_VARS_TRANSFORMS)({
|
|
631
|
+
code: code,
|
|
632
|
+
contextVars: contextVars,
|
|
633
|
+
// correctly ref the class not state object
|
|
634
|
+
context: 'self.',
|
|
635
|
+
});
|
|
614
636
|
});
|
|
615
637
|
},
|
|
616
638
|
}), ";\n if (!this.props) {\n this.props = {};\n }\n ").concat(!componentHasProps
|
|
@@ -108,21 +108,27 @@ var blockToMarko = function (json, options) {
|
|
|
108
108
|
};
|
|
109
109
|
function processBinding(json, code, type) {
|
|
110
110
|
if (type === void 0) { type = 'attribute'; }
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
try {
|
|
112
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
113
|
+
replaceWith: type === 'state' ? 'input.' : type === 'class' ? 'this.input.' : 'input.',
|
|
114
|
+
includeProps: true,
|
|
115
|
+
includeState: false,
|
|
116
|
+
}), {
|
|
117
|
+
replaceWith: function (key) {
|
|
118
|
+
var isProperty = getStatePropertyNames(json).includes(key);
|
|
119
|
+
if (isProperty) {
|
|
120
|
+
return (type === 'state' || type === 'class' ? 'this.state.' : 'state.') + key;
|
|
121
|
+
}
|
|
122
|
+
return (type === 'class' || type === 'state' ? 'this.' : 'component.') + key;
|
|
123
|
+
},
|
|
124
|
+
includeProps: false,
|
|
125
|
+
includeState: true,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error('Marko: could not process binding', code);
|
|
130
|
+
return code;
|
|
131
|
+
}
|
|
126
132
|
}
|
|
127
133
|
var componentToMarko = function (userOptions) {
|
|
128
134
|
if (userOptions === void 0) { userOptions = {}; }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
|
|
2
|
+
import { MitosisComponent } from '../types/mitosis-component';
|
|
2
3
|
import { MitosisNode } from '../types/mitosis-node';
|
|
3
4
|
export interface ToMitosisOptions extends BaseTranspilerOptions {
|
|
4
5
|
format: 'react' | 'legacy';
|
|
5
6
|
}
|
|
6
7
|
export declare const DEFAULT_FORMAT: ToMitosisOptions['format'];
|
|
7
|
-
export declare const blockToMitosis: (json: MitosisNode, toMitosisOptions
|
|
8
|
+
export declare const blockToMitosis: (json: MitosisNode, toMitosisOptions: Partial<ToMitosisOptions> | undefined, component: MitosisComponent) => string;
|
|
8
9
|
export declare const componentToMitosis: TranspilerGenerator<Partial<ToMitosisOptions>>;
|
|
@@ -46,7 +46,7 @@ exports.DEFAULT_FORMAT = 'legacy';
|
|
|
46
46
|
var isValidAttributeName = function (str) {
|
|
47
47
|
return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
|
|
48
48
|
};
|
|
49
|
-
var blockToMitosis = function (json, toMitosisOptions) {
|
|
49
|
+
var blockToMitosis = function (json, toMitosisOptions, component) {
|
|
50
50
|
var _a, _b, _c, _d, _e, _f;
|
|
51
51
|
if (toMitosisOptions === void 0) { toMitosisOptions = {}; }
|
|
52
52
|
var options = __assign({ format: exports.DEFAULT_FORMAT }, toMitosisOptions);
|
|
@@ -56,11 +56,11 @@ var blockToMitosis = function (json, toMitosisOptions) {
|
|
|
56
56
|
stateType: 'useState',
|
|
57
57
|
stylesType: 'emotion',
|
|
58
58
|
prettier: options.prettier,
|
|
59
|
-
});
|
|
59
|
+
}, component);
|
|
60
60
|
}
|
|
61
61
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
62
62
|
var needsWrapper = json.children.length !== 1;
|
|
63
|
-
return "<For each={".concat((_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code, "}>\n {(").concat(json.scope.forName, ", index) =>\n ").concat(needsWrapper ? '<>' : '', "\n ").concat(json.children.map(function (child) { return (0, exports.blockToMitosis)(child, options); }), "}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
|
|
63
|
+
return "<For each={".concat((_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code, "}>\n {(").concat(json.scope.forName, ", index) =>\n ").concat(needsWrapper ? '<>' : '', "\n ").concat(json.children.map(function (child) { return (0, exports.blockToMitosis)(child, options, component); }), "}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
|
|
64
64
|
}
|
|
65
65
|
if (json.properties._text) {
|
|
66
66
|
return json.properties._text;
|
|
@@ -106,7 +106,7 @@ var blockToMitosis = function (json, toMitosisOptions) {
|
|
|
106
106
|
}
|
|
107
107
|
str += '>';
|
|
108
108
|
if (json.children) {
|
|
109
|
-
str += json.children.map(function (item) { return (0, exports.blockToMitosis)(item, options); }).join('\n');
|
|
109
|
+
str += json.children.map(function (item) { return (0, exports.blockToMitosis)(item, options, component); }).join('\n');
|
|
110
110
|
}
|
|
111
111
|
str += "</".concat(json.name, ">");
|
|
112
112
|
return str;
|
|
@@ -159,7 +159,7 @@ var componentToMitosis = function (toMitosisOptions) {
|
|
|
159
159
|
? ''
|
|
160
160
|
: "import { ".concat(!hasState ? '' : 'useStore, ', " ").concat(!refs.length ? '' : 'useRef, ', " ").concat(mitosisComponents.join(', '), " } from '@builder.io/mitosis';"), !otherComponents.length ? '' : "import { ".concat(otherComponents.join(','), " } from '@components';"), json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({ component: json, target: 'mitosis' }), stringifiedUseMetadata && stringifiedUseMetadata !== '{}'
|
|
161
161
|
? "".concat(jsx_1.METADATA_HOOK_NAME, "(").concat(stringifiedUseMetadata, ")")
|
|
162
|
-
: '', component.name, !hasState ? '' : "const state = useStore(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");"), getRefsString(json, refs), !((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ? '' : "onMount(() => { ".concat(json.hooks.onMount.code, " })"), !((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code) ? '' : "onUnMount(() => { ".concat(json.hooks.onUnMount.code, " })"), addWrapper ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToMitosis)(item, options); }).join('\n'), addWrapper ? '</>' : '');
|
|
162
|
+
: '', component.name, !hasState ? '' : "const state = useStore(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");"), getRefsString(json, refs), !((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ? '' : "onMount(() => { ".concat(json.hooks.onMount.code, " })"), !((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code) ? '' : "onUnMount(() => { ".concat(json.hooks.onUnMount.code, " })"), addWrapper ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToMitosis)(item, options, component); }).join('\n'), addWrapper ? '</>' : '');
|
|
163
163
|
if (options.prettier !== false) {
|
|
164
164
|
try {
|
|
165
165
|
str = (0, standalone_1.format)(str, {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TranspilerGenerator } from '../../types/transpiler';
|
|
2
|
+
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
3
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
3
4
|
import { ToReactOptions } from './types';
|
|
4
5
|
export declare const contextPropDrillingKey = "_context";
|
|
5
|
-
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, parentSlots?: any[]) => string;
|
|
6
|
+
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, component: MitosisComponent, parentSlots?: any[]) => string;
|
|
6
7
|
export declare const componentToPreact: TranspilerGenerator<ToReactOptions>;
|
|
7
8
|
export declare const componentToReact: TranspilerGenerator<ToReactOptions>;
|