@builder.io/mitosis 0.0.89 → 0.0.91

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.
@@ -1,24 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
- if (ar || !(i in from)) {
16
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
- ar[i] = from[i];
18
- }
19
- }
20
- return to.concat(ar || Array.prototype.slice.call(from));
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
@@ -29,6 +9,7 @@ var traverse_1 = __importDefault(require("traverse"));
29
9
  var fast_clone_1 = require("../helpers/fast-clone");
30
10
  var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
31
11
  var react_1 = require("./react");
12
+ var merge_options_1 = require("../helpers/merge-options");
32
13
  /**
33
14
  * Transform react to be RSC compatible, such as
34
15
  * - remove event listeners
@@ -84,7 +65,11 @@ var componentToRsc = function (_options) {
84
65
  return function (_a) {
85
66
  var component = _a.component, path = _a.path;
86
67
  var json = (0, fast_clone_1.fastClone)(component);
87
- var options = __assign(__assign(__assign({}, DEFAULT_OPTIONS), _options), { plugins: __spreadArray(__spreadArray([], (DEFAULT_OPTIONS.plugins || []), true), (_options.plugins || []), true), stylesType: 'style-tag', stateType: 'variables', contextType: 'prop-drill' });
68
+ var options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, _options, {
69
+ stylesType: 'style-tag',
70
+ stateType: 'variables',
71
+ contextType: 'prop-drill',
72
+ });
88
73
  return (0, react_1.componentToReact)(options)({ component: json, path: path });
89
74
  };
90
75
  };
@@ -8,7 +8,6 @@ function collectClassString(json, bindingOpenChar, bindingCloseChar) {
8
8
  if (bindingOpenChar === void 0) { bindingOpenChar = '{'; }
9
9
  if (bindingCloseChar === void 0) { bindingCloseChar = '}'; }
10
10
  var staticClasses = [];
11
- var hasStaticClasses = Boolean(staticClasses.length);
12
11
  if (json.properties.class) {
13
12
  staticClasses.push(json.properties.class);
14
13
  delete json.properties.class;
@@ -28,6 +27,7 @@ function collectClassString(json, bindingOpenChar, bindingCloseChar) {
28
27
  }
29
28
  var staticClassesString = staticClasses.join(' ');
30
29
  var dynamicClassesString = dynamicClasses.join(" + ' ' + ");
30
+ var hasStaticClasses = Boolean(staticClasses.length);
31
31
  var hasDynamicClasses = Boolean(dynamicClasses.length);
32
32
  if (hasStaticClasses && !hasDynamicClasses) {
33
33
  return "\"".concat(staticClassesString, "\"");
@@ -0,0 +1,9 @@
1
+ import { ClassStyleMap } from '../helpers/styles/helpers';
2
+ import { MitosisComponent } from '../types/mitosis-component';
3
+ import { ToReactOptions } from './react';
4
+ import { TranspilerGenerator } from '../types/transpiler';
5
+ export declare const DEFAULT_Component_SET: Set<string>;
6
+ export declare type ToTaroOptions = ToReactOptions;
7
+ export declare const collectTaroStyles: (json: MitosisComponent) => ClassStyleMap;
8
+ export declare const TagMap: Record<string, string>;
9
+ export declare const componentToTaro: TranspilerGenerator<Partial<ToTaroOptions>>;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.componentToTaro = exports.TagMap = exports.collectTaroStyles = exports.DEFAULT_Component_SET = void 0;
7
+ var json5_1 = __importDefault(require("json5"));
8
+ var lodash_1 = require("lodash");
9
+ var traverse_1 = __importDefault(require("traverse"));
10
+ var fast_clone_1 = require("../helpers/fast-clone");
11
+ var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
12
+ var react_1 = require("./react");
13
+ var bindings_1 = require("../helpers/bindings");
14
+ var merge_options_1 = require("../helpers/merge-options");
15
+ // @tarojs/components
16
+ exports.DEFAULT_Component_SET = new Set([
17
+ 'View',
18
+ 'Icon',
19
+ 'Progress',
20
+ 'RichText',
21
+ 'Text',
22
+ 'Button',
23
+ 'Checkbox',
24
+ 'CheckboxGroup',
25
+ 'Form',
26
+ 'Input',
27
+ 'Label',
28
+ 'Picker',
29
+ 'PickerView',
30
+ 'PickerViewColumn',
31
+ 'Radio',
32
+ 'RadioGroup',
33
+ 'Slider',
34
+ 'Switch',
35
+ 'CoverImage',
36
+ 'Textarea',
37
+ 'CoverView',
38
+ 'MovableArea',
39
+ 'MovableView',
40
+ 'ScrollView',
41
+ 'Swiper',
42
+ 'SwiperItem',
43
+ 'Navigator',
44
+ 'Audio',
45
+ 'Camera',
46
+ 'Image',
47
+ 'LivePlayer',
48
+ 'Video',
49
+ 'Canvas',
50
+ 'Ad',
51
+ 'WebView',
52
+ 'Block',
53
+ 'Map',
54
+ 'Slot',
55
+ 'SlotView',
56
+ 'Editor',
57
+ 'MatchMedia',
58
+ 'FunctionalPageNavigator',
59
+ 'LivePusher',
60
+ 'OfficialAccount',
61
+ 'OpenData',
62
+ 'NavigationBar',
63
+ 'PageMeta',
64
+ 'VoipRoom',
65
+ 'AdCustom',
66
+ ]);
67
+ // TODO: px to 2 px
68
+ var collectTaroStyles = function (json) {
69
+ var styleMap = {};
70
+ var componentIndexes = {};
71
+ (0, traverse_1.default)(json).forEach(function (item) {
72
+ var _a;
73
+ if (!(0, is_mitosis_node_1.isMitosisNode)(item) || typeof ((_a = item.bindings.css) === null || _a === void 0 ? void 0 : _a.code) !== 'string') {
74
+ return;
75
+ }
76
+ var value = json5_1.default.parse(item.bindings.css.code);
77
+ delete item.bindings.css;
78
+ if (!(0, lodash_1.size)(value)) {
79
+ return;
80
+ }
81
+ for (var key in value) {
82
+ var propertyValue = value[key];
83
+ // convert px to 2 * px, PX to PX
84
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\d/)) {
85
+ var newValue = parseFloat(propertyValue);
86
+ if (!isNaN(newValue)) {
87
+ if (propertyValue.endsWith('px')) {
88
+ newValue = 2 * newValue;
89
+ value[key] = "".concat(newValue, "px");
90
+ }
91
+ else {
92
+ value[key] = newValue;
93
+ }
94
+ }
95
+ }
96
+ }
97
+ var componentName = (0, lodash_1.camelCase)(item.name || 'view');
98
+ var index = (componentIndexes[componentName] = (componentIndexes[componentName] || 0) + 1);
99
+ var className = "".concat(componentName).concat(index);
100
+ item.bindings.style = (0, bindings_1.createSingleBinding)({ code: "styles.".concat(className) });
101
+ styleMap[className] = value;
102
+ });
103
+ return styleMap;
104
+ };
105
+ exports.collectTaroStyles = collectTaroStyles;
106
+ exports.TagMap = {
107
+ span: 'Text',
108
+ button: 'Button',
109
+ input: 'Input',
110
+ img: 'Image',
111
+ form: 'Form',
112
+ textarea: 'Textarea',
113
+ };
114
+ /**
115
+ * Plugin that handles necessary transformations from React to React Native:
116
+ * - Converts DOM tags to @tarojs/components
117
+ * - Removes redundant `class`/`className` attributes
118
+ */
119
+ var PROCESS_TARO_PLUGIN = function () { return ({
120
+ json: {
121
+ pre: function (json) {
122
+ var TaroComponentsImports = { path: '@tarojs/components', imports: {} };
123
+ json.imports.push(TaroComponentsImports);
124
+ (0, traverse_1.default)(json).forEach(function (node) {
125
+ var _a, _b, _c, _d;
126
+ if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
127
+ // TODO: More dom tags convert to @tarojs/components
128
+ if (!!exports.TagMap[node.name]) {
129
+ TaroComponentsImports.imports[exports.TagMap[node.name]] = exports.TagMap[node.name];
130
+ node.name = exports.TagMap[node.name];
131
+ }
132
+ else if (node.name.toLowerCase() === node.name) {
133
+ TaroComponentsImports.imports.View = 'View';
134
+ node.name = 'View';
135
+ }
136
+ if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) || ((_d = (_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.length)) {
137
+ TaroComponentsImports.imports.Text = 'Text';
138
+ node.name = 'Text';
139
+ }
140
+ if (node.properties.class) {
141
+ delete node.properties.class;
142
+ }
143
+ if (node.properties.className) {
144
+ delete node.properties.className;
145
+ }
146
+ if (node.bindings.class) {
147
+ delete node.bindings.class;
148
+ }
149
+ if (node.bindings.className) {
150
+ delete node.bindings.className;
151
+ }
152
+ }
153
+ });
154
+ },
155
+ },
156
+ }); };
157
+ var DEFAULT_OPTIONS = {
158
+ stateType: 'useState',
159
+ plugins: [PROCESS_TARO_PLUGIN],
160
+ };
161
+ var componentToTaro = function (_options) {
162
+ if (_options === void 0) { _options = {}; }
163
+ return function (_a) {
164
+ var component = _a.component, path = _a.path;
165
+ var json = (0, fast_clone_1.fastClone)(component);
166
+ var options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, _options, {
167
+ type: 'taro',
168
+ });
169
+ return (0, react_1.componentToReact)(options)({ component: json, path: path });
170
+ };
171
+ };
172
+ exports.componentToTaro = componentToTaro;
@@ -2,6 +2,6 @@ import { BaseTranspilerOptions } from '..';
2
2
  /**
3
3
  * Merges options while combining the `plugins` array.
4
4
  */
5
- export declare const mergeOptions: <T extends BaseTranspilerOptions>(a: T, b?: Partial<T>) => T & {
5
+ export declare const mergeOptions: <T extends BaseTranspilerOptions>(a: T, b?: Partial<T>, c?: Partial<T> | undefined) => T & {
6
6
  plugins: NonNullable<T["plugins"]>;
7
7
  };
@@ -24,8 +24,8 @@ exports.mergeOptions = void 0;
24
24
  /**
25
25
  * Merges options while combining the `plugins` array.
26
26
  */
27
- var mergeOptions = function (a, b) {
27
+ var mergeOptions = function (a, b, c) {
28
28
  if (b === void 0) { b = {}; }
29
- return __assign(__assign(__assign({}, a), b), { plugins: __spreadArray(__spreadArray([], (a.plugins || []), true), (b.plugins || []), true) });
29
+ return __assign(__assign(__assign(__assign({}, a), b), c), { plugins: __spreadArray(__spreadArray(__spreadArray([], (a.plugins || []), true), (b.plugins || []), true), ((c === null || c === void 0 ? void 0 : c.plugins) || []), true) });
30
30
  };
31
31
  exports.mergeOptions = mergeOptions;
@@ -60,6 +60,7 @@ export * from './generators/template';
60
60
  export * from './generators/swift-ui';
61
61
  export * from './generators/lit';
62
62
  export * from './generators/react-native';
63
+ export * from './generators/taro';
63
64
  export * from './helpers/is-mitosis-node';
64
65
  export * from './types/mitosis-node';
65
66
  export * from './types/mitosis-component';
package/dist/src/index.js CHANGED
@@ -97,6 +97,7 @@ __exportStar(require("./generators/template"), exports);
97
97
  __exportStar(require("./generators/swift-ui"), exports);
98
98
  __exportStar(require("./generators/lit"), exports);
99
99
  __exportStar(require("./generators/react-native"), exports);
100
+ __exportStar(require("./generators/taro"), exports);
100
101
  __exportStar(require("./helpers/is-mitosis-node"), exports);
101
102
  __exportStar(require("./types/mitosis-node"), exports);
102
103
  __exportStar(require("./types/mitosis-component"), exports);
@@ -6,8 +6,8 @@ export declare const targets: {
6
6
  readonly html: import(".").TranspilerGenerator<import("./generators/html").ToHtmlOptions, string>;
7
7
  readonly mitosis: import(".").TranspilerGenerator<Partial<import("./generators/mitosis").ToMitosisOptions>, string>;
8
8
  readonly liquid: import(".").TranspilerGenerator<import("./generators/liquid").ToLiquidOptions, string>;
9
- readonly react: import(".").TranspilerGenerator<import("./generators/react").ToReactOptions, string>;
10
- readonly reactNative: import(".").TranspilerGenerator<import("./generators/react-native").ToReactNativeOptions, string>;
9
+ readonly react: import(".").TranspilerGenerator<Partial<import("./generators/react").ToReactOptions>, string>;
10
+ readonly reactNative: import(".").TranspilerGenerator<Partial<import("./generators/react-native").ToReactNativeOptions>, string>;
11
11
  readonly solid: import(".").TranspilerGenerator<Partial<import("./generators/solid/types").ToSolidOptions>, string>;
12
12
  readonly svelte: import(".").TranspilerGenerator<import("./generators/svelte/types").ToSvelteOptions, string>;
13
13
  readonly swift: import(".").TranspilerGenerator<import(".").BaseTranspilerOptions, string>;
@@ -19,7 +19,8 @@ export declare const targets: {
19
19
  readonly stencil: import(".").TranspilerGenerator<import("./generators/stencil").ToStencilOptions, string>;
20
20
  readonly qwik: import(".").TranspilerGenerator<import("./generators/qwik/component-generator").ToQwikOptions, string>;
21
21
  readonly marko: import(".").TranspilerGenerator<import("./generators/marko").ToMarkoOptions, string>;
22
- readonly preact: import(".").TranspilerGenerator<import("./generators/react").ToReactOptions, string>;
22
+ readonly preact: import(".").TranspilerGenerator<Partial<import("./generators/react").ToReactOptions>, string>;
23
23
  readonly lit: import(".").TranspilerGenerator<import("./generators/lit").ToLitOptions, string>;
24
- readonly rsc: import(".").TranspilerGenerator<import("./generators/rsc").ToRscOptions, string>;
24
+ readonly rsc: import(".").TranspilerGenerator<Partial<import("./generators/react").ToReactOptions>, string>;
25
+ readonly taro: import(".").TranspilerGenerator<Partial<import("./generators/react").ToReactOptions>, string>;
25
26
  };
@@ -20,6 +20,7 @@ var qwik_1 = require("./generators/qwik");
20
20
  var marko_1 = require("./generators/marko");
21
21
  var lit_1 = require("./generators/lit");
22
22
  var rsc_1 = require("./generators/rsc");
23
+ var taro_1 = require("./generators/taro");
23
24
  exports.builder = builder_1.componentToBuilder;
24
25
  exports.targets = {
25
26
  alpine: alpine_1.componentToAlpine,
@@ -44,4 +45,5 @@ exports.targets = {
44
45
  preact: react_2.componentToPreact,
45
46
  lit: lit_1.componentToLit,
46
47
  rsc: rsc_1.componentToRsc,
48
+ taro: taro_1.componentToTaro,
47
49
  };
@@ -24,6 +24,10 @@ export declare type MitosisConfig = {
24
24
  * globs of files to transpile. Defaults to `src/*`.
25
25
  */
26
26
  files?: string | string[];
27
+ /**
28
+ * Optional list of globs to exclude from transpilation.
29
+ */
30
+ exclude?: string[];
27
31
  /**
28
32
  * The directory where overrides are stored. The structure of the override directory must match that of the source code,
29
33
  * with each target having its own sub-directory: `${overridesDir}/${target}/*`