@builder.io/mitosis 0.0.74 → 0.0.76

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.
Files changed (55) hide show
  1. package/dist/src/generators/angular.d.ts +2 -0
  2. package/dist/src/generators/angular.js +16 -5
  3. package/dist/src/generators/lit/generate.js +0 -3
  4. package/dist/src/generators/marko/generate.js +0 -3
  5. package/dist/src/generators/qwik/component-generator.js +9 -8
  6. package/dist/src/generators/qwik/directives.js +4 -0
  7. package/dist/src/generators/qwik/jsx.d.ts +1 -1
  8. package/dist/src/generators/qwik/jsx.js +5 -9
  9. package/dist/src/generators/react/generator.js +15 -11
  10. package/dist/src/generators/solid/index.js +24 -26
  11. package/dist/src/generators/stencil/generate.js +0 -3
  12. package/dist/src/generators/svelte/blocks.d.ts +10 -0
  13. package/dist/src/generators/svelte/blocks.js +188 -0
  14. package/dist/src/generators/svelte/helpers.d.ts +2 -0
  15. package/dist/src/generators/svelte/helpers.js +11 -0
  16. package/dist/src/generators/svelte/index.d.ts +1 -0
  17. package/dist/src/generators/svelte/index.js +5 -0
  18. package/dist/src/generators/svelte/svelte.d.ts +3 -0
  19. package/dist/src/generators/svelte/svelte.js +250 -0
  20. package/dist/src/generators/svelte/types.d.ts +4 -0
  21. package/dist/src/generators/svelte/types.js +2 -0
  22. package/dist/src/generators/vue/blocks.js +13 -23
  23. package/dist/src/generators/vue/compositionApi.js +23 -83
  24. package/dist/src/generators/vue/helpers.d.ts +10 -4
  25. package/dist/src/generators/vue/helpers.js +100 -18
  26. package/dist/src/generators/vue/optionsApi.js +6 -28
  27. package/dist/src/generators/vue/types.d.ts +5 -2
  28. package/dist/src/generators/vue/vue.d.ts +1 -4
  29. package/dist/src/generators/vue/vue.js +70 -49
  30. package/dist/src/helpers/is-children.js +3 -2
  31. package/dist/src/helpers/merge-options.d.ts +7 -0
  32. package/dist/src/helpers/merge-options.js +31 -0
  33. package/dist/src/helpers/plugins/process-code.d.ts +8 -0
  34. package/dist/src/helpers/plugins/process-code.js +69 -0
  35. package/dist/src/helpers/render-imports.d.ts +11 -3
  36. package/dist/src/helpers/render-imports.js +18 -4
  37. package/dist/src/helpers/replace-identifiers.js +18 -8
  38. package/dist/src/helpers/typescript.d.ts +1 -1
  39. package/dist/src/parsers/angular.js +4 -3
  40. package/dist/src/parsers/builder.d.ts +2 -2
  41. package/dist/src/parsers/jsx/ast.d.ts +2 -0
  42. package/dist/src/parsers/jsx/component-types.d.ts +2 -0
  43. package/dist/src/parsers/jsx/element-parser.d.ts +3 -1
  44. package/dist/src/parsers/jsx/exports.d.ts +4 -2
  45. package/dist/src/parsers/jsx/function-parser.d.ts +2 -0
  46. package/dist/src/parsers/jsx/helpers.d.ts +2 -0
  47. package/dist/src/parsers/jsx/imports.d.ts +2 -0
  48. package/dist/src/parsers/jsx/metadata.d.ts +2 -0
  49. package/dist/src/parsers/jsx/state.d.ts +2 -0
  50. package/dist/src/targets.d.ts +1 -1
  51. package/dist/src/types/mitosis-component.d.ts +8 -7
  52. package/dist/tsconfig.build.tsbuildinfo +1 -1
  53. package/package.json +3 -3
  54. package/dist/src/generators/svelte.d.ts +0 -14
  55. package/dist/src/generators/svelte.js +0 -455
@@ -4,6 +4,8 @@ export interface ToAngularOptions extends BaseTranspilerOptions {
4
4
  standalone?: boolean;
5
5
  preserveImports?: boolean;
6
6
  preserveFileExtensions?: boolean;
7
+ importMapper?: Function;
8
+ bootstrapMapper?: Function;
7
9
  }
8
10
  interface AngularBlockOptions {
9
11
  contextVars?: string[];
@@ -53,6 +53,7 @@ var slots_1 = require("../helpers/slots");
53
53
  var get_custom_imports_1 = require("../helpers/get-custom-imports");
54
54
  var get_components_used_1 = require("../helpers/get-components-used");
55
55
  var is_upper_case_1 = require("../helpers/is-upper-case");
56
+ var html_tags_1 = require("../constants/html_tags");
56
57
  var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment']);
57
58
  var mappers = {
58
59
  Fragment: function (json, options, blockOptions) {
@@ -79,6 +80,9 @@ var mappers = {
79
80
  .join('\n'), "</ng-content>");
80
81
  },
81
82
  };
83
+ var generateNgModule = function (content, name, componentsUsed, component, bootstrapMapper) {
84
+ return "import { NgModule } from \"@angular/core\";\nimport { BrowserModule } from \"@angular/platform-browser\";\n\n".concat(content, "\n\n@NgModule({\n declarations: [").concat(name, "],\n imports: [BrowserModule").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 {}");
85
+ };
82
86
  // TODO: Maybe in the future allow defining `string | function` as values
83
87
  var BINDINGS_MAPPER = {
84
88
  innerHTML: 'innerHTML',
@@ -92,6 +96,7 @@ var blockToAngular = function (json, options, blockOptions) {
92
96
  var outputVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.outputVars) || [];
93
97
  var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
94
98
  var domRefs = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.domRefs) || [];
99
+ var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name.trim());
95
100
  if (mappers[json.name]) {
96
101
  return mappers[json.name](json, options, blockOptions);
97
102
  }
@@ -191,11 +196,12 @@ var blockToAngular = function (json, options, blockOptions) {
191
196
  else if (BINDINGS_MAPPER[key]) {
192
197
  str += " [".concat(BINDINGS_MAPPER[key], "]=\"").concat(useValue, "\" ");
193
198
  }
194
- else if (key.includes('-')) {
199
+ else if (isValidHtmlTag || key.includes('-')) {
200
+ // standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
195
201
  str += " [attr.".concat(key, "]=\"").concat(useValue, "\" ");
196
202
  }
197
203
  else {
198
- str += " [".concat(key, "]=\"").concat(useValue, "\" ");
204
+ str += "[".concat(key, "]=\"").concat(useValue, "\" ");
199
205
  }
200
206
  }
201
207
  if (jsx_1.selfClosingTags.has(json.name)) {
@@ -280,7 +286,9 @@ var componentToAngular = function (userOptions) {
280
286
  var domRefs = (0, get_refs_1.getRefs)(json);
281
287
  var jsRefs = Object.keys(json.refs).filter(function (ref) { return !domRefs.has(ref); });
282
288
  var stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
283
- var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter(function (item) { return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !BUILT_IN_COMPONENTS.has(item); });
289
+ var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter(function (item) {
290
+ return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !BUILT_IN_COMPONENTS.has(item);
291
+ });
284
292
  (0, map_refs_1.mapRefs)(json, function (refName) {
285
293
  var isDomRef = domRefs.has(refName);
286
294
  return "this.".concat(isDomRef ? '' : '_').concat(refName).concat(isDomRef ? '.nativeElement' : '');
@@ -334,11 +342,13 @@ var componentToAngular = function (userOptions) {
334
342
  var key = _a[0], value = _a[1];
335
343
  componentMetadata[key] = value;
336
344
  });
337
- 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 default 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 default 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') : '', !json.defaultProps ? '' : "const defaultProps = ".concat(json5_1.default.stringify(json.defaultProps), "\n"), (0, render_imports_1.renderPreComponent)({
345
+ 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') : '', !json.defaultProps ? '' : "const defaultProps = ".concat(json5_1.default.stringify(json.defaultProps), "\n"), (0, render_imports_1.renderPreComponent)({
338
346
  component: json,
339
347
  target: 'angular',
340
348
  excludeMitosisComponents: !options.standalone && !options.preserveImports,
341
349
  preserveFileExtensions: options.preserveFileExtensions,
350
+ componentsUsed: componentsUsed,
351
+ importMapper: options === null || options === void 0 ? void 0 : options.importMapper,
342
352
  }), Object.entries(componentMetadata)
343
353
  .map(function (_a) {
344
354
  var k = _a[0], v = _a[1];
@@ -380,7 +390,7 @@ var componentToAngular = function (userOptions) {
380
390
  outputVars: outputVars,
381
391
  }), "\n "), "\n }\n "), !hasOnMount
382
392
  ? ''
383
- : "ngOnInit() {\n \n ".concat(!((_k = json.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
393
+ : "ngOnInit() {\n\n ".concat(!((_k = json.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
384
394
  ? ''
385
395
  : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_l = json.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, {
386
396
  replaceWith: 'this.',
@@ -408,6 +418,7 @@ var componentToAngular = function (userOptions) {
408
418
  domRefs: Array.from(domRefs),
409
419
  stateVars: stateVars,
410
420
  }), "\n }"));
421
+ str = generateNgModule(str, json.name, componentsUsed, json, options.bootstrapMapper);
411
422
  if (options.plugins) {
412
423
  str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
413
424
  }
@@ -74,9 +74,6 @@ var blockToLit = function (json, options) {
74
74
  }
75
75
  for (var key in json.bindings) {
76
76
  var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
77
- if (key === '_forName') {
78
- continue;
79
- }
80
77
  if (type === 'spread') {
81
78
  str += " ${spread(".concat(code, ")} ");
82
79
  }
@@ -79,9 +79,6 @@ var blockToMarko = function (json, options) {
79
79
  }
80
80
  for (var key in json.bindings) {
81
81
  var _f = json.bindings[key], code = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g, type = _f.type;
82
- if (key === '_forName') {
83
- continue;
84
- }
85
82
  if (type === 'spread') {
86
83
  str += " ...(".concat(code, ") ");
87
84
  }
@@ -53,6 +53,7 @@ var componentToQwik = function (userOptions) {
53
53
  try {
54
54
  emitImports(file, component);
55
55
  emitTypes(file, component);
56
+ emitExports(file, component);
56
57
  var metadata = component.meta.useMetadata || {};
57
58
  var isLightComponent = ((_c = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
58
59
  var mutable_1 = ((_d = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _d === void 0 ? void 0 : _d.mutable) || [];
@@ -97,6 +98,13 @@ var componentToQwik = function (userOptions) {
97
98
  };
98
99
  };
99
100
  exports.componentToQwik = componentToQwik;
101
+ function emitExports(file, component) {
102
+ component.exports &&
103
+ Object.keys(component.exports).forEach(function (key) {
104
+ var exportObj = component.exports[key];
105
+ file.src.emit(exportObj.code);
106
+ });
107
+ }
100
108
  function emitTagNameHack(file, component, metadataValue) {
101
109
  if (typeof metadataValue === 'string' && metadataValue) {
102
110
  file.src.emit(metadataValue, '=', (0, convert_method_to_function_1.convertMethodToFunction)(metadataValue, stateToMethodOrGetter(component.state), getLexicalScopeVars(component)), ';');
@@ -144,14 +152,7 @@ function emitJSX(file, component, mutable) {
144
152
  var handlers = new Map();
145
153
  var styles = new Map();
146
154
  var parentSymbolBindings = {};
147
- var mutablePredicate = mutable.length > 0
148
- ? function (code) {
149
- return !!mutable.find(function (txt) {
150
- return code.indexOf(txt) !== -1;
151
- });
152
- }
153
- : undefined;
154
- file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings, mutablePredicate));
155
+ file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings));
155
156
  }
156
157
  function emitUseContextProvider(file, component) {
157
158
  Object.keys(component.context.set).forEach(function (ctxKey) {
@@ -70,6 +70,10 @@ function Image(props) {
70
70
  loading: isPixel ? 'eager' : 'lazy',
71
71
  srcset: undefined,
72
72
  };
73
+ var qwikBugWorkaround = function (imgProps) {
74
+ return Object.keys(imgProps).forEach(function (k) { return imgProps[k] === undefined && delete imgProps[k]; });
75
+ };
76
+ qwikBugWorkaround(imgProps);
73
77
  if (isBuilderIoImage) {
74
78
  var webpImage_1 = updateQueryParam(image, 'format', 'webp');
75
79
  var srcset = ['100', '200', '400', '800', '1200', '1600', '2000']
@@ -13,4 +13,4 @@ import { CssStyles } from './styles';
13
13
  * @param root True if this is the root JSX, and may need a Fragment wrapper.
14
14
  * @returns
15
15
  */
16
- export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, mutablePredicate?: (code: string) => boolean, root?: boolean): any;
16
+ export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, root?: boolean): any;
@@ -36,7 +36,7 @@ var src_generator_1 = require("./src-generator");
36
36
  * @param root True if this is the root JSX, and may need a Fragment wrapper.
37
37
  * @returns
38
38
  */
39
- function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, mutablePredicate, root) {
39
+ function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, root) {
40
40
  if (root === void 0) { root = true; }
41
41
  return function () {
42
42
  var _this = this;
@@ -121,9 +121,9 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
121
121
  }
122
122
  }
123
123
  var symbolBindings = {};
124
- var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings, mutablePredicate);
124
+ var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
125
125
  _this.jsxBegin(childName, props, __assign(__assign(__assign({}, bindings), parentSymbolBindings), specialBindings));
126
- renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, mutablePredicate, false).call(_this);
126
+ renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, false).call(_this);
127
127
  _this.jsxEnd(childName);
128
128
  }
129
129
  }
@@ -138,7 +138,7 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
138
138
  children = children.filter(function (c) { return !isEmptyTextNode(c); });
139
139
  var childNeedsFragment = children.length > 1 || (children.length && isTextNode(children[0]));
140
140
  childNeedsFragment && srcBuilder.jsxBeginFragment(fragmentSymbol);
141
- renderJSXNodes(file, directives, handlers, children, styles, {}, mutablePredicate, false).call(srcBuilder);
141
+ renderJSXNodes(file, directives, handlers, children, styles, {}, false).call(srcBuilder);
142
142
  childNeedsFragment && srcBuilder.jsxEndFragment();
143
143
  };
144
144
  }
@@ -182,7 +182,7 @@ function isSlotProjection(child) {
182
182
  * @param symbolBindings Options record which will receive the symbol bindings
183
183
  * @returns
184
184
  */
185
- function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredicate) {
185
+ function rewriteHandlers(file, handlers, bindings, symbolBindings) {
186
186
  var _a, _b;
187
187
  var outBindings = {};
188
188
  for (var key in bindings) {
@@ -207,10 +207,6 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredic
207
207
  else if (key.startsWith('component.options.')) {
208
208
  key = (0, src_generator_1.lastProperty)(key);
209
209
  }
210
- if (mutablePredicate && bindingExpr && mutablePredicate(bindingExpr)) {
211
- file.import(file.qwikModule, 'mutable');
212
- bindingExpr = "mutable(".concat(bindingExpr, ")");
213
- }
214
210
  outBindings[key] = { code: bindingExpr, type: (_b = bindings === null || bindings === void 0 ? void 0 : bindings[key]) === null || _b === void 0 ? void 0 : _b.type };
215
211
  }
216
212
  }
@@ -107,9 +107,13 @@ var NODE_MAPPERS = {
107
107
  .join('\n')).concat(wrap ? closeFrag(options) : '', "\n ) : ").concat(!json.meta.else ? 'null' : (0, exports.blockToReact)(json.meta.else, options), "}");
108
108
  },
109
109
  };
110
+ var ATTTRIBUTE_MAPPERS = {
111
+ spellcheck: 'spellCheck',
112
+ autocapitalize: 'autoCapitalize',
113
+ autocomplete: 'autoComplete',
114
+ };
110
115
  // TODO: Maybe in the future allow defining `string | function` as values
111
- var BINDING_MAPPERS = {
112
- ref: function (ref, value, options) {
116
+ var BINDING_MAPPERS = __assign({ ref: function (ref, value, options) {
113
117
  var regexp = /(.+)?props\.(.+)( |\)|;|\()?$/m;
114
118
  if (regexp.test(value)) {
115
119
  var match = regexp.exec(value);
@@ -119,11 +123,9 @@ var BINDING_MAPPERS = {
119
123
  }
120
124
  }
121
125
  return [ref, value];
122
- },
123
- innerHTML: function (_key, value) {
126
+ }, innerHTML: function (_key, value) {
124
127
  return ['dangerouslySetInnerHTML', "{__html: ".concat(value.replace(/\s+/g, ' '), "}")];
125
- },
126
- };
128
+ } }, ATTTRIBUTE_MAPPERS);
127
129
  var blockToReact = function (json, options, parentSlots) {
128
130
  var _a, _b, _c;
129
131
  if (NODE_MAPPERS[json.name]) {
@@ -425,7 +427,7 @@ var _componentToReact = function (json, options, isSubComponent) {
425
427
  var _o = getRefsString(json, allRefs, options), hasStateArgument = _o[0], refsString = _o[1];
426
428
  var nativeStyles = stylesType === 'react-native' && componentHasStyles && (0, react_native_1.collectReactNativeStyles)(json);
427
429
  var propsArgs = "props: ".concat(json.propsTypeRef || 'any');
428
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n "])), options.preact
430
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n "])), options.preact
429
431
  ? "\n /** @jsx h */\n import { h, Fragment } from 'preact';\n "
430
432
  : options.type !== 'native'
431
433
  ? "import * as React from 'react';"
@@ -434,11 +436,11 @@ var _componentToReact = function (json, options, isSubComponent) {
434
436
  : '', componentHasStyles && stylesType === 'emotion' && options.format !== 'lite'
435
437
  ? "/** @jsx jsx */\n import { jsx } from '@emotion/react'".trim()
436
438
  : '', hasState && stateType === 'valtio' ? "import { useLocalProxy } from 'valtio/utils';" : '', hasState && stateType === 'solid' ? "import { useMutable } from 'react-solid-state';" : '', stateType === 'mobx' && hasState
437
- ? "import { useLocalObservable } from 'mobx-react-lite';"
439
+ ? "import { useLocalObservable, observer } from 'mobx-react-lite';"
438
440
  : '', json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
439
441
  component: json,
440
442
  target: options.type === 'native' ? 'reactNative' : 'react',
441
- }), isSubComponent ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', options.contextType === 'prop-drill'
443
+ }), stateType === 'mobx' && isForwardRef ? "const ".concat(json.name || 'MyComponent', " = ") : "", isSubComponent || stateType === 'mobx' ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', options.contextType === 'prop-drill'
442
444
  ? "const ".concat(exports.contextPropDrillingKey, " = { ...props['").concat(exports.contextPropDrillingKey, "'] };")
443
445
  : '', hasStateArgument ? '' : refsString, hasState
444
446
  ? stateType === 'mobx'
@@ -462,7 +464,7 @@ var _componentToReact = function (json, options, isSubComponent) {
462
464
  str: json.hooks.onMount.code,
463
465
  options: options,
464
466
  }), "\n }, [])")
465
- : '', (_k = (_j = json.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.map(function (hook) { return "useEffect(() => {\n ".concat((0, state_2.processHookCode)({ str: hook.code, options: options }), "\n }, \n ").concat(hook.deps ? (0, state_2.processHookCode)({ str: hook.deps, options: options }) : '', ")"); }).join(';')) !== null && _k !== void 0 ? _k : '', ((_l = json.hooks.onUnMount) === null || _l === void 0 ? void 0 : _l.code)
467
+ : '', (_k = (_j = json.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.map(function (hook) { return "useEffect(() => {\n ".concat((0, state_2.processHookCode)({ str: hook.code, options: options }), "\n },\n ").concat(hook.deps ? (0, state_2.processHookCode)({ str: hook.deps, options: options }) : '', ")"); }).join(';')) !== null && _k !== void 0 ? _k : '', ((_l = json.hooks.onUnMount) === null || _l === void 0 ? void 0 : _l.code)
466
468
  ? "useEffect(() => {\n return () => {\n ".concat((0, state_2.processHookCode)({
467
469
  str: json.hooks.onUnMount.code,
468
470
  options: options,
@@ -475,7 +477,9 @@ var _componentToReact = function (json, options, isSubComponent) {
475
477
  ? ''
476
478
  : "".concat(json.name || 'MyComponent', ".defaultProps = ").concat(json5_1.default.stringify(json.defaultProps), ";"), !nativeStyles
477
479
  ? ''
478
- : "\n const styles = StyleSheet.create(".concat(json5_1.default.stringify(nativeStyles), ");\n "), styledComponentsCode ? styledComponentsCode : '');
480
+ : "\n const styles = StyleSheet.create(".concat(json5_1.default.stringify(nativeStyles), ");\n "), styledComponentsCode ? styledComponentsCode : '', stateType === 'mobx'
481
+ ? "\n const observed".concat(json.name || 'MyComponent', " = observer(").concat(json.name || 'MyComponent', ");\n export default observed").concat(json.name || 'MyComponent', ";\n ")
482
+ : '');
479
483
  str = (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(str);
480
484
  return str;
481
485
  };
@@ -78,10 +78,8 @@ var hash_sum_1 = __importDefault(require("hash-sum"));
78
78
  var Array_1 = require("fp-ts/lib/Array");
79
79
  var S = __importStar(require("fp-ts/string"));
80
80
  var helpers_2 = require("./state/helpers");
81
- var DEFAULT_OPTIONS = {
82
- state: 'signals',
83
- stylesType: 'styled-components',
84
- };
81
+ var merge_options_1 = require("../../helpers/merge-options");
82
+ var process_code_1 = require("../../helpers/plugins/process-code");
85
83
  // Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
86
84
  function processDynamicComponents(json, options) {
87
85
  var found = false;
@@ -168,7 +166,6 @@ var preProcessBlockCode = function (_a) {
168
166
  var blockToSolid = function (_a) {
169
167
  var _b, _c;
170
168
  var json = _a.json, options = _a.options, component = _a.component;
171
- preProcessBlockCode({ json: json, options: options, component: component });
172
169
  if (json.properties._text) {
173
170
  return json.properties._text;
174
171
  }
@@ -203,9 +200,6 @@ var blockToSolid = function (_a) {
203
200
  }
204
201
  for (var key in json.bindings) {
205
202
  var _d = json.bindings[key], code = _d.code, _e = _d.arguments, cusArg = _e === void 0 ? ['event'] : _e, type = _d.type;
206
- if (key === '_forName') {
207
- continue;
208
- }
209
203
  if (!code)
210
204
  continue;
211
205
  if (type === 'spread') {
@@ -278,29 +272,34 @@ function addProviderComponents(json, options) {
278
272
  ];
279
273
  }
280
274
  }
281
- var preProcessComponentCode = function (json, options) {
282
- var _a;
283
- var processCode = (0, helpers_2.updateStateCode)({ options: options, component: json });
284
- if ((_a = json.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code) {
285
- json.hooks.onMount.code = processCode(json.hooks.onMount.code);
286
- }
287
- if (json.hooks.onUpdate) {
288
- for (var _i = 0, _b = json.hooks.onUpdate; _i < _b.length; _i++) {
289
- var hook = _b[_i];
290
- hook.code = processCode(hook.code);
291
- if (hook.deps) {
292
- hook.deps = processCode(hook.deps);
293
- }
294
- }
295
- }
275
+ var DEFAULT_OPTIONS = {
276
+ state: 'signals',
277
+ stylesType: 'styled-components',
278
+ plugins: [],
296
279
  };
297
280
  var componentToSolid = function (passedOptions) {
298
- if (passedOptions === void 0) { passedOptions = DEFAULT_OPTIONS; }
299
281
  return function (_a) {
300
282
  var _b, _c, _d, _e, _f, _g;
301
283
  var component = _a.component;
302
- var options = __assign(__assign({}, DEFAULT_OPTIONS), passedOptions);
303
284
  var json = (0, fast_clone_1.fastClone)(component);
285
+ var options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, passedOptions);
286
+ options.plugins = __spreadArray(__spreadArray([], (options.plugins || []), true), [
287
+ (0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
288
+ switch (codeType) {
289
+ case 'state':
290
+ return function (c) { return c; };
291
+ case 'bindings':
292
+ case 'hooks':
293
+ case 'hooks-deps':
294
+ case 'properties':
295
+ return (0, helpers_2.updateStateCode)({
296
+ component: json,
297
+ options: options,
298
+ updateSetters: codeType === 'properties' ? false : true,
299
+ });
300
+ }
301
+ }),
302
+ ], false);
304
303
  if (options.plugins) {
305
304
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
306
305
  }
@@ -310,7 +309,6 @@ var componentToSolid = function (passedOptions) {
310
309
  if (options.plugins) {
311
310
  json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
312
311
  }
313
- preProcessComponentCode(json, options);
314
312
  (0, strip_meta_properties_1.stripMetaProperties)(json);
315
313
  var foundDynamicComponents = processDynamicComponents(json, options);
316
314
  var css = options.stylesType === 'style-tag' &&
@@ -62,9 +62,6 @@ var blockToStencil = function (json, options) {
62
62
  }
63
63
  for (var key in json.bindings) {
64
64
  var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
65
- if (key === '_forName') {
66
- continue;
67
- }
68
65
  if (type === 'spread') {
69
66
  str += " {...(".concat(code, ")} ");
70
67
  }
@@ -0,0 +1,10 @@
1
+ import { MitosisComponent } from '../../types/mitosis-component';
2
+ import { BaseNode, MitosisNode } from '../../types/mitosis-node';
3
+ import { ToSvelteOptions } from './types';
4
+ declare type BlockToSvelte<T extends BaseNode = MitosisNode> = (props: {
5
+ json: T;
6
+ options: ToSvelteOptions;
7
+ parentComponent: MitosisComponent;
8
+ }) => string;
9
+ export declare const blockToSvelte: BlockToSvelte;
10
+ export {};
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.blockToSvelte = void 0;
7
+ var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
8
+ var jsx_1 = require("../../parsers/jsx");
9
+ var is_children_1 = __importDefault(require("../../helpers/is-children"));
10
+ var remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
11
+ var slots_1 = require("../../helpers/slots");
12
+ var html_tags_1 = require("../../constants/html_tags");
13
+ var is_upper_case_1 = require("../../helpers/is-upper-case");
14
+ var for_1 = require("../../helpers/nodes/for");
15
+ var helpers_1 = require("./helpers");
16
+ var mappers = {
17
+ Fragment: function (_a) {
18
+ var _b;
19
+ var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
20
+ if ((_b = json.bindings.innerHTML) === null || _b === void 0 ? void 0 : _b.code) {
21
+ return BINDINGS_MAPPER.innerHTML(json, options);
22
+ }
23
+ else if (json.children.length > 0) {
24
+ return "".concat(json.children
25
+ .map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
26
+ .join('\n'));
27
+ }
28
+ else {
29
+ return '';
30
+ }
31
+ },
32
+ For: function (_a) {
33
+ var _b, _c;
34
+ var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
35
+ var firstChild = json.children[0];
36
+ var keyValue = firstChild.properties.key || ((_b = firstChild.bindings.key) === null || _b === void 0 ? void 0 : _b.code);
37
+ if (keyValue) {
38
+ // we remove extraneous prop which Svelte does not use
39
+ delete firstChild.properties.key;
40
+ delete firstChild.bindings.key;
41
+ }
42
+ var args = (0, for_1.getForArguments)(json, { excludeCollectionName: true }).join(', ');
43
+ return "\n{#each ".concat((0, helpers_1.stripStateAndProps)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, options), " as ").concat(args, " ").concat(keyValue ? "(".concat(keyValue, ")") : '', "}\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
44
+ },
45
+ Show: function (_a) {
46
+ var _b;
47
+ var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
48
+ return "\n{#if ".concat((0, helpers_1.stripStateAndProps)((_b = json.bindings.when) === null || _b === void 0 ? void 0 : _b.code, options), " }\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n\n ").concat(json.meta.else
49
+ ? "\n {:else}\n ".concat((0, exports.blockToSvelte)({
50
+ json: json.meta.else,
51
+ options: options,
52
+ parentComponent: parentComponent,
53
+ }), "\n ")
54
+ : '', "\n{/if}");
55
+ },
56
+ Slot: function (_a) {
57
+ var _b, _c;
58
+ var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
59
+ if (!json.bindings.name) {
60
+ var key = Object.keys(json.bindings).find(Boolean);
61
+ if (!key)
62
+ return '<slot />';
63
+ return "\n <span #".concat(key, ">\n ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code), "\n </span>\n ");
64
+ }
65
+ var strippedTextCode = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.name.code);
66
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\">").concat((_c = json.children) === null || _c === void 0 ? void 0 : _c.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "</slot>");
67
+ },
68
+ };
69
+ var BINDINGS_MAPPER = {
70
+ innerHTML: function (json, options) { var _a; return "{@html ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code), "}"); },
71
+ };
72
+ var SVELTE_SPECIAL_TAGS = {
73
+ COMPONENT: 'svelte:component',
74
+ ELEMENT: 'svelte:element',
75
+ SELF: 'svelte:self',
76
+ };
77
+ var getTagName = function (_a) {
78
+ var json = _a.json, parentComponent = _a.parentComponent;
79
+ if (parentComponent && json.name === parentComponent.name) {
80
+ return SVELTE_SPECIAL_TAGS.SELF;
81
+ }
82
+ var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name);
83
+ var isSpecialSvelteTag = json.name.startsWith('svelte:');
84
+ // Check if any import matches `json.name`
85
+ var hasMatchingImport = parentComponent.imports.some(function (_a) {
86
+ var imports = _a.imports;
87
+ return Object.keys(imports).some(function (name) { return name === json.name; });
88
+ });
89
+ // TO-DO: no way to decide between <svelte:component> and <svelte:element>...need to do that through metadata
90
+ // overrides for now
91
+ if (!isValidHtmlTag && !isSpecialSvelteTag && !hasMatchingImport) {
92
+ json.bindings.this = { code: json.name };
93
+ return SVELTE_SPECIAL_TAGS.COMPONENT;
94
+ }
95
+ return json.name;
96
+ };
97
+ var stringifyBinding = function (options) {
98
+ return function (_a) {
99
+ var key = _a[0], binding = _a[1];
100
+ if (key === 'innerHTML' || !binding) {
101
+ return '';
102
+ }
103
+ var code = binding.code, _b = binding.arguments, cusArgs = _b === void 0 ? ['event'] : _b, type = binding.type;
104
+ var useValue = (0, helpers_1.stripStateAndProps)(code, options);
105
+ if (type === 'spread') {
106
+ var spreadValue = key === 'props' ? '$$props' : useValue;
107
+ return " {...".concat(spreadValue, "} ");
108
+ }
109
+ else if (key.startsWith('on')) {
110
+ var event_1 = key.replace('on', '').toLowerCase();
111
+ // TODO: handle quotes in event handler values
112
+ var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
113
+ if (valueWithoutBlock === key) {
114
+ return " on:".concat(event_1, "={").concat(valueWithoutBlock, "} ");
115
+ }
116
+ else {
117
+ return " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat(valueWithoutBlock, "}}\" ");
118
+ }
119
+ }
120
+ else if (key === 'ref') {
121
+ return " bind:this={".concat(useValue, "} ");
122
+ }
123
+ else {
124
+ return " ".concat(key, "={").concat(useValue, "} ");
125
+ }
126
+ };
127
+ };
128
+ var blockToSvelte = function (_a) {
129
+ var _b, _c, _d, _e;
130
+ var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
131
+ if (mappers[json.name]) {
132
+ return mappers[json.name]({
133
+ json: json,
134
+ options: options,
135
+ parentComponent: parentComponent,
136
+ });
137
+ }
138
+ var tagName = getTagName({ json: json, parentComponent: parentComponent });
139
+ if ((0, is_children_1.default)(json)) {
140
+ return "<slot></slot>";
141
+ }
142
+ if (json.properties._text) {
143
+ return json.properties._text;
144
+ }
145
+ var textCode = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code;
146
+ if (textCode) {
147
+ var strippedTextCode = (0, helpers_1.stripStateAndProps)(textCode, options);
148
+ if ((0, slots_1.isSlotProperty)(strippedTextCode)) {
149
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\"/>");
150
+ }
151
+ return "{".concat(strippedTextCode, "}");
152
+ }
153
+ var str = '';
154
+ str += "<".concat(tagName, " ");
155
+ var isComponent = Boolean(tagName[0] && (0, is_upper_case_1.isUpperCase)(tagName[0]));
156
+ if ((((_c = json.bindings.style) === null || _c === void 0 ? void 0 : _c.code) || json.properties.style) && !isComponent) {
157
+ var useValue = (0, helpers_1.stripStateAndProps)(((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style, options);
158
+ str += "use:mitosis_styling={".concat(useValue, "}");
159
+ delete json.bindings.style;
160
+ delete json.properties.style;
161
+ }
162
+ for (var key in json.properties) {
163
+ var value = json.properties[key];
164
+ str += " ".concat(key, "=\"").concat(value, "\" ");
165
+ }
166
+ var stringifiedBindings = Object.entries(json.bindings).map(stringifyBinding(options)).join('');
167
+ str += stringifiedBindings;
168
+ // if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
169
+ // we use the innerHTML content as children and don't render the self-closing tag.
170
+ if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
171
+ str += '>';
172
+ str += BINDINGS_MAPPER.innerHTML(json, options);
173
+ str += "</".concat(tagName, ">");
174
+ return str;
175
+ }
176
+ if (jsx_1.selfClosingTags.has(tagName)) {
177
+ return str + ' />';
178
+ }
179
+ str += '>';
180
+ if (json.children) {
181
+ str += json.children
182
+ .map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
183
+ .join('');
184
+ }
185
+ str += "</".concat(tagName, ">");
186
+ return str;
187
+ };
188
+ exports.blockToSvelte = blockToSvelte;
@@ -0,0 +1,2 @@
1
+ import { ToSvelteOptions } from './types';
2
+ export declare const stripStateAndProps: (code: string | undefined, options: ToSvelteOptions) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripStateAndProps = void 0;
4
+ var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
5
+ var stripStateAndProps = function (code, options) {
6
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
7
+ includeState: options.stateType === 'variables',
8
+ replaceWith: function (name) { return (name === 'children' ? '$$slots.default' : name); },
9
+ });
10
+ };
11
+ exports.stripStateAndProps = stripStateAndProps;
@@ -0,0 +1 @@
1
+ export { componentToSvelte } from './svelte';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.componentToSvelte = void 0;
4
+ var svelte_1 = require("./svelte");
5
+ Object.defineProperty(exports, "componentToSvelte", { enumerable: true, get: function () { return svelte_1.componentToSvelte; } });