@builder.io/mitosis 0.0.63 → 0.0.65

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 (167) hide show
  1. package/dist/src/constants/html_tags.js +63 -0
  2. package/dist/src/flow.d.ts +3 -0
  3. package/dist/src/flow.js +5 -1
  4. package/dist/src/generators/angular.d.ts +1 -0
  5. package/dist/src/generators/angular.js +33 -10
  6. package/dist/src/generators/react/generator.js +4 -2
  7. package/dist/src/generators/react-native.js +51 -34
  8. package/dist/src/generators/svelte.js +7 -3
  9. package/dist/src/index.d.ts +1 -0
  10. package/dist/src/index.js +1 -0
  11. package/dist/src/types/config.d.ts +3 -1
  12. package/dist/tsconfig.build.tsbuildinfo +1 -1
  13. package/package.json +1 -1
  14. package/dist/src/__tests__/data/advanced-ref.raw.d.ts +0 -4
  15. package/dist/src/__tests__/data/advanced-ref.raw.jsx +0 -39
  16. package/dist/src/__tests__/data/basic-boolean-attribute-component.raw.d.ts +0 -6
  17. package/dist/src/__tests__/data/basic-boolean-attribute-component.raw.jsx +0 -8
  18. package/dist/src/__tests__/data/basic-boolean-attribute.raw.d.ts +0 -6
  19. package/dist/src/__tests__/data/basic-boolean-attribute.raw.jsx +0 -15
  20. package/dist/src/__tests__/data/basic-child-component.raw.d.ts +0 -1
  21. package/dist/src/__tests__/data/basic-child-component.raw.jsx +0 -21
  22. package/dist/src/__tests__/data/basic-context.raw.d.ts +0 -1
  23. package/dist/src/__tests__/data/basic-context.raw.jsx +0 -29
  24. package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.d.ts +0 -1
  25. package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.jsx +0 -10
  26. package/dist/src/__tests__/data/basic-for-show.raw.d.ts +0 -1
  27. package/dist/src/__tests__/data/basic-for-show.raw.jsx +0 -20
  28. package/dist/src/__tests__/data/basic-for.raw.d.ts +0 -1
  29. package/dist/src/__tests__/data/basic-for.raw.jsx +0 -23
  30. package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.d.ts +0 -5
  31. package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.jsx +0 -17
  32. package/dist/src/__tests__/data/basic-forwardRef.raw.d.ts +0 -5
  33. package/dist/src/__tests__/data/basic-forwardRef.raw.jsx +0 -14
  34. package/dist/src/__tests__/data/basic-onChange.raw.d.ts +0 -1
  35. package/dist/src/__tests__/data/basic-onChange.raw.jsx +0 -17
  36. package/dist/src/__tests__/data/basic-onMount-update.raw.d.ts +0 -5
  37. package/dist/src/__tests__/data/basic-onMount-update.raw.jsx +0 -17
  38. package/dist/src/__tests__/data/basic-onUpdate-return.raw.d.ts +0 -1
  39. package/dist/src/__tests__/data/basic-onUpdate-return.raw.jsx +0 -24
  40. package/dist/src/__tests__/data/basic-outputs-meta.raw.d.ts +0 -1
  41. package/dist/src/__tests__/data/basic-outputs-meta.raw.jsx +0 -17
  42. package/dist/src/__tests__/data/basic-outputs.raw.d.ts +0 -1
  43. package/dist/src/__tests__/data/basic-outputs.raw.jsx +0 -14
  44. package/dist/src/__tests__/data/basic-preserve-export-or-local-statement.raw.d.ts +0 -6
  45. package/dist/src/__tests__/data/basic-preserve-export-or-local-statement.raw.jsx +0 -14
  46. package/dist/src/__tests__/data/basic-props-destructure.raw.d.ts +0 -6
  47. package/dist/src/__tests__/data/basic-props-destructure.raw.jsx +0 -14
  48. package/dist/src/__tests__/data/basic-props.raw.d.ts +0 -6
  49. package/dist/src/__tests__/data/basic-props.raw.jsx +0 -13
  50. package/dist/src/__tests__/data/basic-ref-assignment.raw.d.ts +0 -4
  51. package/dist/src/__tests__/data/basic-ref-assignment.raw.jsx +0 -15
  52. package/dist/src/__tests__/data/basic-ref-usePrevious.raw.d.ts +0 -5
  53. package/dist/src/__tests__/data/basic-ref-usePrevious.raw.jsx +0 -35
  54. package/dist/src/__tests__/data/basic-ref.raw.d.ts +0 -4
  55. package/dist/src/__tests__/data/basic-ref.raw.jsx +0 -36
  56. package/dist/src/__tests__/data/basic.raw.d.ts +0 -6
  57. package/dist/src/__tests__/data/basic.raw.jsx +0 -22
  58. package/dist/src/__tests__/data/blocks/button-with-metadata.raw.d.ts +0 -7
  59. package/dist/src/__tests__/data/blocks/button-with-metadata.raw.jsx +0 -23
  60. package/dist/src/__tests__/data/blocks/button.raw.d.ts +0 -7
  61. package/dist/src/__tests__/data/blocks/button.raw.jsx +0 -18
  62. package/dist/src/__tests__/data/blocks/classname-jsx.raw.d.ts +0 -7
  63. package/dist/src/__tests__/data/blocks/classname-jsx.raw.jsx +0 -15
  64. package/dist/src/__tests__/data/blocks/columns.raw.d.ts +0 -12
  65. package/dist/src/__tests__/data/blocks/columns.raw.jsx +0 -42
  66. package/dist/src/__tests__/data/blocks/content-slot-html.raw.d.ts +0 -7
  67. package/dist/src/__tests__/data/blocks/content-slot-html.raw.jsx +0 -15
  68. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.d.ts +0 -6
  69. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.jsx +0 -15
  70. package/dist/src/__tests__/data/blocks/custom-code.raw.d.ts +0 -5
  71. package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +0 -48
  72. package/dist/src/__tests__/data/blocks/embed.raw.d.ts +0 -4
  73. package/dist/src/__tests__/data/blocks/embed.raw.jsx +0 -48
  74. package/dist/src/__tests__/data/blocks/form.raw.d.ts +0 -25
  75. package/dist/src/__tests__/data/blocks/form.raw.jsx +0 -272
  76. package/dist/src/__tests__/data/blocks/image.raw.d.ts +0 -15
  77. package/dist/src/__tests__/data/blocks/image.raw.jsx +0 -65
  78. package/dist/src/__tests__/data/blocks/img-state.raw.d.ts +0 -1
  79. package/dist/src/__tests__/data/blocks/img-state.raw.jsx +0 -17
  80. package/dist/src/__tests__/data/blocks/img.raw.d.ts +0 -9
  81. package/dist/src/__tests__/data/blocks/img.raw.jsx +0 -11
  82. package/dist/src/__tests__/data/blocks/input.raw.d.ts +0 -11
  83. package/dist/src/__tests__/data/blocks/input.raw.jsx +0 -8
  84. package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.d.ts +0 -1
  85. package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.jsx +0 -13
  86. package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.d.ts +0 -1
  87. package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +0 -25
  88. package/dist/src/__tests__/data/blocks/onInit-onMount.raw.d.ts +0 -1
  89. package/dist/src/__tests__/data/blocks/onInit-onMount.raw.jsx +0 -13
  90. package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +0 -8
  91. package/dist/src/__tests__/data/blocks/onInit.raw.jsx +0 -20
  92. package/dist/src/__tests__/data/blocks/onMount.raw.d.ts +0 -1
  93. package/dist/src/__tests__/data/blocks/onMount.raw.jsx +0 -13
  94. package/dist/src/__tests__/data/blocks/onUpdate.raw.d.ts +0 -1
  95. package/dist/src/__tests__/data/blocks/onUpdate.raw.jsx +0 -10
  96. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +0 -5
  97. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +0 -14
  98. package/dist/src/__tests__/data/blocks/raw-text.raw.d.ts +0 -5
  99. package/dist/src/__tests__/data/blocks/raw-text.raw.jsx +0 -7
  100. package/dist/src/__tests__/data/blocks/root-fragment-multi-node.raw.d.ts +0 -7
  101. package/dist/src/__tests__/data/blocks/root-fragment-multi-node.raw.jsx +0 -18
  102. package/dist/src/__tests__/data/blocks/rootShow.raw.d.ts +0 -3
  103. package/dist/src/__tests__/data/blocks/rootShow.raw.jsx +0 -9
  104. package/dist/src/__tests__/data/blocks/section-state.raw.d.ts +0 -6
  105. package/dist/src/__tests__/data/blocks/section-state.raw.jsx +0 -17
  106. package/dist/src/__tests__/data/blocks/section.raw.d.ts +0 -7
  107. package/dist/src/__tests__/data/blocks/section.raw.jsx +0 -11
  108. package/dist/src/__tests__/data/blocks/select.raw.d.ts +0 -11
  109. package/dist/src/__tests__/data/blocks/select.raw.jsx +0 -14
  110. package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.d.ts +0 -1
  111. package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.jsx +0 -15
  112. package/dist/src/__tests__/data/blocks/self-referencing-component.raw.d.ts +0 -1
  113. package/dist/src/__tests__/data/blocks/self-referencing-component.raw.jsx +0 -12
  114. package/dist/src/__tests__/data/blocks/shadow-dom.raw.d.ts +0 -6
  115. package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +0 -52
  116. package/dist/src/__tests__/data/blocks/slot-html.raw.d.ts +0 -5
  117. package/dist/src/__tests__/data/blocks/slot-html.raw.jsx +0 -15
  118. package/dist/src/__tests__/data/blocks/slot-jsx.raw.d.ts +0 -5
  119. package/dist/src/__tests__/data/blocks/slot-jsx.raw.jsx +0 -12
  120. package/dist/src/__tests__/data/blocks/stamped-io.raw.d.ts +0 -6
  121. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +0 -60
  122. package/dist/src/__tests__/data/blocks/submit-button.raw.d.ts +0 -6
  123. package/dist/src/__tests__/data/blocks/submit-button.raw.jsx +0 -9
  124. package/dist/src/__tests__/data/blocks/text.raw.d.ts +0 -8
  125. package/dist/src/__tests__/data/blocks/text.raw.jsx +0 -19
  126. package/dist/src/__tests__/data/blocks/textarea.raw.d.ts +0 -8
  127. package/dist/src/__tests__/data/blocks/textarea.raw.jsx +0 -6
  128. package/dist/src/__tests__/data/blocks/video.raw.d.ts +0 -17
  129. package/dist/src/__tests__/data/blocks/video.raw.jsx +0 -21
  130. package/dist/src/__tests__/data/context/component-with-context.lite.d.ts +0 -3
  131. package/dist/src/__tests__/data/context/component-with-context.lite.jsx +0 -21
  132. package/dist/src/__tests__/data/context/simple.context.lite.d.ts +0 -9
  133. package/dist/src/__tests__/data/context/simple.context.lite.js +0 -15
  134. package/dist/src/__tests__/data/default-props/default-props.raw.d.ts +0 -7
  135. package/dist/src/__tests__/data/default-props/default-props.raw.jsx +0 -23
  136. package/dist/src/__tests__/data/jsx-json.spec.d.ts +0 -2
  137. package/dist/src/__tests__/data/jsx-json.spec.js +0 -10226
  138. package/dist/src/__tests__/data/nested-styles.lite.d.ts +0 -1
  139. package/dist/src/__tests__/data/nested-styles.lite.jsx +0 -20
  140. package/dist/src/__tests__/data/show/nested-show.raw.d.ts +0 -6
  141. package/dist/src/__tests__/data/show/nested-show.raw.jsx +0 -11
  142. package/dist/src/__tests__/data/show/show-with-for.raw.d.ts +0 -6
  143. package/dist/src/__tests__/data/show/show-with-for.raw.jsx +0 -9
  144. package/dist/src/__tests__/data/styles/class-and-className.raw.d.ts +0 -1
  145. package/dist/src/__tests__/data/styles/class-and-className.raw.jsx +0 -10
  146. package/dist/src/__tests__/data/styles/class.raw.d.ts +0 -1
  147. package/dist/src/__tests__/data/styles/class.raw.jsx +0 -10
  148. package/dist/src/__tests__/data/styles/className.raw.d.ts +0 -1
  149. package/dist/src/__tests__/data/styles/className.raw.jsx +0 -10
  150. package/dist/src/__tests__/data/styles/classState.raw.d.ts +0 -1
  151. package/dist/src/__tests__/data/styles/classState.raw.jsx +0 -13
  152. package/dist/src/__tests__/data/types/component-props-interface.raw.d.ts +0 -6
  153. package/dist/src/__tests__/data/types/component-props-interface.raw.jsx +0 -6
  154. package/dist/src/__tests__/data/types/component-props-type.raw.d.ts +0 -6
  155. package/dist/src/__tests__/data/types/component-props-type.raw.jsx +0 -6
  156. package/dist/src/__tests__/data/types/component-with-default-values-types.raw.d.ts +0 -5
  157. package/dist/src/__tests__/data/types/component-with-default-values-types.raw.jsx +0 -9
  158. package/dist/src/__tests__/data/types/foo-type.d.ts +0 -1
  159. package/dist/src/__tests__/data/types/foo-type.js +0 -2
  160. package/dist/src/__tests__/data/types/preserve-typing.raw.d.ts +0 -8
  161. package/dist/src/__tests__/data/types/preserve-typing.raw.jsx +0 -6
  162. package/dist/src/__tests__/data/types/type-dependency.raw.d.ts +0 -7
  163. package/dist/src/__tests__/data/types/type-dependency.raw.jsx +0 -6
  164. package/dist/src/__tests__/data/types/type-export.lite.d.ts +0 -3
  165. package/dist/src/__tests__/data/types/type-export.lite.jsx +0 -6
  166. package/dist/src/__tests__/shared.d.ts +0 -8
  167. package/dist/src/__tests__/shared.js +0 -369
@@ -116,4 +116,67 @@ exports.VALID_HTML_TAGS = [
116
116
  'summary',
117
117
  'slot',
118
118
  'template',
119
+ // tags below are SVG tags. See the below article for list of SVG tags
120
+ // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
121
+ 'animate',
122
+ 'animateMotion',
123
+ 'animateTransform',
124
+ 'circle',
125
+ 'clipPath',
126
+ 'defs',
127
+ 'desc',
128
+ 'discard',
129
+ 'ellipse',
130
+ 'feBlend',
131
+ 'feColorMatrix',
132
+ 'feComponentTransfer',
133
+ 'feComposite',
134
+ 'feConvolveMatrix',
135
+ 'feDiffuseLighting',
136
+ 'feDisplacementMap',
137
+ 'feDistantLight',
138
+ 'feDropShadow',
139
+ 'feFlood',
140
+ 'feFuncA',
141
+ 'feFuncB',
142
+ 'feFuncG',
143
+ 'feFuncR',
144
+ 'feGaussianBlur',
145
+ 'feImage',
146
+ 'feMerge',
147
+ 'feMergeNode',
148
+ 'feMorphology',
149
+ 'feOffset',
150
+ 'fePointLight',
151
+ 'feSpecularLighting',
152
+ 'feSpotLight',
153
+ 'feTile',
154
+ 'feTurbulence',
155
+ 'filter',
156
+ 'foreignObject',
157
+ 'g',
158
+ 'hatch',
159
+ 'hatchpath',
160
+ 'image',
161
+ 'line',
162
+ 'linearGradient',
163
+ 'marker',
164
+ 'mask',
165
+ 'metadata',
166
+ 'mpath',
167
+ 'path',
168
+ 'pattern',
169
+ 'polygon',
170
+ 'polyline',
171
+ 'radialGradient',
172
+ 'rect',
173
+ 'set',
174
+ 'stop',
175
+ 'switch',
176
+ 'symbol',
177
+ 'text',
178
+ 'textPath',
179
+ 'tspan',
180
+ 'use',
181
+ 'view',
119
182
  ];
@@ -21,3 +21,6 @@ export declare function Show<T>(props: {
21
21
  else?: JSX.Element;
22
22
  children?: JSX.Element | null;
23
23
  }): any;
24
+ export declare function Fragment(props: {
25
+ children: JSX.Element | JSX.Element[];
26
+ }): any;
package/dist/src/flow.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Show = exports.Slot = exports.For = void 0;
3
+ exports.Fragment = exports.Show = exports.Slot = exports.For = void 0;
4
4
  /**
5
5
  * Flow control based on Solid
6
6
  *
@@ -21,3 +21,7 @@ function Show(props) {
21
21
  return null;
22
22
  }
23
23
  exports.Show = Show;
24
+ function Fragment(props) {
25
+ return null;
26
+ }
27
+ exports.Fragment = Fragment;
@@ -2,6 +2,7 @@ import { MitosisNode } from '../types/mitosis-node';
2
2
  import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
3
3
  export interface ToAngularOptions extends BaseTranspilerOptions {
4
4
  standalone?: boolean;
5
+ preserveImports?: boolean;
5
6
  }
6
7
  interface AngularBlockOptions {
7
8
  contextVars?: string[];
@@ -3,6 +3,17 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
3
3
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
4
  return cooked;
5
5
  };
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
6
17
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
7
18
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
8
19
  if (ar || !(i in from)) {
@@ -202,11 +213,15 @@ var blockToAngular = function (json, options, blockOptions) {
202
213
  return str;
203
214
  };
204
215
  exports.blockToAngular = blockToAngular;
205
- var componentToAngular = function (options) {
206
- if (options === void 0) { options = {}; }
216
+ var componentToAngular = function (userOptions) {
217
+ if (userOptions === void 0) { userOptions = {}; }
207
218
  return function (_a) {
208
219
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
209
220
  var _component = _a.component;
221
+ var DEFAULT_OPTIONS = {
222
+ preserveImports: false,
223
+ };
224
+ var options = __assign(__assign({}, DEFAULT_OPTIONS), userOptions);
210
225
  // Make a copy we can safely mutate, similar to babel's toolchain
211
226
  var json = (0, fast_clone_1.fastClone)(_component);
212
227
  if (options.plugins) {
@@ -301,16 +316,24 @@ var componentToAngular = function (options) {
301
316
  });
302
317
  },
303
318
  });
304
- 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 selector: '", "',\n template: `\n ", "\n `,\n ", "\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 selector: '", "',\n template: \\`\n ", "\n \\`,\n ", "\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)({
319
+ // Preparing built in component metadata parameters
320
+ 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 ? { styles: "[`".concat((0, indent_1.indent)(css, 8), "`]") } : {})), (options.standalone
321
+ ? // TODO: also add child component imports here as well
322
+ {
323
+ standalone: 'true',
324
+ imports: "[".concat(__spreadArray(['CommonModule'], componentsUsed, true).join(', '), "]"),
325
+ }
326
+ : {}));
327
+ // Taking into consideration what user has passed in options and allowing them to override the default generated metadata
328
+ Object.entries(json.meta.angularConfig || {}).forEach(function (_a) {
329
+ var key = _a[0], value = _a[1];
330
+ componentMetadata[key] = value;
331
+ });
332
+ 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)({
305
333
  component: json,
306
334
  target: 'angular',
307
- excludeMitosisComponents: !options.standalone,
308
- }), options.standalone
309
- ? // TODO: also add child component imports here as well
310
- "\n standalone: true,\n imports: [CommonModule".concat(componentsUsed.length ? ", ".concat(componentsUsed.join(', ')) : '', "],\n ")
311
- : '', (0, lodash_1.kebabCase)(json.name || 'my-component'), (0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), css.length
312
- ? "styles: [\n `".concat((0, indent_1.indent)(css, 8), "`\n ],")
313
- : '', Object.entries(json.meta.angularConfig || {})
335
+ excludeMitosisComponents: !options.standalone && !options.preserveImports,
336
+ }), Object.entries(componentMetadata)
314
337
  .map(function (_a) {
315
338
  var k = _a[0], v = _a[1];
316
339
  return "".concat(k, ": ").concat(v);
@@ -83,7 +83,6 @@ var NODE_MAPPERS = {
83
83
  },
84
84
  Fragment: function (json, options) {
85
85
  var wrap = wrapInFragment(json);
86
- var tagName = options.preact ? 'Fragment' : '';
87
86
  return "".concat(wrap ? getFragment('open', options) : '').concat(json.children
88
87
  .map(function (item) { return (0, exports.blockToReact)(item, options); })
89
88
  .join('\n')).concat(wrap ? getFragment('close', options) : '');
@@ -409,7 +408,10 @@ var _componentToReact = function (json, options, isSubComponent) {
409
408
  ? "/** @jsx jsx */\n import { jsx } from '@emotion/react'".trim()
410
409
  : '', hasState && stateType === 'valtio' ? "import { useLocalProxy } from 'valtio/utils';" : '', hasState && stateType === 'solid' ? "import { useMutable } from 'react-solid-state';" : '', stateType === 'mobx' && hasState
411
410
  ? "import { useLocalObservable } from 'mobx-react-lite';"
412
- : '', json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({ component: json, target: 'react' }), isSubComponent ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', hasStateArgument ? '' : refsString, hasState
411
+ : '', json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
412
+ component: json,
413
+ target: options.type === 'native' ? 'reactNative' : 'react',
414
+ }), isSubComponent ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', hasStateArgument ? '' : refsString, hasState
413
415
  ? stateType === 'mobx'
414
416
  ? "const state = useLocalObservable(() => (".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), "));")
415
417
  : stateType === 'useState'
@@ -10,6 +10,15 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
13
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
24
  };
@@ -66,45 +75,53 @@ var collectReactNativeStyles = function (json) {
66
75
  return styleMap;
67
76
  };
68
77
  exports.collectReactNativeStyles = collectReactNativeStyles;
69
- // Plugin to convert DOM tags to <View /> and <Text />
70
- function processReactNative() {
71
- return function () { return ({
72
- json: {
73
- pre: function (json) {
74
- (0, traverse_1.default)(json).forEach(function (node) {
75
- var _a, _b, _c, _d;
76
- if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
77
- // TODO: handle TextInput, Image, etc
78
- if (node.name.toLowerCase() === node.name) {
79
- node.name = 'View';
80
- }
81
- if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) || ((_d = (_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.length)) {
82
- node.name = 'Text';
83
- }
84
- if (node.properties.class) {
85
- delete node.properties.class;
86
- }
87
- if (node.properties.className) {
88
- delete node.properties.className;
89
- }
90
- if (node.bindings.class) {
91
- delete node.bindings.class;
92
- }
93
- if (node.bindings.className) {
94
- delete node.bindings.className;
95
- }
78
+ /**
79
+ * Plugin that handles necessary transformations from React to React Native:
80
+ * - Converts DOM tags to <View /> and <Text />
81
+ * - Removes redundant `class`/`className` attributes
82
+ */
83
+ var PROCESS_REACT_NATIVE_PLUGIN = function () { return ({
84
+ json: {
85
+ pre: function (json) {
86
+ (0, traverse_1.default)(json).forEach(function (node) {
87
+ var _a, _b, _c, _d;
88
+ if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
89
+ // TODO: handle TextInput, Image, etc
90
+ if (node.name.toLowerCase() === node.name) {
91
+ node.name = 'View';
92
+ }
93
+ if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) || ((_d = (_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.length)) {
94
+ node.name = 'Text';
95
+ }
96
+ if (node.properties.class) {
97
+ delete node.properties.class;
98
+ }
99
+ if (node.properties.className) {
100
+ delete node.properties.className;
96
101
  }
97
- });
98
- },
102
+ if (node.bindings.class) {
103
+ delete node.bindings.class;
104
+ }
105
+ if (node.bindings.className) {
106
+ delete node.bindings.className;
107
+ }
108
+ }
109
+ });
99
110
  },
100
- }); };
101
- }
102
- var componentToReactNative = function (options) {
103
- if (options === void 0) { options = {}; }
111
+ },
112
+ }); };
113
+ var DEFAULT_OPTIONS = {
114
+ stateType: 'useState',
115
+ stylesType: 'react-native',
116
+ plugins: [PROCESS_REACT_NATIVE_PLUGIN],
117
+ };
118
+ var componentToReactNative = function (_options) {
119
+ if (_options === void 0) { _options = {}; }
104
120
  return function (_a) {
105
121
  var component = _a.component, path = _a.path;
106
122
  var json = (0, fast_clone_1.fastClone)(component);
107
- return (0, react_1.componentToReact)(__assign(__assign({}, options), { plugins: (options.plugins || []).concat([processReactNative()]), stylesType: options.stylesType || 'react-native', type: 'native' }))({ component: json, path: path });
123
+ var options = __assign(__assign(__assign({}, DEFAULT_OPTIONS), _options), { plugins: __spreadArray(__spreadArray([], (DEFAULT_OPTIONS.plugins || []), true), (_options.plugins || []), true), type: 'native' });
124
+ return (0, react_1.componentToReact)(options)({ component: json, path: path });
108
125
  };
109
126
  };
110
127
  exports.componentToReactNative = componentToReactNative;
@@ -363,7 +363,9 @@ var componentToSvelte = function (_a) {
363
363
  if ((0, context_1.hasContext)(component)) {
364
364
  svelteImports.push('getContext', 'setContext');
365
365
  }
366
- str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
366
+ str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n "
367
+ // https://svelte.dev/repl/bd9b56891f04414982517bbd10c52c82?version=3.31.0
368
+ , "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
367
369
  .map(function (name) {
368
370
  if (name === 'children') {
369
371
  return '';
@@ -378,8 +380,10 @@ var componentToSvelte = function (_a) {
378
380
  propDeclaration += ';';
379
381
  return propDeclaration;
380
382
  })
381
- .join('\n'), (0, helpers_1.hasStyle)(json)
382
- ? "\n function mitosis_styling (node, vars) {\n Object.entries(vars || {}).forEach(([ p, v ]) => { node.style[p] = v })\n }\n "
383
+ .join('\n'),
384
+ // https://svelte.dev/repl/bd9b56891f04414982517bbd10c52c82?version=3.31.0
385
+ (0, helpers_1.hasStyle)(json)
386
+ ? "\n function mitosis_styling (node, vars) {\n Object.entries(vars || {}).forEach(([ p, v ]) => {\n if (p.startsWith('--')) {\n node.style.setProperty(p, v);\n } else {\n node.style[p] = v;\n }\n })\n }\n "
383
387
  : '', getContextCode(json), setContextCode(json), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, refs.map(function (ref) { return "let ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref)); }).join('\n'), options.stateType === 'proxies'
384
388
  ? dataString.length < 4
385
389
  ? ''
@@ -54,6 +54,7 @@ export * from './types/mitosis-node';
54
54
  export * from './types/mitosis-component';
55
55
  export * from './types/config';
56
56
  export * from './types/transpiler';
57
+ export * from './types/plugins';
57
58
  export * from './plugins/compile-away-builder-components';
58
59
  export * from './plugins/compile-away-components';
59
60
  export * from './plugins/map-styles';
package/dist/src/index.js CHANGED
@@ -95,6 +95,7 @@ __exportStar(require("./types/mitosis-node"), exports);
95
95
  __exportStar(require("./types/mitosis-component"), exports);
96
96
  __exportStar(require("./types/config"), exports);
97
97
  __exportStar(require("./types/transpiler"), exports);
98
+ __exportStar(require("./types/plugins"), exports);
98
99
  __exportStar(require("./plugins/compile-away-builder-components"), exports);
99
100
  __exportStar(require("./plugins/compile-away-components"), exports);
100
101
  __exportStar(require("./plugins/map-styles"), exports);
@@ -64,6 +64,8 @@ export declare type MitosisConfig = {
64
64
  * Configure a custom function that provides the output path for each target.
65
65
  * If you provide this function, you must provide a value for every target yourself.
66
66
  */
67
- getTargetPath?: (target: Target) => string;
67
+ getTargetPath: ({ target }: {
68
+ target: Target;
69
+ }) => string;
68
70
  };
69
71
  export {};