@builder.io/mitosis 0.4.0 → 0.4.2
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.
- package/dist/src/constants/media-sizes.js +4 -5
- package/dist/src/generators/alpine/generate.js +114 -132
- package/dist/src/generators/alpine/render-mount-hook.js +8 -5
- package/dist/src/generators/alpine/render-update-hooks.js +13 -13
- package/dist/src/generators/angular/helpers.js +19 -9
- package/dist/src/generators/angular/index.js +599 -584
- package/dist/src/generators/builder.js +200 -165
- package/dist/src/generators/context/angular.js +32 -26
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +25 -21
- package/dist/src/generators/context/qwik.js +21 -21
- package/dist/src/generators/context/react.js +22 -22
- package/dist/src/generators/context/rsc.js +20 -22
- package/dist/src/generators/context/solid.js +22 -22
- package/dist/src/generators/context/svelte.js +33 -28
- package/dist/src/generators/context/vue.js +1 -1
- package/dist/src/generators/helpers/context.js +6 -13
- package/dist/src/generators/helpers/functions.js +8 -8
- package/dist/src/generators/helpers/on-mount.js +9 -5
- package/dist/src/generators/helpers/rsc.js +7 -9
- package/dist/src/generators/html.js +995 -534
- package/dist/src/generators/liquid.js +81 -79
- package/dist/src/generators/lit/collect-class-string.js +10 -12
- package/dist/src/generators/lit/generate.js +204 -159
- package/dist/src/generators/marko/generate.js +193 -183
- package/dist/src/generators/minify.js +5 -9
- package/dist/src/generators/mitosis.js +135 -134
- package/dist/src/generators/qwik/component-generator.js +159 -154
- package/dist/src/generators/qwik/component.js +51 -81
- package/dist/src/generators/qwik/directives.js +68 -84
- package/dist/src/generators/qwik/helpers/add-prevent-default.js +6 -7
- package/dist/src/generators/qwik/helpers/convert-method-to-function.js +38 -38
- package/dist/src/generators/qwik/helpers/handlers.js +16 -25
- package/dist/src/generators/qwik/helpers/stable-inject.js +7 -8
- package/dist/src/generators/qwik/helpers/stable-serialize.js +7 -8
- package/dist/src/generators/qwik/helpers/state.js +36 -43
- package/dist/src/generators/qwik/helpers/styles.js +19 -40
- package/dist/src/generators/qwik/jsx.js +63 -75
- package/dist/src/generators/qwik/src-generator.js +134 -167
- package/dist/src/generators/react/blocks.js +122 -127
- package/dist/src/generators/react/generator.js +314 -259
- package/dist/src/generators/react/helpers.js +23 -28
- package/dist/src/generators/react/state.js +34 -51
- package/dist/src/generators/react-native/index.js +72 -84
- package/dist/src/generators/react-native/sanitize-react-native-block-styles.js +14 -26
- package/dist/src/generators/rsc.js +30 -36
- package/dist/src/generators/solid/blocks.js +46 -43
- package/dist/src/generators/solid/helpers/styles.js +11 -11
- package/dist/src/generators/solid/index.js +199 -190
- package/dist/src/generators/solid/state/helpers.js +76 -90
- package/dist/src/generators/solid/state/signals.js +30 -37
- package/dist/src/generators/solid/state/state.js +35 -48
- package/dist/src/generators/solid/state/store.js +40 -46
- package/dist/src/generators/stencil/collect-class-string.js +10 -12
- package/dist/src/generators/stencil/generate.js +158 -145
- package/dist/src/generators/svelte/blocks.js +146 -144
- package/dist/src/generators/svelte/helpers.js +10 -17
- package/dist/src/generators/svelte/svelte.js +321 -287
- package/dist/src/generators/swift-ui.js +162 -101
- package/dist/src/generators/taro.js +32 -36
- package/dist/src/generators/template.js +71 -74
- package/dist/src/generators/vue/blocks.js +116 -107
- package/dist/src/generators/vue/compositionApi.js +67 -50
- package/dist/src/generators/vue/helpers.js +71 -96
- package/dist/src/generators/vue/optionsApi.js +134 -105
- package/dist/src/generators/vue/vue.js +210 -207
- package/dist/src/helpers/babel-transform.js +40 -63
- package/dist/src/helpers/bindings.js +4 -12
- package/dist/src/helpers/camel-case.js +4 -5
- package/dist/src/helpers/capitalize.js +1 -1
- package/dist/src/helpers/component-file-extensions.js +23 -35
- package/dist/src/helpers/create-mitosis-component.js +22 -26
- package/dist/src/helpers/create-mitosis-context.js +5 -12
- package/dist/src/helpers/create-mitosis-node.js +10 -12
- package/dist/src/helpers/dash-case.js +2 -2
- package/dist/src/helpers/dedent.js +18 -22
- package/dist/src/helpers/event-handlers.js +1 -1
- package/dist/src/helpers/fast-clone.js +1 -1
- package/dist/src/helpers/filter-empty-text-nodes.js +2 -2
- package/dist/src/helpers/generic-format.js +7 -8
- package/dist/src/helpers/get-bindings.js +4 -4
- package/dist/src/helpers/get-components-used.js +3 -3
- package/dist/src/helpers/get-components.js +4 -4
- package/dist/src/helpers/get-custom-imports.js +10 -12
- package/dist/src/helpers/get-prop-functions.js +7 -8
- package/dist/src/helpers/get-props-ref.js +8 -8
- package/dist/src/helpers/get-props.js +12 -13
- package/dist/src/helpers/get-refs.js +4 -4
- package/dist/src/helpers/get-state-object-string.js +42 -61
- package/dist/src/helpers/get-state-used.js +7 -8
- package/dist/src/helpers/get-styles.js +6 -6
- package/dist/src/helpers/getters-to-functions.js +8 -12
- package/dist/src/helpers/handle-missing-state.js +3 -3
- package/dist/src/helpers/has-bindings-text.js +6 -6
- package/dist/src/helpers/has-component.js +4 -4
- package/dist/src/helpers/has-props.js +3 -3
- package/dist/src/helpers/has-stateful-dom.js +4 -4
- package/dist/src/helpers/has.js +3 -3
- package/dist/src/helpers/indent.js +2 -3
- package/dist/src/helpers/is-children.js +4 -5
- package/dist/src/helpers/is-component.js +1 -1
- package/dist/src/helpers/is-html-attribute.js +2 -11
- package/dist/src/helpers/is-mitosis-node.js +1 -1
- package/dist/src/helpers/is-root-text-node.js +1 -1
- package/dist/src/helpers/is-upper-case.js +1 -1
- package/dist/src/helpers/is-valid-attribute-name.js +1 -1
- package/dist/src/helpers/json.js +2 -2
- package/dist/src/helpers/map-refs.js +29 -40
- package/dist/src/helpers/merge-options.js +20 -31
- package/dist/src/helpers/mitosis-imports.js +5 -6
- package/dist/src/helpers/nodes/for.js +2 -3
- package/dist/src/helpers/nullable.js +1 -3
- package/dist/src/helpers/on-event.js +32 -36
- package/dist/src/helpers/output.js +4 -5
- package/dist/src/helpers/parse-node.js +13 -5
- package/dist/src/helpers/parsers.js +10 -14
- package/dist/src/helpers/patterns.js +6 -8
- package/dist/src/helpers/plugins/process-code/index.js +114 -120
- package/dist/src/helpers/plugins/process-signals.js +114 -125
- package/dist/src/helpers/plugins/process-target-blocks.js +18 -20
- package/dist/src/helpers/process-http-requests.js +8 -4
- package/dist/src/helpers/remove-surrounding-block.js +2 -2
- package/dist/src/helpers/render-imports.js +99 -111
- package/dist/src/helpers/replace-identifiers.js +40 -49
- package/dist/src/helpers/replace-new-lines-in-strings.js +3 -3
- package/dist/src/helpers/signals/signals.js +27 -35
- package/dist/src/helpers/slots.js +11 -20
- package/dist/src/helpers/state.js +1 -3
- package/dist/src/helpers/strip-meta-properties.js +6 -6
- package/dist/src/helpers/strip-state-and-props-refs.js +21 -32
- package/dist/src/helpers/styles/collect-css.js +39 -44
- package/dist/src/helpers/styles/collect-styled-components.js +30 -28
- package/dist/src/helpers/styles/helpers.js +23 -29
- package/dist/src/helpers/trace-reference-to-module-path.js +3 -4
- package/dist/src/helpers/transform-state-setters.js +16 -19
- package/dist/src/helpers/traverse-nodes.js +2 -2
- package/dist/src/helpers/try-prettier-format.js +3 -3
- package/dist/src/helpers/typescript-project.js +25 -25
- package/dist/src/helpers/typescript.js +1 -3
- package/dist/src/modules/plugins.js +20 -28
- package/dist/src/parsers/angular.js +49 -57
- package/dist/src/parsers/builder/builder.js +448 -343
- package/dist/src/parsers/builder/helpers.js +10 -10
- package/dist/src/parsers/context.js +15 -17
- package/dist/src/parsers/jsx/ast.js +11 -11
- package/dist/src/parsers/jsx/component-types.js +22 -32
- package/dist/src/parsers/jsx/context.js +12 -12
- package/dist/src/parsers/jsx/element-parser.js +43 -54
- package/dist/src/parsers/jsx/exports.js +12 -14
- package/dist/src/parsers/jsx/function-parser.js +108 -119
- package/dist/src/parsers/jsx/helpers.js +11 -13
- package/dist/src/parsers/jsx/hooks/helpers.js +14 -16
- package/dist/src/parsers/jsx/hooks/index.js +34 -44
- package/dist/src/parsers/jsx/hooks/use-target.js +27 -27
- package/dist/src/parsers/jsx/imports.js +7 -17
- package/dist/src/parsers/jsx/jsx.js +92 -91
- package/dist/src/parsers/jsx/props-types.js +8 -10
- package/dist/src/parsers/jsx/props.js +15 -23
- package/dist/src/parsers/jsx/signals.js +28 -29
- package/dist/src/parsers/jsx/state.d.ts +2 -4
- package/dist/src/parsers/jsx/state.js +59 -93
- package/dist/src/parsers/svelte/css/index.js +1 -1
- package/dist/src/parsers/svelte/helpers/bindings.js +18 -19
- package/dist/src/parsers/svelte/helpers/children.js +5 -6
- package/dist/src/parsers/svelte/helpers/expressions.js +7 -9
- package/dist/src/parsers/svelte/helpers/hooks.js +2 -2
- package/dist/src/parsers/svelte/helpers/post-process.js +49 -70
- package/dist/src/parsers/svelte/helpers/string.js +5 -5
- package/dist/src/parsers/svelte/html/actions.js +17 -10
- package/dist/src/parsers/svelte/html/each.js +11 -16
- package/dist/src/parsers/svelte/html/element.js +68 -78
- package/dist/src/parsers/svelte/html/fragment.js +3 -3
- package/dist/src/parsers/svelte/html/if-else.js +11 -18
- package/dist/src/parsers/svelte/html/index.js +14 -14
- package/dist/src/parsers/svelte/html/mustache-tag.js +5 -5
- package/dist/src/parsers/svelte/html/slot.js +5 -5
- package/dist/src/parsers/svelte/html/text.js +7 -14
- package/dist/src/parsers/svelte/index.js +23 -72
- package/dist/src/parsers/svelte/instance/context.js +17 -17
- package/dist/src/parsers/svelte/instance/expressions.js +2 -2
- package/dist/src/parsers/svelte/instance/functions.js +35 -30
- package/dist/src/parsers/svelte/instance/hooks.js +4 -5
- package/dist/src/parsers/svelte/instance/imports.js +11 -21
- package/dist/src/parsers/svelte/instance/index.js +22 -22
- package/dist/src/parsers/svelte/instance/properties.js +11 -23
- package/dist/src/parsers/svelte/instance/reactive.js +11 -11
- package/dist/src/parsers/svelte/instance/references.js +13 -13
- package/dist/src/parsers/svelte/instance/statements.js +3 -3
- package/dist/src/parsers/svelte/module/index.js +14 -26
- package/dist/src/parsers/svelte/typescript/index.js +27 -36
- package/dist/src/plugins/compile-away-builder-components.js +223 -156
- package/dist/src/plugins/compile-away-components.js +13 -21
- package/dist/src/plugins/map-styles.js +7 -7
- package/dist/src/symbols/symbol-processor.js +44 -62
- package/dist/src/targets.js +19 -19
- package/dist/src/types/mitosis-node.js +1 -1
- package/package.json +1 -1
|
@@ -1,58 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
-
if (ar || !(i in from)) {
|
|
20
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
-
ar[i] = from[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
-
};
|
|
26
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
4
|
};
|
|
29
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
6
|
exports.componentToMitosis = exports.blockToMitosis = exports.DEFAULT_FORMAT = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
7
|
+
const plugins_1 = require("../modules/plugins");
|
|
8
|
+
const json5_1 = __importDefault(require("json5"));
|
|
9
|
+
const standalone_1 = require("prettier/standalone");
|
|
10
|
+
const hooks_1 = require("../constants/hooks");
|
|
11
|
+
const html_tags_1 = require("../constants/html_tags");
|
|
12
|
+
const dedent_1 = require("../helpers/dedent");
|
|
13
|
+
const fast_clone_1 = require("../helpers/fast-clone");
|
|
14
|
+
const get_components_1 = require("../helpers/get-components");
|
|
15
|
+
const get_refs_1 = require("../helpers/get-refs");
|
|
16
|
+
const get_state_object_string_1 = require("../helpers/get-state-object-string");
|
|
17
|
+
const is_root_text_node_1 = require("../helpers/is-root-text-node");
|
|
18
|
+
const map_refs_1 = require("../helpers/map-refs");
|
|
19
|
+
const render_imports_1 = require("../helpers/render-imports");
|
|
20
|
+
const state_1 = require("../helpers/state");
|
|
21
|
+
const mitosis_node_1 = require("../types/mitosis-node");
|
|
22
|
+
const react_1 = require("./react");
|
|
47
23
|
exports.DEFAULT_FORMAT = 'legacy';
|
|
48
24
|
// Special isValidAttributeName for Mitosis so we can allow for $ in names
|
|
49
|
-
|
|
25
|
+
const isValidAttributeName = (str) => {
|
|
50
26
|
return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
|
|
51
27
|
};
|
|
52
|
-
|
|
28
|
+
const blockToMitosis = (json, toMitosisOptions = {}, component) => {
|
|
53
29
|
var _a, _b, _c, _d, _e, _f;
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
const options = {
|
|
31
|
+
format: exports.DEFAULT_FORMAT,
|
|
32
|
+
...toMitosisOptions,
|
|
33
|
+
};
|
|
56
34
|
if (options.format === 'react') {
|
|
57
35
|
return (0, react_1.blockToReact)(json, {
|
|
58
36
|
format: 'lite',
|
|
@@ -63,40 +41,45 @@ var blockToMitosis = function (json, toMitosisOptions, component) {
|
|
|
63
41
|
}, component, true);
|
|
64
42
|
}
|
|
65
43
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
66
|
-
|
|
67
|
-
return
|
|
44
|
+
const needsWrapper = json.children.length !== 1;
|
|
45
|
+
return `<For each={${(_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code}}>
|
|
46
|
+
{(${json.scope.forName}, ${json.scope.indexName || 'index'}) =>
|
|
47
|
+
${needsWrapper ? '<>' : ''}
|
|
48
|
+
${json.children.map((child) => (0, exports.blockToMitosis)(child, options, component))}}
|
|
49
|
+
${needsWrapper ? '</>' : ''}
|
|
50
|
+
</For>`;
|
|
68
51
|
}
|
|
69
52
|
if (json.properties._text) {
|
|
70
53
|
return json.properties._text;
|
|
71
54
|
}
|
|
72
55
|
if ((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code) {
|
|
73
|
-
return
|
|
56
|
+
return `{${(_c = json.bindings._text) === null || _c === void 0 ? void 0 : _c.code}}`;
|
|
74
57
|
}
|
|
75
|
-
|
|
76
|
-
str +=
|
|
77
|
-
for (
|
|
78
|
-
|
|
58
|
+
let str = '';
|
|
59
|
+
str += `<${json.name} `;
|
|
60
|
+
for (const key in json.properties) {
|
|
61
|
+
const value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
79
62
|
if (!isValidAttributeName(key)) {
|
|
80
63
|
console.warn('Skipping invalid attribute name:', key);
|
|
81
64
|
}
|
|
82
65
|
else {
|
|
83
|
-
str +=
|
|
66
|
+
str += ` ${key}="${value}" `;
|
|
84
67
|
}
|
|
85
68
|
}
|
|
86
|
-
for (
|
|
87
|
-
|
|
69
|
+
for (const key in json.bindings) {
|
|
70
|
+
const value = (_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.code;
|
|
88
71
|
if (((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.type) === 'spread') {
|
|
89
|
-
str +=
|
|
72
|
+
str += ` {...(${(_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code})} `;
|
|
90
73
|
}
|
|
91
74
|
else if (key.startsWith('on')) {
|
|
92
|
-
str +=
|
|
75
|
+
str += ` ${key}={event => ${value.replace(/\s*;$/, '')}} `;
|
|
93
76
|
}
|
|
94
77
|
else {
|
|
95
78
|
if (!isValidAttributeName(key)) {
|
|
96
79
|
console.warn('Skipping invalid attribute name:', key);
|
|
97
80
|
}
|
|
98
81
|
else {
|
|
99
|
-
str +=
|
|
82
|
+
str += ` ${key}={${value}} `;
|
|
100
83
|
}
|
|
101
84
|
}
|
|
102
85
|
}
|
|
@@ -110,92 +93,110 @@ var blockToMitosis = function (json, toMitosisOptions, component) {
|
|
|
110
93
|
}
|
|
111
94
|
str += '>';
|
|
112
95
|
if (json.children) {
|
|
113
|
-
str += json.children.map(
|
|
96
|
+
str += json.children.map((item) => (0, exports.blockToMitosis)(item, options, component)).join('\n');
|
|
114
97
|
}
|
|
115
|
-
str +=
|
|
98
|
+
str += `</${json.name}>`;
|
|
116
99
|
return str;
|
|
117
100
|
};
|
|
118
101
|
exports.blockToMitosis = blockToMitosis;
|
|
119
|
-
|
|
102
|
+
const getRefsString = (json, refs = Array.from((0, get_refs_1.getRefs)(json))) => {
|
|
120
103
|
var _a, _b;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var argument = ((_b = json['refs'][ref]) === null || _b === void 0 ? void 0 : _b.argument) || '';
|
|
127
|
-
str += "\nconst ".concat(ref, " = useRef").concat(typeParameter ? "<".concat(typeParameter, ">") : '', "(").concat(argument, ");");
|
|
104
|
+
let str = '';
|
|
105
|
+
for (const ref of refs) {
|
|
106
|
+
const typeParameter = ((_a = json['refs'][ref]) === null || _a === void 0 ? void 0 : _a.typeParameter) || '';
|
|
107
|
+
const argument = ((_b = json['refs'][ref]) === null || _b === void 0 ? void 0 : _b.argument) || '';
|
|
108
|
+
str += `\nconst ${ref} = useRef${typeParameter ? `<${typeParameter}>` : ''}(${argument});`;
|
|
128
109
|
}
|
|
129
110
|
return str;
|
|
130
111
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
112
|
+
const mitosisCoreComponents = ['Show', 'For'];
|
|
113
|
+
const componentToMitosis = (toMitosisOptions = {}) => ({ component }) => {
|
|
114
|
+
var _a;
|
|
115
|
+
const options = {
|
|
116
|
+
format: exports.DEFAULT_FORMAT,
|
|
117
|
+
...toMitosisOptions,
|
|
118
|
+
};
|
|
119
|
+
if (options.format === 'react') {
|
|
120
|
+
return (0, react_1.componentToReact)({
|
|
121
|
+
format: 'lite',
|
|
122
|
+
stateType: 'useState',
|
|
123
|
+
stylesType: 'emotion',
|
|
124
|
+
prettier: options.prettier,
|
|
125
|
+
})({ component });
|
|
126
|
+
}
|
|
127
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
128
|
+
if (options.plugins) {
|
|
129
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
130
|
+
}
|
|
131
|
+
const domRefs = (0, get_refs_1.getRefs)(component);
|
|
132
|
+
// grab refs not used for bindings
|
|
133
|
+
const jsRefs = Object.keys(component.refs).filter((ref) => domRefs.has(ref));
|
|
134
|
+
const refs = [...jsRefs, ...Array.from(domRefs)];
|
|
135
|
+
(0, map_refs_1.mapRefs)(json, (refName) => {
|
|
136
|
+
return `${refName}${domRefs.has(refName) ? `.current` : ''}`;
|
|
137
|
+
});
|
|
138
|
+
const addWrapper = json.children.length !== 1 || (0, is_root_text_node_1.isRootTextNode)(json);
|
|
139
|
+
const components = Array.from((0, get_components_1.getComponents)(json));
|
|
140
|
+
const mitosisComponents = components.filter((item) => mitosisCoreComponents.includes(item));
|
|
141
|
+
const otherComponents = components.filter((item) => !mitosisCoreComponents.includes(item));
|
|
142
|
+
if (options.plugins) {
|
|
143
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
144
|
+
}
|
|
145
|
+
const hasState = (0, state_1.checkHasState)(component);
|
|
146
|
+
const needsMitosisCoreImport = Boolean(hasState || refs.length || mitosisComponents.length);
|
|
147
|
+
const stringifiedUseMetadata = json5_1.default.stringify(component.meta.useMetadata);
|
|
148
|
+
// TODO: smart only pull in imports as needed
|
|
149
|
+
let str = (0, dedent_1.dedent) `
|
|
150
|
+
${!needsMitosisCoreImport
|
|
151
|
+
? ''
|
|
152
|
+
: `import { ${!hasState ? '' : 'useStore, '} ${!refs.length ? '' : 'useRef, '} ${mitosisComponents.join(', ')} } from '..';`}
|
|
153
|
+
${!otherComponents.length ? '' : `import { ${otherComponents.join(',')} } from '@components';`}
|
|
154
|
+
${json.types ? json.types.join('\n') : ''}
|
|
155
|
+
|
|
156
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
157
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
158
|
+
component: json,
|
|
159
|
+
target: 'mitosis',
|
|
160
|
+
})}
|
|
161
|
+
|
|
162
|
+
${stringifiedUseMetadata && stringifiedUseMetadata !== '{}'
|
|
163
|
+
? `${hooks_1.HOOKS.METADATA}(${stringifiedUseMetadata})`
|
|
164
|
+
: ''}
|
|
165
|
+
|
|
166
|
+
export default function ${component.name}(props) {
|
|
167
|
+
${!hasState ? '' : `const state = useStore(${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json)});`}
|
|
168
|
+
${getRefsString(json, refs)}
|
|
169
|
+
|
|
170
|
+
${json.hooks.onMount.map((hook) => `onMount(() => { ${hook.code} })`)}
|
|
171
|
+
|
|
172
|
+
${!((_a = json.hooks.onUnMount) === null || _a === void 0 ? void 0 : _a.code) ? '' : `onUnMount(() => { ${json.hooks.onUnMount.code} })`}
|
|
173
|
+
|
|
174
|
+
return (${addWrapper ? '<>' : ''}
|
|
175
|
+
${json.children.map((item) => (0, exports.blockToMitosis)(item, options, component)).join('\n')}
|
|
176
|
+
${addWrapper ? '</>' : ''})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
`;
|
|
180
|
+
if (options.plugins) {
|
|
181
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
182
|
+
}
|
|
183
|
+
if (options.prettier !== false) {
|
|
184
|
+
try {
|
|
185
|
+
str = (0, standalone_1.format)(str, {
|
|
186
|
+
parser: 'typescript',
|
|
187
|
+
plugins: [
|
|
188
|
+
require('prettier/parser-typescript'), // To support running in browsers
|
|
189
|
+
],
|
|
190
|
+
});
|
|
193
191
|
}
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
catch (err) {
|
|
193
|
+
console.error('Format error for file:', str, JSON.stringify(json, null, 2));
|
|
194
|
+
throw err;
|
|
196
195
|
}
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
}
|
|
197
|
+
if (options.plugins) {
|
|
198
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
199
|
+
}
|
|
200
|
+
return str;
|
|
199
201
|
};
|
|
200
202
|
exports.componentToMitosis = componentToMitosis;
|
|
201
|
-
var templateObject_1;
|