@builder.io/mitosis 0.1.3 → 0.1.5

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.
@@ -212,8 +212,24 @@ var blockToReact = function (json, options, component, parentSlots) {
212
212
  }
213
213
  else {
214
214
  if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
215
- str += " ".concat(key, "={").concat(useBindingValue, "} ");
215
+ if (useBindingValue === 'true') {
216
+ str += " ".concat(key, " ");
217
+ }
218
+ else {
219
+ str += " ".concat(key, "={").concat(useBindingValue, "} ");
220
+ }
221
+ }
222
+ }
223
+ }
224
+ if (json.slots) {
225
+ for (var key in json.slots) {
226
+ var value = json.slots[key];
227
+ if (!(value === null || value === void 0 ? void 0 : value.length)) {
228
+ continue;
216
229
  }
230
+ var reactComponents = value.map(function (node) { return (0, exports.blockToReact)(node, options, component); });
231
+ var slotStringValue = reactComponents.length === 1 ? reactComponents[0] : "<>".concat(reactComponents.join('\n'), "</>");
232
+ str += " ".concat(key, "={").concat(slotStringValue, "} ");
217
233
  }
218
234
  }
219
235
  if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
@@ -47,7 +47,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  };
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.builderContentToMitosisComponent = exports.isBuilderElement = exports.createBuilderElement = exports.convertExportDefaultToReturn = exports.extractStateHook = exports.builderElementToMitosisNode = exports.symbolBlocksAsChildren = void 0;
50
- var mitosis_1 = require("../../generators/mitosis");
51
50
  var symbol_processor_1 = require("../../symbols/symbol-processor");
52
51
  var babel = __importStar(require("@babel/core"));
53
52
  var generator_1 = __importDefault(require("@babel/generator"));
@@ -496,6 +495,7 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
496
495
  }
497
496
  var bindings = {};
498
497
  var children = [];
498
+ var slots = {};
499
499
  if (blockBindings) {
500
500
  for (var key in blockBindings) {
501
501
  if (key === 'css') {
@@ -528,15 +528,12 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
528
528
  for (var key in block.component.options) {
529
529
  var value = block.component.options[key];
530
530
  var valueIsArrayOfBuilderElements = Array.isArray(value) && value.every(exports.isBuilderElement);
531
- var transformBldrElementToBinding = function (item) {
531
+ var transformBldrElementToMitosisNode = function (item) {
532
532
  var node = (0, exports.builderElementToMitosisNode)(item, __assign(__assign({}, options), { includeSpecialBindings: false }));
533
- // For now, stringify to Mitosis nodes even though that only really works in React, due to syntax overlap.
534
- // the correct long term solution is to hold on to the Mitosis Node, and have a plugin for each framework
535
- // which processes any Mitosis nodes set into the attribute and moves them as slots when relevant (Svelte/Vue)
536
- return (0, mitosis_1.blockToMitosis)(node, {}, null);
533
+ return node;
537
534
  };
538
535
  if ((0, exports.isBuilderElement)(value)) {
539
- bindings[key] = (0, bindings_1.createSingleBinding)({ code: transformBldrElementToBinding(value) });
536
+ slots[key] = [transformBldrElementToMitosisNode(value)];
540
537
  }
541
538
  else if (typeof value === 'string') {
542
539
  properties[key] = value;
@@ -550,9 +547,8 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
550
547
  }
551
548
  return true;
552
549
  })
553
- .map(transformBldrElementToBinding);
554
- var strVal = childrenElements.length === 1 ? childrenElements[0] : "<>".concat(childrenElements.join(''), "</>");
555
- bindings[key] = (0, bindings_1.createSingleBinding)({ code: strVal });
550
+ .map(transformBldrElementToMitosisNode);
551
+ slots[key] = childrenElements;
556
552
  }
557
553
  else {
558
554
  bindings[key] = (0, bindings_1.createSingleBinding)({ code: json5_1.default.stringify(value) });
@@ -583,6 +579,7 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
583
579
  Object.keys(css).length && {
584
580
  css: (0, bindings_1.createSingleBinding)({ code: JSON.stringify(css) }),
585
581
  })),
582
+ slots: __assign({}, slots),
586
583
  });
587
584
  // Has single text node child
588
585
  var firstChild = (_s = block.children) === null || _s === void 0 ? void 0 : _s[0];
@@ -11,6 +11,9 @@ export declare function parseText(node: TemplateNode): {
11
11
  [key: string]: import("../../..").Binding | undefined;
12
12
  };
13
13
  children: import("../../..").MitosisNode[];
14
+ slots?: {
15
+ [key: string]: import("../../..").MitosisNode[];
16
+ } | undefined;
14
17
  } | {
15
18
  name: string;
16
19
  properties: {
@@ -27,4 +30,7 @@ export declare function parseText(node: TemplateNode): {
27
30
  [key: string]: import("../../..").Binding | undefined;
28
31
  };
29
32
  children: import("../../..").MitosisNode[];
33
+ slots?: {
34
+ [key: string]: import("../../..").MitosisNode[];
35
+ } | undefined;
30
36
  };
@@ -43,6 +43,13 @@ export type BaseNode = {
43
43
  [key: string]: Binding | undefined;
44
44
  };
45
45
  children: MitosisNode[];
46
+ /**
47
+ * Key-value store of slots. The key is the slot name and the value is an array of nodes.
48
+ * It is used when components have props that are also nodes
49
+ */
50
+ slots?: {
51
+ [key: string]: MitosisNode[];
52
+ };
46
53
  };
47
54
  export type SpecialNodesNames = 'For' | 'Fragment' | 'Show' | 'Slot';
48
55
  export type ForNode = BaseNode & {
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.1.3",
25
+ "version": "0.1.5",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {