@builder.io/mitosis 0.2.4 → 0.2.6

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.
@@ -189,10 +189,6 @@ var stringifyBinding = function (node, options, blockOptions) {
189
189
  if (key === 'key') {
190
190
  return;
191
191
  }
192
- if (key === 'attributes') {
193
- // TODO: contains ternary operator which needs to be handled
194
- return;
195
- }
196
192
  var keyToUse = BINDINGS_MAPPER[key] || key;
197
193
  var _b = binding, code = _b.code, _c = _b.arguments, cusArgs = _c === void 0 ? ['event'] : _c;
198
194
  // TODO: proper babel transform to replace. Util for this
@@ -227,11 +223,7 @@ var handleNgOutletBindings = function (node) {
227
223
  continue;
228
224
  }
229
225
  var _a = node.bindings[key], code = _a.code, _b = _a.arguments, cusArgs = _b === void 0 ? ['event'] : _b;
230
- if (code.includes('?')) {
231
- // TODO handle ternary
232
- continue;
233
- }
234
- else if (key.includes('props.')) {
226
+ if (key.includes('props.')) {
235
227
  allProps += "".concat(key.replace('props.', ''), ": ").concat(code, ", ");
236
228
  }
237
229
  else if (key.includes('.')) {
@@ -256,7 +248,7 @@ var handleNgOutletBindings = function (node) {
256
248
  return [allProps, events];
257
249
  };
258
250
  var blockToAngular = function (json, options, blockOptions) {
259
- var _a, _b, _c;
251
+ var _a, _b, _c, _d;
260
252
  if (options === void 0) { options = {}; }
261
253
  if (blockOptions === void 0) { blockOptions = {
262
254
  nativeAttributes: [],
@@ -274,8 +266,7 @@ var blockToAngular = function (json, options, blockOptions) {
274
266
  var textCode = (_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
275
267
  if (textCode) {
276
268
  if ((0, slots_1.isSlotProperty)(textCode)) {
277
- var selector = (0, function_1.pipe)(textCode, slots_1.stripSlotPrefix, lodash_1.kebabCase);
278
- return "<ng-content select=\"[".concat(selector, "]\"></ng-content>");
269
+ return "<ng-content select=\"[".concat((0, slots_1.toKebabSlot)(textCode), "]\"></ng-content>");
279
270
  }
280
271
  if (textCode.includes('JSON.stringify')) {
281
272
  var obj = textCode.replace('JSON.stringify', '');
@@ -294,18 +285,24 @@ var blockToAngular = function (json, options, blockOptions) {
294
285
  else if (json.name === 'Show') {
295
286
  var condition = (_c = json.bindings.when) === null || _c === void 0 ? void 0 : _c.code;
296
287
  if (condition === null || condition === void 0 ? void 0 : condition.includes('typeof')) {
297
- var wordAfterTypeof = condition.split('typeof')[1].trim();
288
+ var wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
298
289
  condition = condition.replace("typeof ".concat(wordAfterTypeof), "useTypeOf(".concat(wordAfterTypeof, ")"));
299
290
  }
300
291
  str += "<ng-container *ngIf=\"".concat(condition, "\">");
301
292
  str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
302
293
  str += "</ng-container>";
294
+ // else condition
295
+ if ((0, is_mitosis_node_1.isMitosisNode)((_d = json.meta) === null || _d === void 0 ? void 0 : _d.else)) {
296
+ str += "<ng-container *ngIf=\"!(".concat(condition, ")\">");
297
+ str += (0, exports.blockToAngular)(json.meta.else, options, blockOptions);
298
+ str += "</ng-container>";
299
+ }
303
300
  }
304
301
  else if (json.name.includes('.')) {
305
302
  var elSelector = childComponents.find(function (impName) { return impName === json.name; })
306
303
  ? (0, lodash_1.kebabCase)(json.name)
307
304
  : json.name;
308
- var _d = handleNgOutletBindings(json), allProps = _d[0], events = _d[1];
305
+ var _e = handleNgOutletBindings(json), allProps = _e[0], events = _e[1];
309
306
  str += "<ng-container ".concat(events, " *ngComponentOutlet=\"\n ").concat(elSelector.replace('state.', '').replace('props.', ''), ";\n inputs: { ").concat(allProps, " };\n content: myContent;\n \"> ");
310
307
  str += "</ng-container>";
311
308
  }
@@ -82,7 +82,11 @@ var checkIsObjectWithCodeBlock = function (obj) {
82
82
  return typeof obj == 'object' && (obj === null || obj === void 0 ? void 0 : obj.code) && typeof obj.code === 'string';
83
83
  };
84
84
  function getLexicalScopeVars(component) {
85
- return __spreadArray(__spreadArray(['props', 'state'], Object.keys(component.refs), true), Object.keys(component.context.get), true);
85
+ var newLocal = __spreadArray(__spreadArray(__spreadArray([
86
+ 'props',
87
+ 'state'
88
+ ], Object.keys(component.state).filter(function (k) { return component.state[k].type === 'getter'; }), true), Object.keys(component.refs), true), Object.keys(component.context.get), true);
89
+ return newLocal;
86
90
  }
87
91
  exports.getLexicalScopeVars = getLexicalScopeVars;
88
92
  function rewriteCodeExpr(component, methodMap, lexicalArgs, replace) {
@@ -90,19 +90,24 @@ function renderJSXNodes(file, directives, handlers, children, styles, key, paren
90
90
  includedHelperDirectives(directive.toString(), directives);
91
91
  }
92
92
  else {
93
- if (typeof directive == 'string') {
94
- directives.set(childName, directive);
95
- includedHelperDirectives(directive, directives);
96
- if (file.module !== 'med' && file.imports.hasImport(childName)) {
97
- file.import('./med.js', childName);
98
- }
93
+ if (childName === 'Slot') {
94
+ _this.file.import(_this.file.qwikModule, 'Slot');
99
95
  }
100
- if (isSymbol(childName)) {
101
- // TODO(misko): We are hard coding './med.js' which is not right.
102
- !file.imports.hasImport(childName) && file.import('./med.js', childName);
103
- var exportedChildName = file.exports.get(childName);
104
- if (exportedChildName) {
105
- childName = exportedChildName;
96
+ else {
97
+ if (typeof directive == 'string') {
98
+ directives.set(childName, directive);
99
+ includedHelperDirectives(directive, directives);
100
+ if (file.module !== 'med' && file.imports.hasImport(childName)) {
101
+ file.import('./med.js', childName);
102
+ }
103
+ }
104
+ if (isSymbol(childName)) {
105
+ // TODO(misko): We are hard coding './med.js' which is not right.
106
+ !file.imports.hasImport(childName) && file.import('./med.js', childName);
107
+ var exportedChildName = file.exports.get(childName);
108
+ if (exportedChildName) {
109
+ childName = exportedChildName;
110
+ }
106
111
  }
107
112
  }
108
113
  var props = child.properties;
@@ -114,7 +114,7 @@ var mappers = {
114
114
  }
115
115
  return "\n <span #".concat(key, ">\n ").concat((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.code, "\n </span>\n ");
116
116
  }
117
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(slotName, SLOT_PREFIX).toLowerCase(), "\">").concat(renderChildren(), "</slot>");
117
+ return "<slot name=\"".concat((0, slots_1.toKebabSlot)(slotName, SLOT_PREFIX), "\">").concat(renderChildren(), "</slot>");
118
118
  },
119
119
  };
120
120
  var BINDINGS_MAPPER = {
@@ -72,7 +72,7 @@ var NODE_MAPPERS = {
72
72
  if (slotName === 'default') {
73
73
  return "<slot>".concat(renderChildren(), "</slot>");
74
74
  }
75
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(slotName, SLOT_PREFIX).toLowerCase(), "\">").concat(renderChildren(), "</slot>");
75
+ return "<slot name=\"".concat((0, slots_1.toKebabSlot)(slotName, SLOT_PREFIX), "\">").concat(renderChildren(), "</slot>");
76
76
  },
77
77
  };
78
78
  var SPECIAL_HTML_TAGS = ['style', 'script'];
@@ -1,4 +1,5 @@
1
1
  export type SlotMapper = (slotName: string) => string;
2
2
  export declare const isSlotProperty: (key: string, slotPrefix?: string) => boolean;
3
3
  export declare const stripSlotPrefix: (key: string, slotPrefix?: string) => string;
4
+ export declare const toKebabSlot: (key: string, slotPrefix?: string) => string;
4
5
  export declare function replaceSlotsInString(code: string, mapper: SlotMapper): string;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceSlotsInString = exports.stripSlotPrefix = exports.isSlotProperty = void 0;
3
+ exports.replaceSlotsInString = exports.toKebabSlot = exports.stripSlotPrefix = exports.isSlotProperty = void 0;
4
4
  var core_1 = require("@babel/core");
5
+ var function_1 = require("fp-ts/function");
6
+ var lodash_1 = require("lodash");
5
7
  var babel_transform_1 = require("./babel-transform");
6
8
  var SLOT_PREFIX = 'slot';
7
9
  var isSlotProperty = function (key, slotPrefix) {
@@ -14,6 +16,11 @@ var stripSlotPrefix = function (key, slotPrefix) {
14
16
  return (0, exports.isSlotProperty)(key, slotPrefix) ? key.substring(slotPrefix.length) : key;
15
17
  };
16
18
  exports.stripSlotPrefix = stripSlotPrefix;
19
+ var toKebabSlot = function (key, slotPrefix) {
20
+ if (slotPrefix === void 0) { slotPrefix = SLOT_PREFIX; }
21
+ return (0, function_1.pipe)((0, exports.stripSlotPrefix)(key, slotPrefix), lodash_1.kebabCase);
22
+ };
23
+ exports.toKebabSlot = toKebabSlot;
17
24
  function replaceSlotsInString(code, mapper) {
18
25
  return (0, babel_transform_1.babelTransformExpression)(code, {
19
26
  Identifier: function (path) {
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.2.4",
25
+ "version": "0.2.6",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {
@@ -49,7 +49,6 @@
49
49
  "remove-stableVersion": "./scripts/remove-stableVersion.sh",
50
50
  "release:dev": "yarn build && yarn run remove-stableVersion && yarn version prerelease && yarn npm publish --tag dev",
51
51
  "release:patch": "yarn build && yarn run remove-stableVersion && yarn version patch && yarn npm publish",
52
- "mitosis-save-artifacts": "node -r esbuild-register ../../scripts/mitosis-save-artifacts.ts",
53
52
  "start": "yarn rmrf && concurrently --kill-others \"yarn tsc --watch\" \"yarn tsc-alias --watch\"",
54
53
  "script": "ts-node -O '{\"module\": \"commonjs\"}'"
55
54
  },