@builder.io/mitosis 0.1.2 → 0.1.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.
@@ -216,6 +216,17 @@ var blockToReact = function (json, options, component, parentSlots) {
216
216
  }
217
217
  }
218
218
  }
219
+ if (json.slots) {
220
+ for (var key in json.slots) {
221
+ var value = json.slots[key];
222
+ if (!(value === null || value === void 0 ? void 0 : value.length)) {
223
+ continue;
224
+ }
225
+ var reactComponents = value.map(function (node) { return (0, exports.blockToReact)(node, options, component); });
226
+ var slotStringValue = reactComponents.length === 1 ? reactComponents[0] : "<>".concat(reactComponents.join('\n'), "</>");
227
+ str += " ".concat(key, "={").concat(slotStringValue, "} ");
228
+ }
229
+ }
219
230
  if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
220
231
  return str + ' />';
221
232
  }
@@ -1,4 +1,4 @@
1
- import { MitosisConfig, Target } from '..';
1
+ import { MitosisConfig, Target } from '../types/config';
2
2
  export declare const COMPONENT_IMPORT_EXTENSIONS: string[];
3
3
  export declare const checkIsSvelteComponentFilePath: (filePath: string) => boolean;
4
4
  export declare const checkIsLiteComponentFilePath: (filePath: string) => boolean;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getComponentFileExtensionForTarget = exports.renameImport = exports.renameComponentFile = exports.INPUT_EXTENSION_REGEX = exports.checkIsMitosisComponentFilePath = exports.checkIsLiteComponentFilePath = exports.checkIsSvelteComponentFilePath = exports.COMPONENT_IMPORT_EXTENSIONS = void 0;
4
- var mitosis_1 = require("..");
4
+ var output_1 = require("./output");
5
5
  var COMPONENT_EXTENSIONS = {
6
6
  jsx: ['.lite.tsx', '.lite.jsx'],
7
7
  svelte: ['.svelte'],
@@ -30,7 +30,7 @@ var renameComponentFile = function (_a) {
30
30
  return path.replace(exports.INPUT_EXTENSION_REGEX, (0, exports.getComponentFileExtensionForTarget)({
31
31
  type: 'filename',
32
32
  target: target,
33
- isTypescript: (0, mitosis_1.checkShouldOutputTypeScript)({ options: options, target: target }),
33
+ isTypescript: (0, output_1.checkShouldOutputTypeScript)({ options: options, target: target }),
34
34
  }));
35
35
  };
36
36
  exports.renameComponentFile = renameComponentFile;
@@ -1,5 +1,5 @@
1
+ import { MitosisComponent, MitosisState } from '../../types/mitosis-component';
1
2
  import { BuilderContent, BuilderElement } from '@builder.io/sdk';
2
- import { MitosisComponent, MitosisState } from '../..';
3
3
  import { MitosisNode } from '../../types/mitosis-node';
4
4
  type InternalOptions = {
5
5
  skipMapper?: boolean;
@@ -47,12 +47,12 @@ 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 symbol_processor_1 = require("../../symbols/symbol-processor");
50
51
  var babel = __importStar(require("@babel/core"));
51
52
  var generator_1 = __importDefault(require("@babel/generator"));
52
53
  var json5_1 = __importDefault(require("json5"));
53
54
  var lodash_1 = require("lodash");
54
55
  var traverse_1 = __importDefault(require("traverse"));
55
- var __1 = require("../..");
56
56
  var media_sizes_1 = require("../../constants/media-sizes");
57
57
  var bindings_1 = require("../../helpers/bindings");
58
58
  var capitalize_1 = require("../../helpers/capitalize");
@@ -495,6 +495,7 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
495
495
  }
496
496
  var bindings = {};
497
497
  var children = [];
498
+ var slots = {};
498
499
  if (blockBindings) {
499
500
  for (var key in blockBindings) {
500
501
  if (key === 'css') {
@@ -527,15 +528,12 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
527
528
  for (var key in block.component.options) {
528
529
  var value = block.component.options[key];
529
530
  var valueIsArrayOfBuilderElements = Array.isArray(value) && value.every(exports.isBuilderElement);
530
- var transformBldrElementToBinding = function (item) {
531
+ var transformBldrElementToMitosisNode = function (item) {
531
532
  var node = (0, exports.builderElementToMitosisNode)(item, __assign(__assign({}, options), { includeSpecialBindings: false }));
532
- // For now, stringify to Mitosis nodes even though that only really works in React, due to syntax overlap.
533
- // the correct long term solution is to hold on to the Mitosis Node, and have a plugin for each framework
534
- // which processes any Mitosis nodes set into the attribute and moves them as slots when relevant (Svelte/Vue)
535
- return (0, __1.blockToMitosis)(node, {}, null);
533
+ return node;
536
534
  };
537
535
  if ((0, exports.isBuilderElement)(value)) {
538
- bindings[key] = (0, bindings_1.createSingleBinding)({ code: transformBldrElementToBinding(value) });
536
+ slots[key] = [transformBldrElementToMitosisNode(value)];
539
537
  }
540
538
  else if (typeof value === 'string') {
541
539
  properties[key] = value;
@@ -549,9 +547,8 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
549
547
  }
550
548
  return true;
551
549
  })
552
- .map(transformBldrElementToBinding);
553
- var strVal = childrenElements.length === 1 ? childrenElements[0] : "<>".concat(childrenElements.join(''), "</>");
554
- bindings[key] = (0, bindings_1.createSingleBinding)({ code: strVal });
550
+ .map(transformBldrElementToMitosisNode);
551
+ slots[key] = childrenElements;
555
552
  }
556
553
  else {
557
554
  bindings[key] = (0, bindings_1.createSingleBinding)({ code: json5_1.default.stringify(value) });
@@ -582,6 +579,7 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
582
579
  Object.keys(css).length && {
583
580
  css: (0, bindings_1.createSingleBinding)({ code: JSON.stringify(css) }),
584
581
  })),
582
+ slots: __assign({}, slots),
585
583
  });
586
584
  // Has single text node child
587
585
  var firstChild = (_s = block.children) === null || _s === void 0 ? void 0 : _s[0];
@@ -751,7 +749,7 @@ function extractSymbols(json) {
751
749
  subComponents: subComponents,
752
750
  };
753
751
  }
754
- var createBuilderElement = function (options) { return (__assign({ '@type': '@builder.io/sdk:Element', id: 'builder-' + (0, __1.hashCodeAsString)(options) }, options)); };
752
+ var createBuilderElement = function (options) { return (__assign({ '@type': '@builder.io/sdk:Element', id: 'builder-' + (0, symbol_processor_1.hashCodeAsString)(options) }, options)); };
755
753
  exports.createBuilderElement = createBuilderElement;
756
754
  var isBuilderElement = function (el) {
757
755
  return (el === null || el === void 0 ? void 0 : el['@type']) === '@builder.io/sdk:Element';
@@ -29,7 +29,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getUseTargetStatements = exports.getIdFromMatch = exports.USE_TARGET_MAGIC_REGEX = exports.USE_TARGET_MAGIC_STRING = exports.getMagicString = exports.getTargetId = void 0;
30
30
  var babel = __importStar(require("@babel/core"));
31
31
  var generator_1 = __importDefault(require("@babel/generator"));
32
- var targets_1 = require("../../../targets");
32
+ var TARGETS = {
33
+ alpine: null,
34
+ angular: null,
35
+ customElement: null,
36
+ html: null,
37
+ mitosis: null,
38
+ liquid: null,
39
+ react: null,
40
+ reactNative: null,
41
+ solid: null,
42
+ svelte: null,
43
+ swift: null,
44
+ template: null,
45
+ webcomponent: null,
46
+ vue: null,
47
+ stencil: null,
48
+ qwik: null,
49
+ marko: null,
50
+ preact: null,
51
+ lit: null,
52
+ rsc: null,
53
+ taro: null,
54
+ };
33
55
  var types = babel.types;
34
56
  var getTargetId = function (component) {
35
57
  var latestId = Object.keys(component.targetBlocks || {}).length;
@@ -76,7 +98,7 @@ var getUseTargetStatements = function (path) {
76
98
  if (!types.isIdentifier(prop.key)) {
77
99
  throw new Error('ERROR Parsing `useTarget()`: Expected an identifier, instead got: ' + prop.key);
78
100
  }
79
- if (!Object.keys(targets_1.targets).concat('default').includes(prop.key.name)) {
101
+ if (!Object.keys(TARGETS).concat('default').includes(prop.key.name)) {
80
102
  throw new Error('ERROR Parsing `useTarget()`: Invalid target: ' + prop.key.name);
81
103
  }
82
104
  var keyName = prop.key.name;
@@ -39,7 +39,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.parseStateObjectToMitosisState = exports.mapStateIdentifiers = void 0;
41
41
  var babel = __importStar(require("@babel/core"));
42
- var generator_1 = __importDefault(require("@babel/generator"));
43
42
  var function_1 = require("fp-ts/lib/function");
44
43
  var traverse_1 = __importDefault(require("traverse"));
45
44
  var babel_transform_1 = require("../../helpers/babel-transform");
@@ -79,12 +78,13 @@ function mapStateIdentifiersInExpression(expression, stateProperties) {
79
78
  path.replaceWith(newExpression);
80
79
  }
81
80
  catch (err) {
82
- console.log('err: ', {
83
- from: (0, generator_1.default)(path.parent).code,
84
- fromChild: (0, generator_1.default)(path.node).code,
85
- to: newExpression,
86
- // err,
87
- });
81
+ console.error(err);
82
+ // console.log('err: ', {
83
+ // from: generate(path.parent).code,
84
+ // fromChild: generate(path.node).code,
85
+ // to: newExpression,
86
+ // // err,
87
+ // });
88
88
  }
89
89
  }
90
90
  }
@@ -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.2",
25
+ "version": "0.1.4",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {