@builder.io/mitosis 0.7.2 → 0.7.4

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.
@@ -52,6 +52,13 @@ exports.DEFAULT_FORMAT = 'legacy';
52
52
  const isValidAttributeName = (str) => {
53
53
  return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
54
54
  };
55
+ const isInvalidJsxAttributeName = (str) => {
56
+ let attr = str.trim();
57
+ if (attr.startsWith(':') || str.startsWith('@')) {
58
+ return true;
59
+ }
60
+ return false;
61
+ };
55
62
  const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
56
63
  var _a, _b, _c, _d, _e, _f, _g, _h;
57
64
  const options = {
@@ -154,6 +161,10 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
154
161
  let str = '';
155
162
  str += `<${json.name} `;
156
163
  for (const key in json.properties) {
164
+ if (isInvalidJsxAttributeName(key)) {
165
+ console.warn('Skipping invalid attribute name:', key);
166
+ continue;
167
+ }
157
168
  const value = (json.properties[key] || '').replace(/"/g, '&quot;').replace(/\n/g, '\\n');
158
169
  if (!isValidAttributeName(key)) {
159
170
  console.warn('Skipping invalid attribute name:', key);
@@ -163,6 +174,10 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
163
174
  }
164
175
  }
165
176
  for (const key in json.bindings) {
177
+ if (isInvalidJsxAttributeName(key)) {
178
+ console.warn('Skipping invalid attribute name:', key);
179
+ continue;
180
+ }
166
181
  const value = (_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.code;
167
182
  if (!value || ((_f = json.slots) === null || _f === void 0 ? void 0 : _f[key])) {
168
183
  continue;
@@ -7,7 +7,6 @@ const helpers_1 = require("../../generators/stencil/helpers");
7
7
  const get_code_processor_plugins_1 = require("../../generators/stencil/plugins/get-code-processor-plugins");
8
8
  const dash_case_1 = require("../../helpers/dash-case");
9
9
  const dedent_1 = require("../../helpers/dedent");
10
- const event_handlers_1 = require("../../helpers/event-handlers");
11
10
  const fast_clone_1 = require("../../helpers/fast-clone");
12
11
  const get_child_components_1 = require("../../helpers/get-child-components");
13
12
  const get_props_1 = require("../../helpers/get-props");
@@ -41,16 +40,7 @@ const componentToStencil = (_options = {
41
40
  const defaultProps = json.defaultProps;
42
41
  const childComponents = (0, get_child_components_1.getChildComponents)(json);
43
42
  const processBindingOptions = { events };
44
- props = props
45
- .map((prop) => {
46
- // Stencil adds "on" to every `@Event` so we need to remove "on" from event props
47
- // https://stenciljs.com/docs/events#using-events-in-jsx
48
- if ((0, helpers_1.isEvent)(prop)) {
49
- return (0, event_handlers_1.getEventNameWithoutOn)(prop);
50
- }
51
- return prop;
52
- })
53
- .filter((prop) => {
43
+ props = props.filter((prop) => {
54
44
  // Stencil doesn't need children as a prop
55
45
  return prop !== 'children';
56
46
  });
@@ -14,7 +14,10 @@ const appendEmits = (str, events) => {
14
14
  let code = str;
15
15
  if (events.length) {
16
16
  for (const event of events) {
17
- code = code.replaceAll(`props.${event}(`, `props.${(0, event_handlers_1.getEventNameWithoutOn)(event)}.emit(`);
17
+ const eventWithoutOn = (0, event_handlers_1.getEventNameWithoutOn)(event);
18
+ code = code
19
+ .replaceAll(`props.${event}(`, `props.${eventWithoutOn}.emit(`)
20
+ .replaceAll(`props.${event}`, `props.${eventWithoutOn}`);
18
21
  }
19
22
  }
20
23
  return code;
@@ -53,17 +56,21 @@ const getPropsAsCode = ({ props, propOptions, defaultProps, json, }) => {
53
56
  const defaultProp = defaultProps ? (_a = defaultProps[item]) === null || _a === void 0 ? void 0 : _a.code : undefined;
54
57
  const defaultPropString = defaultProp ? ` = ${defaultProp}` : '';
55
58
  const propOption = propOptions[item];
56
- if ((0, exports.isEvent)(item)) {
57
- return `@Event() ${item}: any${defaultPropString}`;
58
- }
59
- const type = propsTypeRef &&
59
+ const hasTyping = propsTypeRef &&
60
60
  propsTypeRef !== 'any' &&
61
61
  propsTypeRef !== 'unknown' &&
62
62
  propsTypeRef !== 'never' &&
63
- !isInternalType
64
- ? `${propsTypeRef}["${item}"]`
65
- : 'any';
66
- return `@Prop(${propOption ? JSON.stringify(propOption) : ''}) ${item}: ${type}${defaultPropString}`;
63
+ !isInternalType;
64
+ if ((0, exports.isEvent)(item)) {
65
+ // Stencil adds "on" to every `@Event` so we need to remove "on" from event props
66
+ // https://stenciljs.com/docs/events#using-events-in-jsx
67
+ const eventType = hasTyping
68
+ ? `EventEmitter<ReturnType<Required<${propsTypeRef}>["${item}"]>>`
69
+ : 'any';
70
+ return `@Event() ${(0, event_handlers_1.getEventNameWithoutOn)(item)}: ${eventType}${defaultPropString}`;
71
+ }
72
+ const propType = hasTyping ? `${propsTypeRef}["${item}"]` : 'any';
73
+ return `@Prop(${propOption ? JSON.stringify(propOption) : ''}) ${item}: ${propType}${defaultPropString}`;
67
74
  })
68
75
  .join(';\n');
69
76
  };
@@ -101,6 +108,7 @@ const getStencilCoreImportsAsString = ({ wrap, events, props, dataString, watch,
101
108
  Host: wrap,
102
109
  Watch: watch,
103
110
  Event: events.length > 0,
111
+ EventEmitter: events.length > 0,
104
112
  Prop: props.length > 0,
105
113
  State: dataString.length > 0,
106
114
  };
@@ -1,4 +1,4 @@
1
- import { ProcessBindingOptions } from '../../../generators/stencil/helpers/index';
1
+ import { ProcessBindingOptions } from '../../../generators/stencil/helpers';
2
2
  import { ToStencilOptions } from '../../../generators/stencil/types';
3
3
  import { MitosisComponent } from '../../../types/mitosis-component';
4
4
  export declare const getCodeProcessorPlugins: (json: MitosisComponent, options: ToStencilOptions, processBindingOptions: ProcessBindingOptions) => import("../../..").MitosisPlugin[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCodeProcessorPlugins = void 0;
4
- const index_1 = require("../../../generators/stencil/helpers/index");
4
+ const helpers_1 = require("../../../generators/stencil/helpers");
5
5
  const process_code_1 = require("../../../helpers/plugins/process-code");
6
6
  const getCodeProcessorPlugins = (json, options, processBindingOptions) => {
7
7
  return [
@@ -16,7 +16,7 @@ const getCodeProcessorPlugins = (json, options, processBindingOptions) => {
16
16
  case 'context-set':
17
17
  case 'dynamic-jsx-elements':
18
18
  case 'types':
19
- return (code) => (0, index_1.processBinding)(json, code, processBindingOptions);
19
+ return (code) => (0, helpers_1.processBinding)(json, code, processBindingOptions);
20
20
  }
21
21
  }),
22
22
  ];
@@ -208,6 +208,17 @@ const stringifyBinding = (node, options) => ([key, binding]) => {
208
208
  };
209
209
  const blockToSvelte = ({ json, options, parentComponent }) => {
210
210
  var _a, _b, _c, _d;
211
+ // Handling key binding by wrapping the element in a #key block
212
+ if (json.bindings.key) {
213
+ const keyCode = json.bindings.key.code;
214
+ delete json.bindings.key;
215
+ const str = `
216
+ {#key ${keyCode}}
217
+ ${(0, exports.blockToSvelte)({ json, options, parentComponent })}
218
+ {/key}
219
+ `;
220
+ return str;
221
+ }
211
222
  if (mappers[json.name]) {
212
223
  return mappers[json.name]({
213
224
  json: json,
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.7.2",
25
+ "version": "0.7.4",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {