@builder.io/mitosis 0.0.56-90 → 0.0.56-93

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.
@@ -197,9 +197,9 @@ var componentToAngular = function (options) {
197
197
  if (options === void 0) { options = {}; }
198
198
  return function (_a) {
199
199
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
200
- var component = _a.component;
200
+ var _component = _a.component;
201
201
  // Make a copy we can safely mutate, similar to babel's toolchain
202
- var json = (0, fast_clone_1.fastClone)(component);
202
+ var json = (0, fast_clone_1.fastClone)(_component);
203
203
  if (options.plugins) {
204
204
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
205
205
  }
@@ -215,7 +215,7 @@ var componentToAngular = function (options) {
215
215
  });
216
216
  });
217
217
  var customImports = (0, get_custom_imports_1.getCustomImports)(json);
218
- var _p = component.exports, localExports = _p === void 0 ? {} : _p;
218
+ var _p = json.exports, localExports = _p === void 0 ? {} : _p;
219
219
  var localExportVars = Object.keys(localExports)
220
220
  .filter(function (key) { return localExports[key].usedInLocal; })
221
221
  .map(function (key) { return "".concat(key, " = ").concat(key, ";"); });
@@ -232,14 +232,14 @@ var componentToAngular = function (options) {
232
232
  }
233
233
  return "public ".concat(variableName, " : ").concat(variableType);
234
234
  });
235
- var hasConstructor = Boolean(injectables.length || ((_e = component.hooks) === null || _e === void 0 ? void 0 : _e.onInit));
236
- var props = (0, get_props_1.getProps)(component);
235
+ var hasConstructor = Boolean(injectables.length || ((_e = json.hooks) === null || _e === void 0 ? void 0 : _e.onInit));
236
+ var props = (0, get_props_1.getProps)(json);
237
237
  // prevent jsx props from showing up as @Input
238
238
  if (hasPropRef) {
239
239
  props.delete(forwardProp);
240
240
  }
241
241
  props.delete('children');
242
- var outputVars = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], metaOutputVars, true), (0, get_prop_functions_1.getPropFunctions)(component), true));
242
+ var outputVars = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], metaOutputVars, true), (0, get_prop_functions_1.getPropFunctions)(json), true));
243
243
  // remove props for outputs
244
244
  outputVars.forEach(function (variableName) {
245
245
  props.delete(variableName);
@@ -251,7 +251,7 @@ var componentToAngular = function (options) {
251
251
  }
252
252
  return "@Output() ".concat(variableName, " = new EventEmitter()");
253
253
  });
254
- var hasOnMount = Boolean((_f = component.hooks) === null || _f === void 0 ? void 0 : _f.onMount);
254
+ var hasOnMount = Boolean((_f = json.hooks) === null || _f === void 0 ? void 0 : _f.onMount);
255
255
  var domRefs = (0, get_refs_1.getRefs)(json);
256
256
  var jsRefs = Object.keys(json.refs).filter(function (ref) { return !domRefs.has(ref); });
257
257
  var stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
@@ -301,7 +301,7 @@ var componentToAngular = function (options) {
301
301
  "\n standalone: true,\n imports: [CommonModule".concat(componentsUsed.length ? ", ".concat(componentsUsed.join(', ')) : '', "],\n ")
302
302
  : '', (0, lodash_1.kebabCase)(json.name || 'my-component'), (0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), css.length
303
303
  ? "styles: [\n `".concat((0, indent_1.indent)(css, 8), "`\n ],")
304
- : '', component.name, localExportVars.join('\n'), customImports.map(function (name) { return "".concat(name, " = ").concat(name); }).join('\n'), Array.from(props)
304
+ : '', json.name, localExportVars.join('\n'), customImports.map(function (name) { return "".concat(name, " = ").concat(name); }).join('\n'), Array.from(props)
305
305
  .filter(function (item) { return !(0, slots_1.isSlotProperty)(item) && item !== 'children'; })
306
306
  .map(function (item) {
307
307
  var propType = propsTypeRef ? "".concat(propsTypeRef, "[\"").concat(item, "\"]") : 'any';
@@ -311,8 +311,8 @@ var componentToAngular = function (options) {
311
311
  .map(function (refName) { return "@ViewChild('".concat(refName, "') ").concat(refName, ": ElementRef"); })
312
312
  .join('\n'), dataString, jsRefs
313
313
  .map(function (ref) {
314
- var argument = component.refs[ref].argument;
315
- var typeParameter = component.refs[ref].typeParameter;
314
+ var argument = json.refs[ref].argument;
315
+ var typeParameter = json.refs[ref].typeParameter;
316
316
  return "private _".concat(ref).concat(typeParameter ? ": ".concat(typeParameter) : '').concat(argument
317
317
  ? " = ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(argument, {
318
318
  replaceWith: 'this.',
@@ -325,25 +325,25 @@ var componentToAngular = function (options) {
325
325
  })
326
326
  .join('\n'), !hasConstructor
327
327
  ? ''
328
- : "constructor(\n".concat(injectables.join(',\n'), ") {\n ").concat(!((_h = component.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
328
+ : "constructor(\n".concat(injectables.join(',\n'), ") {\n ").concat(!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
329
329
  ? ''
330
- : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_j = component.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, {
330
+ : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, {
331
331
  replaceWith: 'this.',
332
332
  contextVars: contextVars,
333
333
  outputVars: outputVars,
334
334
  }), "\n "), "\n }\n "), !hasOnMount
335
335
  ? ''
336
- : "ngOnInit() {\n \n ".concat(!((_k = component.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
336
+ : "ngOnInit() {\n \n ".concat(!((_k = json.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
337
337
  ? ''
338
- : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_l = component.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, {
338
+ : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_l = json.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, {
339
339
  replaceWith: 'this.',
340
340
  contextVars: contextVars,
341
341
  outputVars: outputVars,
342
342
  domRefs: Array.from(domRefs),
343
343
  stateVars: stateVars,
344
- }), "\n "), "\n }"), !((_m = component.hooks.onUpdate) === null || _m === void 0 ? void 0 : _m.length)
344
+ }), "\n "), "\n }"), !((_m = json.hooks.onUpdate) === null || _m === void 0 ? void 0 : _m.length)
345
345
  ? ''
346
- : "ngAfterContentChecked() {\n ".concat(component.hooks.onUpdate.reduce(function (code, hook) {
346
+ : "ngAfterContentChecked() {\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
347
347
  code += (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(hook.code, {
348
348
  replaceWith: 'this.',
349
349
  contextVars: contextVars,
@@ -352,9 +352,9 @@ var componentToAngular = function (options) {
352
352
  stateVars: stateVars,
353
353
  });
354
354
  return code + '\n';
355
- }, ''), "\n }"), !component.hooks.onUnMount
355
+ }, ''), "\n }"), !json.hooks.onUnMount
356
356
  ? ''
357
- : "ngOnDestroy() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(component.hooks.onUnMount.code, {
357
+ : "ngOnDestroy() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.hooks.onUnMount.code, {
358
358
  replaceWith: 'this.',
359
359
  contextVars: contextVars,
360
360
  outputVars: outputVars,
@@ -28,6 +28,17 @@ var get_refs_1 = require("../../helpers/get-refs");
28
28
  var lodash_1 = require("lodash");
29
29
  var is_upper_case_1 = require("../../helpers/is-upper-case");
30
30
  var has_1 = require("../../helpers/has");
31
+ var getCustomTagName = function (name, options) {
32
+ if (!name || !(0, is_upper_case_1.isUpperCase)(name[0])) {
33
+ return name;
34
+ }
35
+ var kebabCaseName = (0, dash_case_1.dashCase)(name);
36
+ if (!kebabCaseName.includes('-')) {
37
+ // TODO: option to choose your prefix
38
+ return 'my-' + kebabCaseName;
39
+ }
40
+ return kebabCaseName;
41
+ };
31
42
  var blockToLit = function (json, options) {
32
43
  var _a, _b, _c, _d, _e;
33
44
  if (options === void 0) { options = {}; }
@@ -50,7 +61,7 @@ var blockToLit = function (json, options) {
50
61
  .join('\n'), "`\n : ").concat(!json.meta.else ? 'null' : "html`".concat(blockToLit(json.meta.else, options), "`"), "}");
51
62
  }
52
63
  var str = '';
53
- var tagName = (0, is_upper_case_1.isUpperCase)(json.name[0]) ? (0, dash_case_1.dashCase)(json.name) : json.name;
64
+ var tagName = getCustomTagName(json.name, options);
54
65
  str += "<".concat(tagName, " ");
55
66
  var classString = (0, collect_class_string_1.collectClassString)(json);
56
67
  if (classString) {
@@ -164,9 +175,9 @@ var componentToLit = function (options) {
164
175
  html = html.replace(/\n{3,}/g, '\n\n');
165
176
  }
166
177
  }
167
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html`\n ", "\n `\n }\n }\n "], ["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html\\`\n ", "\n \\`\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({ component: json, target: 'lit' }), json.types ? json.types.join('\n') : '', hasSpread
178
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state, query } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html`\n ", "\n `\n }\n }\n "], ["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state, query } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html\\`\n ", "\n \\`\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({ component: json, target: 'lit' }), json.types ? json.types.join('\n') : '', hasSpread
168
179
  ? "\n const spread = (properties) =>\n directive((part) => {\n for (const property in properties) {\n const value = properties[attr];\n part.element[property] = value;\n }\n });\n "
169
- : '', ((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName) || (0, dash_case_1.dashCase)(json.name), json.name, css.length
180
+ : '', ((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName) || getCustomTagName(json.name, options), json.name, css.length
170
181
  ? "static styles = css`\n ".concat((0, indent_1.indent)(css, 8), "`;")
171
182
  : '', Array.from(domRefs)
172
183
  .map(function (refName) { return "\n @query('[ref=\"".concat(refName, "\"]')\n ").concat((0, lodash_1.camelCase)(refName), "!: HTMLElement;\n "); })
@@ -62,7 +62,7 @@ function getStatePropertyNames(json) {
62
62
  return Object.keys(json.state).filter(function (key) { var _a; return ((_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; });
63
63
  }
64
64
  var blockToMarko = function (json, options) {
65
- var _a, _b, _c, _d, _e;
65
+ var _a, _b, _c, _d, _e, _f;
66
66
  if (json.properties._text) {
67
67
  return json.properties._text;
68
68
  }
@@ -73,20 +73,21 @@ var blockToMarko = function (json, options) {
73
73
  return json.children.map(function (child) { return blockToMarko(child, options); }).join('\n');
74
74
  }
75
75
  if (json.name === 'For') {
76
- return "<for|".concat(json.properties._forName, "| of=(").concat(processBinding(options.component, (_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code), ")>\n ").concat(json.children
76
+ var forArguments = (((_c = json === null || json === void 0 ? void 0 : json.scope) === null || _c === void 0 ? void 0 : _c.For) || []).join(',');
77
+ return "<for|".concat(forArguments, "| of=(").concat(processBinding(options.component, (_d = json.bindings.each) === null || _d === void 0 ? void 0 : _d.code), ")>\n ").concat(json.children
77
78
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
78
79
  .map(function (item) { return blockToMarko(item, options); })
79
80
  .join('\n'), "\n </for>");
80
81
  }
81
82
  else if (json.name === 'Show') {
82
- return "<if(".concat(processBinding(options.component, (_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code), ")>\n ").concat(json.children
83
+ return "<if(".concat(processBinding(options.component, (_e = json.bindings.when) === null || _e === void 0 ? void 0 : _e.code), ")>\n ").concat(json.children
83
84
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
84
85
  .map(function (item) { return blockToMarko(item, options); })
85
86
  .join('\n'), "</if>\n ").concat(!json.meta.else ? '' : "<else>".concat(blockToMarko(json.meta.else, options), "</else>"));
86
87
  }
87
88
  var str = '';
88
89
  str += "<".concat(json.name, " ");
89
- if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
90
+ if ((_f = json.bindings._spread) === null || _f === void 0 ? void 0 : _f.code) {
90
91
  str += " ...(".concat(json.bindings._spread.code, ") ");
91
92
  }
92
93
  for (var key in json.properties) {
@@ -94,7 +95,7 @@ var blockToMarko = function (json, options) {
94
95
  str += " ".concat(key, "=\"").concat(value, "\" ");
95
96
  }
96
97
  for (var key in json.bindings) {
97
- var _f = json.bindings[key], code = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g;
98
+ var _g = json.bindings[key], code = _g.code, _h = _g.arguments, cusArgs = _h === void 0 ? ['event'] : _h;
98
99
  if (key === '_spread' || key === '_forName') {
99
100
  continue;
100
101
  }
@@ -28,7 +28,7 @@ var stripStateAndPropsRefs = function (code, options) {
28
28
  if (outputVars.length) {
29
29
  outputVars.forEach(function (_var) {
30
30
  // determine expression edge cases onMessage( to this.onMessage.emit(
31
- var regexp = '( |;|\\()(props\\.?)' + _var + '\\(';
31
+ var regexp = '(^|\\s|;|\\()(props\\.?)' + _var + '\\(';
32
32
  var replacer = '$1' + context + _var + '.emit(';
33
33
  newCode = newCode.replace(new RegExp(regexp, 'g'), replacer);
34
34
  });