@builder.io/mitosis 0.0.56-21 → 0.0.56-24

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 (32) hide show
  1. package/dist/src/__tests__/data/blocks/classname-jsx.raw.d.ts +1 -1
  2. package/dist/src/__tests__/data/blocks/content-slot-html.raw.d.ts +1 -1
  3. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.d.ts +1 -1
  4. package/dist/src/__tests__/data/blocks/image.raw.d.ts +1 -1
  5. package/dist/src/__tests__/data/blocks/image.raw.jsx +1 -1
  6. package/dist/src/__tests__/data/show/nested-show.raw copy.d.ts +6 -0
  7. package/dist/src/__tests__/data/show/nested-show.raw copy.jsx +11 -0
  8. package/dist/src/__tests__/data/show/nested-show.raw.d.ts +6 -0
  9. package/dist/src/__tests__/data/show/nested-show.raw.jsx +11 -0
  10. package/dist/src/__tests__/data/show/show-with-for.raw.d.ts +6 -0
  11. package/dist/src/__tests__/data/show/show-with-for.raw.jsx +9 -0
  12. package/dist/src/__tests__/data/styles/classState.raw.jsx +2 -1
  13. package/dist/src/__tests__/shared.js +66 -47
  14. package/dist/src/flow.d.ts +1 -1
  15. package/dist/src/generators/angular.js +4 -2
  16. package/dist/src/generators/react.js +2 -1
  17. package/dist/src/generators/svelte.js +38 -9
  18. package/dist/src/generators/vue.d.ts +5 -1
  19. package/dist/src/generators/vue.js +94 -33
  20. package/dist/src/helpers/babel-transform.js +2 -2
  21. package/dist/src/helpers/is-children.js +2 -1
  22. package/dist/src/helpers/slots.d.ts +1 -0
  23. package/dist/src/helpers/slots.js +6 -0
  24. package/dist/src/helpers/styles/helpers.d.ts +2 -2
  25. package/dist/src/parsers/jsx.js +5 -1
  26. package/dist/src/types/mitosis-node.d.ts +3 -3
  27. package/dist/tsconfig.build.tsbuildinfo +1 -1
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/jsx-runtime.d.ts +1837 -0
  30. package/package.json +5 -4
  31. package/dist/src/jsx-types.d.ts +0 -1173
  32. package/dist/src/jsx-types.js +0 -10
@@ -1,4 +1,4 @@
1
- import type { JSX } from '../../../jsx-types';
1
+ import type { JSX } from '../../../../jsx-runtime';
2
2
  declare type Props = {
3
3
  [key: string]: string | JSX.Element;
4
4
  slotTesting: JSX.Element;
@@ -1,4 +1,4 @@
1
- import type { JSX } from '../../../jsx-types';
1
+ import type { JSX } from '../../../../jsx-runtime';
2
2
  declare type Props = {
3
3
  [key: string]: string | JSX.Element;
4
4
  slotTesting: JSX.Element;
@@ -1,4 +1,4 @@
1
- import type { JSX } from '../../../jsx-types';
1
+ import type { JSX } from '../../../../jsx-runtime';
2
2
  declare type Props = {
3
3
  [key: string]: string | JSX.Element;
4
4
  };
@@ -1,5 +1,5 @@
1
1
  export interface ImageProps {
2
- class?: string;
2
+ _class?: string;
3
3
  image: string;
4
4
  sizes?: string;
5
5
  lazy?: boolean;
@@ -53,7 +53,7 @@ function Image(props) {
53
53
  transition: 'opacity 0.2s ease-in-out',
54
54
  objectFit: 'cover',
55
55
  objectPosition: 'center',
56
- }} class={'builder-image' + (props.class ? ' ' + props.class : '')} src={props.image} onLoad={function () { return state.setLoaded(); }}
56
+ }} class={'builder-image' + (props._class ? ' ' + props._class : '')} src={props.image} onLoad={function () { return state.setLoaded(); }}
57
57
  // TODO: memoize on image on client
58
58
  srcset={props.srcset} sizes={props.sizes}/>
59
59
  </mitosis_1.Show>
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ conditionA: boolean;
3
+ conditionB: boolean;
4
+ }
5
+ export default function NestedShow(props: Props): import("@builder.io/mitosis/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var mitosis_1 = require("@builder.io/mitosis");
4
+ function NestedShow(props) {
5
+ return (<mitosis_1.Show when={props.conditionA} else={<div>else-condition-A</div>}>
6
+ <mitosis_1.Show when={!props.conditionB} else={<div>else-condition-B</div>}>
7
+ <div>if condition A and condition B</div>
8
+ </mitosis_1.Show>
9
+ </mitosis_1.Show>);
10
+ }
11
+ exports.default = NestedShow;
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ conditionA: boolean;
3
+ conditionB: boolean;
4
+ }
5
+ export default function NestedShow(props: Props): import("@builder.io/mitosis/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var mitosis_1 = require("@builder.io/mitosis");
4
+ function NestedShow(props) {
5
+ return (<mitosis_1.Show when={props.conditionA} else={<div>else-condition-A</div>}>
6
+ <mitosis_1.Show when={!props.conditionB} else={<div>else-condition-B</div>}>
7
+ <div>if condition A and condition B</div>
8
+ </mitosis_1.Show>
9
+ </mitosis_1.Show>);
10
+ }
11
+ exports.default = NestedShow;
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ conditionA: boolean;
3
+ items: string[];
4
+ }
5
+ export default function NestedShow(props: Props): import("@builder.io/mitosis/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var mitosis_1 = require("@builder.io/mitosis");
4
+ function NestedShow(props) {
5
+ return (<mitosis_1.Show when={props.conditionA} else={<div>else-condition-A</div>}>
6
+ <mitosis_1.For each={props.items}>{function (item, idx) { return <div key={idx}>{item}</div>; }}</mitosis_1.For>
7
+ </mitosis_1.Show>);
8
+ }
9
+ exports.default = NestedShow;
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var mitosis_1 = require("@builder.io/mitosis");
4
4
  function MyBasicComponent() {
5
5
  var _a = (0, mitosis_1.useState)('testClassName'), classState = _a[0], setClassState = _a[1];
6
+ var _b = (0, mitosis_1.useState)({ color: 'red' }), styleState = _b[0], setStyleState = _b[1];
6
7
  return (<div class={classState} css={{
7
8
  padding: '10px',
8
- }}>
9
+ }} style={styleState}>
9
10
  Hello! I can run in React, Vue, Solid, or Liquid!
10
11
  </div>);
11
12
  }
@@ -4,13 +4,9 @@ exports.runTestsForTarget = void 0;
4
4
  var jsx_1 = require("../parsers/jsx");
5
5
  var basicForShow = require('./data/basic-for-show.raw');
6
6
  var basicOnMountUpdate = require('./data/basic-onMount-update.raw');
7
- var sectionState = require('./data/blocks/section-state.raw');
8
- var imageState = require('./data/blocks/img-state.raw');
9
- var onInitonMount = require('./data/blocks/onInit-onMount.raw');
10
7
  var basicContext = require('./data/basic-context.raw');
11
8
  var basicOutputsMeta = require('./data/basic-outputs-meta.raw');
12
9
  var basicOutputs = require('./data/basic-outputs.raw');
13
- var classNameJsx = require('./data/blocks/classname-jsx.raw');
14
10
  var basic = require('./data/basic.raw');
15
11
  var basicMitosis = require('./data/basic-custom-mitosis-package.raw');
16
12
  var basicChildComponent = require('./data/basic-child-component.raw');
@@ -20,46 +16,48 @@ var basicForwardRef = require('./data/basic-forwardRef.raw');
20
16
  var basicForwardRefMetadata = require('./data/basic-forwardRef-metadata.raw');
21
17
  var basicRefPrevious = require('./data/basic-ref-usePrevious.raw');
22
18
  var basicRefAssignment = require('./data/basic-ref-assignment.raw');
23
- var submitButtonBlock = require('./data/blocks/submit-button.raw');
24
- var inputBlock = require('./data/blocks/input.raw');
25
- var selectBlock = require('./data/blocks/select.raw');
26
- var formBlock = require('./data/blocks/form.raw');
19
+ var propsDestructure = require('./data/basic-props-destructure.raw');
20
+ var preserveExportOrLocalStatement = require('./data/basic-preserve-export-or-local-statement.raw');
21
+ var propsType = require('./data/types/component-props-type.raw');
22
+ var propsInterface = require('./data/types/component-props-interface.raw');
23
+ var preserveTyping = require('./data/types/preserve-typing.raw');
24
+ var classRaw = require('./data/styles/class.raw');
25
+ var className = require('./data/styles/className.raw');
26
+ var classAndClassName = require('./data/styles/class-and-className.raw');
27
+ var classState = require('./data/styles/classState.raw');
27
28
  var button = require('./data/blocks/button.raw');
28
- var textarea = require('./data/blocks/textarea.raw');
29
- var img = require('./data/blocks/img.raw');
30
- var video = require('./data/blocks/video.raw');
31
- var section = require('./data/blocks/section.raw');
32
- var text = require('./data/blocks/text.raw');
33
- var rawText = require('./data/blocks/raw-text.raw');
34
- var stamped = require('./data/blocks/stamped-io.raw');
29
+ var classNameJsx = require('./data/blocks/classname-jsx.raw');
30
+ var columns = require('./data/blocks/columns.raw');
31
+ var contentSlotHtml = require('./data/blocks/content-slot-html.raw');
32
+ var contentSlotJsx = require('./data/blocks/content-slot-jsx.raw');
35
33
  var customCode = require('./data/blocks/custom-code.raw');
34
+ var formBlock = require('./data/blocks/form.raw');
36
35
  var image = require('./data/blocks/image.raw');
37
- var columns = require('./data/blocks/columns.raw');
38
- var onUpdate = require('./data/blocks/onUpdate.raw');
39
- var onInit = require('./data/blocks/onInit.raw');
40
- var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
36
+ var imageState = require('./data/blocks/img-state.raw');
37
+ var img = require('./data/blocks/img.raw');
38
+ var inputBlock = require('./data/blocks/input.raw');
41
39
  var multipleOnUpdate = require('./data/blocks/multiple-onUpdate.raw');
42
40
  var multipleOnUpdateWithDeps = require('./data/blocks/multiple-onUpdateWithDeps.raw');
41
+ var onInit = require('./data/blocks/onInit.raw');
42
+ var onInitonMount = require('./data/blocks/onInit-onMount.raw');
43
43
  var onMount = require('./data/blocks/onMount.raw');
44
- var rootShow = require('./data/blocks/rootShow.raw');
45
- var contentSlotHtml = require('./data/blocks/content-slot-html.raw');
46
- var contentSlotJsx = require('./data/blocks/content-slot-jsx.raw');
47
- var slotJsx = require('./data/blocks/slot-jsx.raw');
44
+ var onUpdate = require('./data/blocks/onUpdate.raw');
45
+ var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
46
+ var rawText = require('./data/blocks/raw-text.raw');
47
+ var section = require('./data/blocks/section.raw');
48
+ var sectionState = require('./data/blocks/section-state.raw');
49
+ var selectBlock = require('./data/blocks/select.raw');
50
+ var selfRefCompWChildren = require('./data/blocks/self-referencing-component-with-children.raw');
51
+ var selfRefComp = require('./data/blocks/self-referencing-component.raw');
48
52
  var slotHtml = require('./data/blocks/slot-html.raw');
49
- var propsType = require('./data/types/component-props-type.raw');
50
- var propsInterface = require('./data/types/component-props-interface.raw');
51
- var preserveTyping = require('./data/types/preserve-typing.raw');
52
- var propsDestructure = require('./data/basic-props-destructure.raw');
53
- var preserveExportOrLocalStatement = require('./data/basic-preserve-export-or-local-statement.raw');
54
- var classRaw = require('./data/styles/class.raw');
55
- var className = require('./data/styles/className.raw');
56
- var classAndClassName = require('./data/styles/class-and-className.raw');
53
+ var slotJsx = require('./data/blocks/slot-jsx.raw');
54
+ var stamped = require('./data/blocks/stamped-io.raw');
55
+ var submitButtonBlock = require('./data/blocks/submit-button.raw');
56
+ var text = require('./data/blocks/text.raw');
57
+ var textarea = require('./data/blocks/textarea.raw');
58
+ var video = require('./data/blocks/video.raw');
57
59
  var path = 'test-path';
58
60
  var BASIC_TESTS = {
59
- ContentSlotJSX: contentSlotJsx,
60
- ContentSlotHtml: contentSlotHtml,
61
- SlotJsx: slotJsx,
62
- SlotHtml: slotHtml,
63
61
  Basic: basic,
64
62
  BasicRef: basicRef,
65
63
  BasicRefPrevious: basicRefPrevious,
@@ -100,6 +98,15 @@ var BASIC_TESTS = {
100
98
  'class + css': classRaw,
101
99
  'className + css': className,
102
100
  'class + ClassName + css': classAndClassName,
101
+ 'self-referencing component with children': selfRefCompWChildren,
102
+ 'self-referencing component': selfRefComp,
103
+ };
104
+ var SLOTS_TESTS = {
105
+ ContentSlotJSX: contentSlotJsx,
106
+ ContentSlotHtml: contentSlotHtml,
107
+ SlotJsx: slotJsx,
108
+ SlotHtml: slotHtml,
109
+ classState: classState,
103
110
  };
104
111
  var MULTI_ON_UPDATE_TESTS = {
105
112
  multipleOnUpdate: multipleOnUpdate,
@@ -116,13 +123,16 @@ var FORWARD_REF_TESTS = {
116
123
  basicForwardRef: basicForwardRef,
117
124
  basicForwardRefMetadata: basicForwardRefMetadata,
118
125
  };
119
- var ROOT_SHOW_TESTS = {
120
- rootShow: rootShow,
126
+ var SHOW_TESTS = {
127
+ rootShow: require('./data/blocks/rootShow.raw'),
128
+ nestedShow: require('./data/show/nested-show.raw'),
129
+ showWithFor: require('./data/show/show-with-for.raw'),
121
130
  };
122
131
  var TESTS_FOR_TARGET = {
123
132
  react: [
124
133
  BASIC_TESTS,
125
- ROOT_SHOW_TESTS,
134
+ SLOTS_TESTS,
135
+ SHOW_TESTS,
126
136
  FORWARD_REF_TESTS,
127
137
  MULTI_ON_UPDATE_TESTS,
128
138
  FORM_BLOCK_TESTS,
@@ -130,7 +140,8 @@ var TESTS_FOR_TARGET = {
130
140
  ],
131
141
  angular: [
132
142
  BASIC_TESTS,
133
- ROOT_SHOW_TESTS,
143
+ SLOTS_TESTS,
144
+ SHOW_TESTS,
134
145
  FORWARD_REF_TESTS,
135
146
  MULTI_ON_UPDATE_TESTS,
136
147
  FORM_BLOCK_TESTS,
@@ -138,7 +149,8 @@ var TESTS_FOR_TARGET = {
138
149
  ],
139
150
  webcomponent: [
140
151
  BASIC_TESTS,
141
- ROOT_SHOW_TESTS,
152
+ SLOTS_TESTS,
153
+ SHOW_TESTS,
142
154
  FORWARD_REF_TESTS,
143
155
  MULTI_ON_UPDATE_TESTS,
144
156
  FOR_SHOW_TESTS,
@@ -146,7 +158,8 @@ var TESTS_FOR_TARGET = {
146
158
  ],
147
159
  vue: [
148
160
  BASIC_TESTS,
149
- ROOT_SHOW_TESTS,
161
+ SLOTS_TESTS,
162
+ SHOW_TESTS,
150
163
  FORWARD_REF_TESTS,
151
164
  MULTI_ON_UPDATE_TESTS,
152
165
  FORM_BLOCK_TESTS,
@@ -154,7 +167,7 @@ var TESTS_FOR_TARGET = {
154
167
  ],
155
168
  svelte: [
156
169
  BASIC_TESTS,
157
- ROOT_SHOW_TESTS,
170
+ SHOW_TESTS,
158
171
  FORWARD_REF_TESTS,
159
172
  MULTI_ON_UPDATE_TESTS,
160
173
  FORM_BLOCK_TESTS,
@@ -162,7 +175,8 @@ var TESTS_FOR_TARGET = {
162
175
  ],
163
176
  html: [
164
177
  BASIC_TESTS,
165
- ROOT_SHOW_TESTS,
178
+ SLOTS_TESTS,
179
+ SHOW_TESTS,
166
180
  FORWARD_REF_TESTS,
167
181
  MULTI_ON_UPDATE_TESTS,
168
182
  FOR_SHOW_TESTS,
@@ -170,6 +184,7 @@ var TESTS_FOR_TARGET = {
170
184
  ],
171
185
  stencil: [
172
186
  BASIC_TESTS,
187
+ SLOTS_TESTS,
173
188
  // ROOT_SHOW_TESTS,
174
189
  FORWARD_REF_TESTS,
175
190
  // MULTI_ON_UPDATE_TESTS,
@@ -178,7 +193,8 @@ var TESTS_FOR_TARGET = {
178
193
  ],
179
194
  solid: [
180
195
  BASIC_TESTS,
181
- ROOT_SHOW_TESTS,
196
+ SLOTS_TESTS,
197
+ SHOW_TESTS,
182
198
  // FORWARD_REF_TESTS,
183
199
  MULTI_ON_UPDATE_TESTS,
184
200
  FORM_BLOCK_TESTS,
@@ -186,7 +202,8 @@ var TESTS_FOR_TARGET = {
186
202
  ],
187
203
  reactNative: [
188
204
  BASIC_TESTS,
189
- ROOT_SHOW_TESTS,
205
+ SLOTS_TESTS,
206
+ SHOW_TESTS,
190
207
  FORWARD_REF_TESTS,
191
208
  MULTI_ON_UPDATE_TESTS,
192
209
  FORM_BLOCK_TESTS,
@@ -194,14 +211,16 @@ var TESTS_FOR_TARGET = {
194
211
  ],
195
212
  liquid: [
196
213
  BASIC_TESTS,
197
- ROOT_SHOW_TESTS,
214
+ SLOTS_TESTS,
215
+ SHOW_TESTS,
198
216
  FORWARD_REF_TESTS,
199
217
  MULTI_ON_UPDATE_TESTS,
200
218
  FORM_BLOCK_TESTS,
201
219
  ],
202
220
  qwik: [
203
221
  BASIC_TESTS,
204
- ROOT_SHOW_TESTS,
222
+ SLOTS_TESTS,
223
+ SHOW_TESTS,
205
224
  FORWARD_REF_TESTS,
206
225
  MULTI_ON_UPDATE_TESTS,
207
226
  FORM_BLOCK_TESTS,
@@ -1,4 +1,4 @@
1
- import { JSX } from './jsx-types';
1
+ import { JSX } from '../jsx-runtime';
2
2
  /**
3
3
  * Flow control based on Solid
4
4
  *
@@ -36,6 +36,7 @@ var lodash_1 = require("lodash");
36
36
  var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
37
37
  var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
38
38
  var indent_1 = require("../helpers/indent");
39
+ var slots_1 = require("../helpers/slots");
39
40
  var mappers = {
40
41
  Fragment: function (json, options, blockOptions) {
41
42
  return "<div>".concat(json.children
@@ -58,6 +59,7 @@ var mappers = {
58
59
  // TODO: Maybe in the future allow defining `string | function` as values
59
60
  var BINDINGS_MAPPER = {
60
61
  innerHTML: 'innerHTML',
62
+ style: 'ngStyle',
61
63
  };
62
64
  var blockToAngular = function (json, options, blockOptions) {
63
65
  var _a, _b, _c, _d, _e, _f;
@@ -153,7 +155,7 @@ var blockToAngular = function (json, options, blockOptions) {
153
155
  else if (key === 'ref') {
154
156
  str += " #".concat(useValue, " ");
155
157
  }
156
- else if (key.startsWith('slot')) {
158
+ else if ((0, slots_1.isSlotProperty)(key)) {
157
159
  var lowercaseKey = key.replace('slot', '')[0].toLowerCase() + key.replace('slot', '').substring(1);
158
160
  needsToRenderSlots.push("".concat(useValue.replace(/(\/\>)|\>/, " ".concat(lowercaseKey, ">"))));
159
161
  }
@@ -276,7 +278,7 @@ var componentToAngular = function (options) {
276
278
  var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " } from '@angular/core';\n\n ", "\n ", "\n ", "\n\n @Component({\n selector: '", "',\n template: `\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 import { ", " ", " Component ", "", " } from '@angular/core';\n\n ", "\n ", "\n ", "\n\n @Component({\n selector: '", "',\n template: \\`\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 "])), 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' : '', json.types ? json.types.join('\n') : '', json.interfaces ? (_h = json.interfaces) === null || _h === void 0 ? void 0 : _h.join('\n') : '', (0, render_imports_1.renderPreComponent)({ component: json, target: 'angular' }), (0, lodash_1.kebabCase)(json.name || 'my-component'), (0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), css.length
277
279
  ? "styles: [\n `".concat((0, indent_1.indent)(css, 8), "`\n ],")
278
280
  : '', component.name, localExportVars.join('\n'), Array.from(props)
279
- .filter(function (item) { return !item.startsWith('slot') && item !== 'children'; })
281
+ .filter(function (item) { return !(0, slots_1.isSlotProperty)(item) && item !== 'children'; })
280
282
  .map(function (item) {
281
283
  var propType = propsTypeRef ? "".concat(propsTypeRef, "[\"").concat(item, "\"]") : 'any';
282
284
  return "@Input() ".concat(item, ": ").concat(propType);
@@ -53,6 +53,7 @@ var context_1 = require("./helpers/context");
53
53
  var react_native_1 = require("./react-native");
54
54
  var collect_styled_components_1 = require("../helpers/styles/collect-styled-components");
55
55
  var helpers_1 = require("../helpers/styles/helpers");
56
+ var slots_1 = require("../helpers/slots");
56
57
  /**
57
58
  * If the root Mitosis component only has 1 child, and it is a `Show` node, then we need to wrap it in a fragment.
58
59
  * Otherwise, we end up with invalid React render code.
@@ -257,7 +258,7 @@ var processBinding = function (str, options) {
257
258
  if (options.stateType !== 'useState') {
258
259
  return str;
259
260
  }
260
- if (str.startsWith('slot')) {
261
+ if ((0, slots_1.isSlotProperty)(str)) {
261
262
  return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(str, {
262
263
  includeState: true,
263
264
  includeProps: false,
@@ -81,11 +81,18 @@ var mappers = {
81
81
  }
82
82
  },
83
83
  For: function (_a) {
84
- var _b;
84
+ var _b, _c;
85
85
  var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
86
- return "\n{#each ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code, {
86
+ var firstChild = json.children[0];
87
+ var keyValue = firstChild.properties.key || ((_b = firstChild.bindings.key) === null || _b === void 0 ? void 0 : _b.code);
88
+ if (keyValue) {
89
+ // we remove extraneous prop which Svelte does not use
90
+ delete firstChild.properties.key;
91
+ delete firstChild.bindings.key;
92
+ }
93
+ return "\n{#each ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, {
87
94
  includeState: options.stateType === 'variables',
88
- }), " as ").concat(json.properties._forName, ", index }\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
95
+ }), " as ").concat(json.scope.For[0], ", ").concat(json.scope.For[1], " ").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");
89
96
  },
90
97
  Show: function (_a) {
91
98
  var _b;
@@ -145,7 +152,7 @@ var getTagName = function (_a) {
145
152
  return json.name;
146
153
  };
147
154
  var blockToSvelte = function (_a) {
148
- var _b, _c, _d;
155
+ var _b, _c, _d, _e, _f;
149
156
  var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
150
157
  if (mappers[json.name]) {
151
158
  return mappers[json.name]({ json: json, options: options, parentComponent: parentComponent });
@@ -169,6 +176,14 @@ var blockToSvelte = function (_a) {
169
176
  includeState: options.stateType === 'variables',
170
177
  }), "}");
171
178
  }
179
+ if (((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style) {
180
+ var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(((_e = json.bindings.style) === null || _e === void 0 ? void 0 : _e.code) || json.properties.style, {
181
+ includeState: options.stateType === 'variables',
182
+ });
183
+ str += "use:mitosis_styling={".concat(useValue, "}");
184
+ delete json.bindings.style;
185
+ delete json.properties.style;
186
+ }
172
187
  for (var key in json.properties) {
173
188
  var value = json.properties[key];
174
189
  str += " ".concat(key, "=\"").concat(value, "\" ");
@@ -180,7 +195,7 @@ var blockToSvelte = function (_a) {
180
195
  if (key === '_spread') {
181
196
  continue;
182
197
  }
183
- var _e = json.bindings[key], value = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f;
198
+ var _g = json.bindings[key], value = _g.code, _h = _g.arguments, cusArgs = _h === void 0 ? ['event'] : _h;
184
199
  // TODO: proper babel transform to replace. Util for this
185
200
  var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value, {
186
201
  includeState: options.stateType === 'variables',
@@ -188,7 +203,7 @@ var blockToSvelte = function (_a) {
188
203
  if (key.startsWith('on')) {
189
204
  var event_1 = key.replace('on', '').toLowerCase();
190
205
  // TODO: handle quotes in event handler values
191
- str += " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => ").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue), "}\" ");
206
+ str += " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue), "}}\" ");
192
207
  }
193
208
  else if (key === 'ref') {
194
209
  str += " bind:this={".concat(useValue, "} ");
@@ -199,7 +214,7 @@ var blockToSvelte = function (_a) {
199
214
  }
200
215
  // if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
201
216
  // we use the innerHTML content as children and don't render the self-closing tag.
202
- if ((_d = json.bindings.innerHTML) === null || _d === void 0 ? void 0 : _d.code) {
217
+ if ((_f = json.bindings.innerHTML) === null || _f === void 0 ? void 0 : _f.code) {
203
218
  str += '>';
204
219
  str += BINDINGS_MAPPER.innerHTML(json, options);
205
220
  str += "</".concat(tagName, ">");
@@ -271,6 +286,18 @@ var FUNCTION_HACK_PLUGIN = function () { return ({
271
286
  },
272
287
  },
273
288
  }); };
289
+ var hasStyleObject = function (children) {
290
+ for (var i = 0; i < children.length; i++) {
291
+ var child = children[i];
292
+ if (child.bindings.style || child.properties.style) {
293
+ return true;
294
+ }
295
+ else if (child.children.length) {
296
+ return hasStyleObject(child.children);
297
+ }
298
+ }
299
+ return false;
300
+ };
274
301
  var componentToSvelte = function (_a) {
275
302
  if (_a === void 0) { _a = {}; }
276
303
  var _b = _a.plugins, plugins = _b === void 0 ? [] : _b, options = __rest(_a, ["plugins"]);
@@ -334,14 +361,16 @@ var componentToSvelte = function (_a) {
334
361
  includeState: useOptions.stateType === 'variables',
335
362
  }), babel_transform_1.babelTransformCode);
336
363
  };
337
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __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 "])), !((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ? '' : "import { onMount } from 'svelte'", !((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length) ? '' : "import { afterUpdate } from 'svelte'", !((_d = json.hooks.onUnMount) === null || _d === void 0 ? void 0 : _d.code) ? '' : "import { onDestroy } from 'svelte'", (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), (0, context_1.hasContext)(component) ? 'import { getContext, setContext } from "svelte";' : '', !hasData || useOptions.stateType === 'variables' ? '' : "import onChange from 'on-change'", (0, lodash_1.uniq)(refs.map(function (ref) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref); }).concat(props))
364
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __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 "])), !((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ? '' : "import { onMount } from 'svelte'", !((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length) ? '' : "import { afterUpdate } from 'svelte'", !((_d = json.hooks.onUnMount) === null || _d === void 0 ? void 0 : _d.code) ? '' : "import { onDestroy } from 'svelte'", (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), (0, context_1.hasContext)(component) ? 'import { getContext, setContext } from "svelte";' : '', !hasData || useOptions.stateType === 'variables' ? '' : "import onChange from 'on-change'", (0, lodash_1.uniq)(refs.map(function (ref) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref); }).concat(props))
338
365
  .map(function (name) {
339
366
  if (name === 'children') {
340
367
  return '';
341
368
  }
342
369
  return "export let ".concat(name, ";");
343
370
  })
344
- .join('\n'), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, getContextCode(json), setContextCode(json), useOptions.stateType === 'proxies'
371
+ .join('\n'), hasStyleObject(json.children)
372
+ ? "\n function mitosis_styling (node, vars) {\n Object.entries(vars).forEach(([ p, v ]) => { node.style[p] = v })\n }\n "
373
+ : '', functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, getContextCode(json), setContextCode(json), useOptions.stateType === 'proxies'
345
374
  ? dataString.length < 4
346
375
  ? ''
347
376
  : "let state = onChange(".concat(dataString, ", () => state = state)")
@@ -10,7 +10,11 @@ export interface ToVueOptions extends BaseTranspilerOptions, VueVersionOpt {
10
10
  namePrefix?: (path: string) => string;
11
11
  asyncComponentImports?: boolean;
12
12
  }
13
- export declare const blockToVue: (node: MitosisNode, options: ToVueOptions) => string;
13
+ declare type BlockRenderer = (json: MitosisNode, options: ToVueOptions, scope?: Scope) => string;
14
+ interface Scope {
15
+ isRootNode?: boolean;
16
+ }
17
+ export declare const blockToVue: BlockRenderer;
14
18
  declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
15
19
  export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
16
20
  export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => Transpiler;