@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,186 +1,166 @@
|
|
|
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.componentToReact = exports.componentToPreact = exports.contextPropDrillingKey = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
7
|
+
const bindings_1 = require("../../helpers/bindings");
|
|
8
|
+
const create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
|
|
9
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
10
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
11
|
+
const get_props_ref_1 = require("../../helpers/get-props-ref");
|
|
12
|
+
const get_refs_1 = require("../../helpers/get-refs");
|
|
13
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
14
|
+
const getters_to_functions_1 = require("../../helpers/getters-to-functions");
|
|
15
|
+
const handle_missing_state_1 = require("../../helpers/handle-missing-state");
|
|
16
|
+
const is_root_text_node_1 = require("../../helpers/is-root-text-node");
|
|
17
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
18
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
19
|
+
const nullable_1 = require("../../helpers/nullable");
|
|
20
|
+
const on_event_1 = require("../../helpers/on-event");
|
|
21
|
+
const process_code_1 = require("../../helpers/plugins/process-code");
|
|
22
|
+
const process_http_requests_1 = require("../../helpers/process-http-requests");
|
|
23
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
24
|
+
const replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
25
|
+
const replace_new_lines_in_strings_1 = require("../../helpers/replace-new-lines-in-strings");
|
|
26
|
+
const state_1 = require("../../helpers/state");
|
|
27
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
28
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
29
|
+
const collect_styled_components_1 = require("../../helpers/styles/collect-styled-components");
|
|
30
|
+
const helpers_1 = require("../../helpers/styles/helpers");
|
|
31
|
+
const core_1 = require("@babel/core");
|
|
32
|
+
const hash_sum_1 = __importDefault(require("hash-sum"));
|
|
33
|
+
const json5_1 = __importDefault(require("json5"));
|
|
34
|
+
const standalone_1 = require("prettier/standalone");
|
|
35
|
+
const plugins_1 = require("../../modules/plugins");
|
|
36
|
+
const context_1 = require("../helpers/context");
|
|
37
|
+
const rsc_1 = require("../helpers/rsc");
|
|
38
|
+
const react_native_1 = require("../react-native");
|
|
39
|
+
const blocks_1 = require("./blocks");
|
|
40
|
+
const helpers_2 = require("./helpers");
|
|
41
|
+
const state_2 = require("./state");
|
|
66
42
|
exports.contextPropDrillingKey = '_context';
|
|
67
43
|
/**
|
|
68
44
|
* If the root Mitosis component only has 1 child, and it is a `Show`/`For` node, then we need to wrap it in a fragment.
|
|
69
45
|
* Otherwise, we end up with invalid React render code.
|
|
70
46
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
var getRefsString = function (json, refs, options) {
|
|
47
|
+
const isRootSpecialNode = (json) => json.children.length === 1 && ['Show', 'For'].includes(json.children[0].name);
|
|
48
|
+
const getRefsString = (json, refs, options) => {
|
|
75
49
|
var _a, _b;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (
|
|
80
|
-
|
|
81
|
-
var typeParameter = ((_a = json['refs'][ref]) === null || _a === void 0 ? void 0 : _a.typeParameter) || '';
|
|
50
|
+
let hasStateArgument = false;
|
|
51
|
+
let code = '';
|
|
52
|
+
const domRefs = (0, get_refs_1.getRefs)(json);
|
|
53
|
+
for (const ref of refs) {
|
|
54
|
+
const typeParameter = ((_a = json['refs'][ref]) === null || _a === void 0 ? void 0 : _a.typeParameter) || '';
|
|
82
55
|
// domRefs must have null argument
|
|
83
|
-
|
|
56
|
+
const argument = ((_b = json['refs'][ref]) === null || _b === void 0 ? void 0 : _b.argument) || (domRefs.has(ref) ? 'null' : '');
|
|
84
57
|
hasStateArgument = /state\./.test(argument);
|
|
85
|
-
code +=
|
|
58
|
+
code += `\nconst ${ref} = useRef${typeParameter && options.typescript ? `<${typeParameter}>` : ''}(${(0, state_2.processHookCode)({
|
|
86
59
|
str: argument,
|
|
87
|
-
options
|
|
88
|
-
})
|
|
60
|
+
options,
|
|
61
|
+
})});`;
|
|
89
62
|
}
|
|
90
63
|
return [hasStateArgument, code];
|
|
91
64
|
};
|
|
92
65
|
function provideContext(json, options) {
|
|
93
66
|
if (options.contextType === 'prop-drill') {
|
|
94
|
-
|
|
95
|
-
for (
|
|
96
|
-
|
|
67
|
+
let str = '';
|
|
68
|
+
for (const key in json.context.set) {
|
|
69
|
+
const { name, ref, value } = json.context.set[key];
|
|
97
70
|
if (value) {
|
|
98
|
-
str +=
|
|
71
|
+
str += `
|
|
72
|
+
${exports.contextPropDrillingKey}.${name} = ${(0, get_state_object_string_1.stringifyContextValue)(value)};
|
|
73
|
+
`;
|
|
99
74
|
}
|
|
100
75
|
// TODO: support refs. I'm not sure what those are so unclear how to support them
|
|
101
76
|
}
|
|
102
77
|
return str;
|
|
103
78
|
}
|
|
104
79
|
else {
|
|
105
|
-
for (
|
|
106
|
-
|
|
80
|
+
for (const key in json.context.set) {
|
|
81
|
+
const { name, ref, value } = json.context.set[key];
|
|
107
82
|
if (value) {
|
|
108
83
|
json.children = [
|
|
109
|
-
(0, create_mitosis_node_1.createMitosisNode)(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
84
|
+
(0, create_mitosis_node_1.createMitosisNode)({
|
|
85
|
+
name: `${name}.Provider`,
|
|
86
|
+
children: json.children,
|
|
87
|
+
...(value && {
|
|
88
|
+
bindings: {
|
|
89
|
+
value: (0, bindings_1.createSingleBinding)({
|
|
90
|
+
code: (0, get_state_object_string_1.stringifyContextValue)(value),
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
116
95
|
];
|
|
117
96
|
}
|
|
118
97
|
else if (ref) {
|
|
119
98
|
json.children = [
|
|
120
|
-
(0, create_mitosis_node_1.createMitosisNode)(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
99
|
+
(0, create_mitosis_node_1.createMitosisNode)({
|
|
100
|
+
name: `${name}.Provider`,
|
|
101
|
+
children: json.children,
|
|
102
|
+
...(ref && {
|
|
103
|
+
bindings: {
|
|
104
|
+
value: (0, bindings_1.createSingleBinding)({ code: ref }),
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
}),
|
|
125
108
|
];
|
|
126
109
|
}
|
|
127
110
|
}
|
|
128
111
|
}
|
|
129
112
|
}
|
|
130
113
|
function getContextString(component, options) {
|
|
131
|
-
|
|
132
|
-
for (
|
|
114
|
+
let str = '';
|
|
115
|
+
for (const key in component.context.get) {
|
|
133
116
|
if (options.contextType === 'prop-drill') {
|
|
134
|
-
str +=
|
|
117
|
+
str += `
|
|
118
|
+
const ${key} = ${exports.contextPropDrillingKey}['${component.context.get[key].name}'];
|
|
119
|
+
`;
|
|
135
120
|
}
|
|
136
121
|
else {
|
|
137
|
-
str +=
|
|
122
|
+
str += `
|
|
123
|
+
const ${key} = useContext(${component.context.get[key].name});
|
|
124
|
+
`;
|
|
138
125
|
}
|
|
139
126
|
}
|
|
140
127
|
return str;
|
|
141
128
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
129
|
+
const componentToPreact = (reactOptions = {}) => (0, exports.componentToReact)({
|
|
130
|
+
...reactOptions,
|
|
131
|
+
preact: true,
|
|
132
|
+
});
|
|
146
133
|
exports.componentToPreact = componentToPreact;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
plugins: __spreadArray([
|
|
168
|
-
(0, on_event_1.processOnEventHooksPlugin)({ setBindings: false })
|
|
169
|
-
], (stateType === 'variables'
|
|
134
|
+
const componentToReact = (reactOptions = {}) => ({ component, path }) => {
|
|
135
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
136
|
+
const target = reactOptions.preact
|
|
137
|
+
? 'preact'
|
|
138
|
+
: reactOptions.type === 'native'
|
|
139
|
+
? 'reactNative'
|
|
140
|
+
: reactOptions.type === 'taro'
|
|
141
|
+
? 'taro'
|
|
142
|
+
: reactOptions.rsc
|
|
143
|
+
? 'rsc'
|
|
144
|
+
: 'react';
|
|
145
|
+
const stateType = reactOptions.stateType || 'useState';
|
|
146
|
+
const DEFAULT_OPTIONS = {
|
|
147
|
+
addUseClientDirectiveIfNeeded: true,
|
|
148
|
+
stateType,
|
|
149
|
+
stylesType: 'styled-jsx',
|
|
150
|
+
type: 'dom',
|
|
151
|
+
plugins: [
|
|
152
|
+
(0, on_event_1.processOnEventHooksPlugin)({ setBindings: false }),
|
|
153
|
+
...(stateType === 'variables'
|
|
170
154
|
? [
|
|
171
|
-
(0, process_code_1.CODE_PROCESSOR_PLUGIN)(
|
|
155
|
+
(0, process_code_1.CODE_PROCESSOR_PLUGIN)((codeType, json) => (code, hookType) => {
|
|
172
156
|
if (codeType === 'types')
|
|
173
157
|
return code;
|
|
174
158
|
code = (0, replace_identifiers_1.replaceNodes)({
|
|
175
|
-
code
|
|
159
|
+
code,
|
|
176
160
|
nodeMaps: Object.entries(json.state)
|
|
177
|
-
.filter(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
})
|
|
181
|
-
.map(function (_a) {
|
|
182
|
-
var key = _a[0], value = _a[1];
|
|
183
|
-
var expr = core_1.types.memberExpression(core_1.types.identifier('state'), core_1.types.identifier(key));
|
|
161
|
+
.filter(([key, value]) => (value === null || value === void 0 ? void 0 : value.type) === 'getter')
|
|
162
|
+
.map(([key, value]) => {
|
|
163
|
+
const expr = core_1.types.memberExpression(core_1.types.identifier('state'), core_1.types.identifier(key));
|
|
184
164
|
return {
|
|
185
165
|
from: expr,
|
|
186
166
|
// condition: (path) => !types.isObjectMethod(path.parent),
|
|
@@ -190,80 +170,87 @@ var componentToReact = function (reactOptions) {
|
|
|
190
170
|
});
|
|
191
171
|
code = (0, replace_identifiers_1.replaceStateIdentifier)(null)(code);
|
|
192
172
|
return code;
|
|
193
|
-
}
|
|
173
|
+
}),
|
|
194
174
|
]
|
|
195
|
-
: []),
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
catch (err) {
|
|
226
|
-
console.error('Format error for file:', str);
|
|
227
|
-
throw err;
|
|
228
|
-
}
|
|
175
|
+
: []),
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
179
|
+
target,
|
|
180
|
+
component,
|
|
181
|
+
defaults: DEFAULT_OPTIONS,
|
|
182
|
+
userOptions: reactOptions,
|
|
183
|
+
});
|
|
184
|
+
if (options.plugins) {
|
|
185
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
186
|
+
}
|
|
187
|
+
let str = _componentToReact(json, options);
|
|
188
|
+
str +=
|
|
189
|
+
'\n\n\n' +
|
|
190
|
+
json.subComponents.map((item) => _componentToReact(item, options, true)).join('\n\n\n');
|
|
191
|
+
if (options.plugins) {
|
|
192
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
193
|
+
}
|
|
194
|
+
if (options.prettier !== false) {
|
|
195
|
+
try {
|
|
196
|
+
str = (0, standalone_1.format)(str, {
|
|
197
|
+
parser: 'typescript',
|
|
198
|
+
plugins: [
|
|
199
|
+
require('prettier/parser-typescript'), // To support running in browsers
|
|
200
|
+
require('prettier/parser-postcss'),
|
|
201
|
+
],
|
|
202
|
+
})
|
|
203
|
+
// Remove spaces between imports
|
|
204
|
+
.replace(/;\n\nimport\s/g, ';\nimport ');
|
|
229
205
|
}
|
|
230
|
-
|
|
231
|
-
|
|
206
|
+
catch (err) {
|
|
207
|
+
console.error('Format error for file:', str);
|
|
208
|
+
throw err;
|
|
232
209
|
}
|
|
233
|
-
|
|
234
|
-
|
|
210
|
+
}
|
|
211
|
+
if (options.plugins) {
|
|
212
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
213
|
+
}
|
|
214
|
+
return str;
|
|
235
215
|
};
|
|
236
216
|
exports.componentToReact = componentToReact;
|
|
237
217
|
// TODO: import target components when they are required
|
|
238
|
-
|
|
239
|
-
|
|
218
|
+
const getDefaultImport = (json, options) => {
|
|
219
|
+
const { preact, type } = options;
|
|
240
220
|
if (preact) {
|
|
241
|
-
return
|
|
221
|
+
return `
|
|
222
|
+
/** @jsx h */
|
|
223
|
+
import { h, Fragment } from 'preact';
|
|
224
|
+
`;
|
|
242
225
|
}
|
|
243
226
|
if (type === 'native') {
|
|
244
|
-
return
|
|
227
|
+
return `
|
|
228
|
+
import * as React from 'react';
|
|
229
|
+
import { FlatList, ScrollView, View, StyleSheet, Image, Text, Pressable, TextInput, TouchableOpacity, Button, Linking } from 'react-native';
|
|
230
|
+
`;
|
|
245
231
|
}
|
|
246
232
|
if (type === 'taro') {
|
|
247
|
-
return
|
|
233
|
+
return `
|
|
234
|
+
import * as React from 'react';
|
|
235
|
+
`;
|
|
248
236
|
}
|
|
249
237
|
return "import * as React from 'react';";
|
|
250
238
|
};
|
|
251
|
-
|
|
252
|
-
var json = _a.json;
|
|
239
|
+
const getPropsDefinition = ({ json }) => {
|
|
253
240
|
if (!json.defaultProps)
|
|
254
241
|
return '';
|
|
255
|
-
|
|
256
|
-
.map(
|
|
242
|
+
const defaultPropsString = Object.keys(json.defaultProps)
|
|
243
|
+
.map((prop) => {
|
|
257
244
|
var _a;
|
|
258
|
-
|
|
245
|
+
const value = json.defaultProps.hasOwnProperty(prop)
|
|
259
246
|
? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
260
247
|
: 'undefined';
|
|
261
|
-
return
|
|
248
|
+
return `${prop}: ${value}`;
|
|
262
249
|
})
|
|
263
250
|
.join(',');
|
|
264
|
-
return
|
|
251
|
+
return `${json.name}.defaultProps = {${defaultPropsString}};`;
|
|
265
252
|
};
|
|
266
|
-
|
|
253
|
+
const checkShouldAddUseClientDirective = (json, options) => {
|
|
267
254
|
var _a, _b;
|
|
268
255
|
if (!options.addUseClientDirectiveIfNeeded)
|
|
269
256
|
return false;
|
|
@@ -272,20 +259,19 @@ var checkShouldAddUseClientDirective = function (json, options) {
|
|
|
272
259
|
if (options.preact)
|
|
273
260
|
return false;
|
|
274
261
|
// When using RSC generator, we check `componentType` field in metadata to determine if it's a server component
|
|
275
|
-
|
|
262
|
+
const componentType = (_b = (_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.rsc) === null || _b === void 0 ? void 0 : _b.componentType;
|
|
276
263
|
if (options.rsc && (0, nullable_1.checkIsDefined)(componentType)) {
|
|
277
264
|
return componentType === 'client';
|
|
278
265
|
}
|
|
279
266
|
return (0, rsc_1.checkIfIsClientComponent)(json);
|
|
280
267
|
};
|
|
281
|
-
|
|
268
|
+
const _componentToReact = (json, options, isSubComponent = false) => {
|
|
282
269
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
283
|
-
if (isSubComponent === void 0) { isSubComponent = false; }
|
|
284
270
|
(0, process_http_requests_1.processHttpRequests)(json);
|
|
285
271
|
(0, handle_missing_state_1.handleMissingState)(json);
|
|
286
272
|
(0, helpers_2.processTagReferences)(json, options);
|
|
287
|
-
|
|
288
|
-
|
|
273
|
+
const contextStr = provideContext(json, options);
|
|
274
|
+
const componentHasStyles = (0, helpers_1.hasCss)(json);
|
|
289
275
|
if (options.stateType === 'useState') {
|
|
290
276
|
(0, getters_to_functions_1.gettersToFunctions)(json);
|
|
291
277
|
(0, state_2.updateStateSetters)(json, options);
|
|
@@ -294,38 +280,38 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
294
280
|
json.name = 'MyComponent';
|
|
295
281
|
}
|
|
296
282
|
// const domRefs = getRefs(json);
|
|
297
|
-
|
|
298
|
-
(0, map_refs_1.mapRefs)(json,
|
|
283
|
+
const allRefs = Object.keys(json.refs);
|
|
284
|
+
(0, map_refs_1.mapRefs)(json, (refName) => `${refName}.current`);
|
|
299
285
|
// Always use state if we are generate Builder react code
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
286
|
+
const hasState = options.stateType === 'builder' || (0, state_1.checkHasState)(json);
|
|
287
|
+
const [forwardRef, hasPropRef] = (0, get_props_ref_1.getPropsRef)(json);
|
|
288
|
+
const isForwardRef = !options.preact && Boolean(((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.forwardRef) || hasPropRef);
|
|
303
289
|
if (isForwardRef) {
|
|
304
|
-
|
|
290
|
+
const meta = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.forwardRef;
|
|
305
291
|
options.forwardRef = meta || forwardRef;
|
|
306
292
|
}
|
|
307
|
-
|
|
308
|
-
?
|
|
293
|
+
const forwardRefType = options.typescript && json.propsTypeRef && forwardRef && json.propsTypeRef !== 'any'
|
|
294
|
+
? `<${json.propsTypeRef}["${forwardRef}"]>`
|
|
309
295
|
: '';
|
|
310
|
-
|
|
296
|
+
const useStateCode = options.stateType === 'useState' ? (0, state_2.getUseStateCode)(json, options) : '';
|
|
311
297
|
if (options.plugins) {
|
|
312
|
-
json = (0, plugins_1.runPostJsonPlugins)({ json
|
|
298
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
313
299
|
}
|
|
314
|
-
|
|
300
|
+
const css = options.stylesType === 'styled-jsx'
|
|
315
301
|
? (0, collect_css_1.collectCss)(json)
|
|
316
302
|
: options.stylesType === 'style-tag'
|
|
317
303
|
? (0, collect_css_1.collectCss)(json, {
|
|
318
304
|
prefix: (0, hash_sum_1.default)(json),
|
|
319
305
|
})
|
|
320
306
|
: null;
|
|
321
|
-
|
|
307
|
+
const styledComponentsCode = (options.stylesType === 'styled-components' &&
|
|
322
308
|
componentHasStyles &&
|
|
323
309
|
(0, collect_styled_components_1.collectStyledComponents)(json)) ||
|
|
324
310
|
'';
|
|
325
311
|
if (options.format !== 'lite') {
|
|
326
312
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
327
313
|
}
|
|
328
|
-
|
|
314
|
+
const reactLibImports = new Set();
|
|
329
315
|
if (useStateCode.includes('useState')) {
|
|
330
316
|
reactLibImports.add('useState');
|
|
331
317
|
}
|
|
@@ -341,101 +327,170 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
341
327
|
if (json.hooks.onMount.length || ((_d = json.hooks.onUnMount) === null || _d === void 0 ? void 0 : _d.code) || ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)) {
|
|
342
328
|
reactLibImports.add('useEffect');
|
|
343
329
|
}
|
|
344
|
-
|
|
345
|
-
|
|
330
|
+
const hasCustomStyles = !!((_f = json.style) === null || _f === void 0 ? void 0 : _f.length);
|
|
331
|
+
const shouldInjectCustomStyles = hasCustomStyles &&
|
|
346
332
|
(options.stylesType === 'styled-components' || options.stylesType === 'emotion');
|
|
347
|
-
|
|
333
|
+
const wrap = (0, helpers_2.wrapInFragment)(json) ||
|
|
348
334
|
(0, is_root_text_node_1.isRootTextNode)(json) ||
|
|
349
335
|
(componentHasStyles &&
|
|
350
336
|
(options.stylesType === 'styled-jsx' || options.stylesType === 'style-tag')) ||
|
|
351
337
|
shouldInjectCustomStyles ||
|
|
352
338
|
isRootSpecialNode(json);
|
|
353
|
-
|
|
339
|
+
const [hasStateArgument, refsString] = getRefsString(json, allRefs, options);
|
|
354
340
|
// NOTE: `collectReactNativeStyles` must run before style generation in the component generation body, as it has
|
|
355
341
|
// side effects that delete styles bindings from the JSON.
|
|
356
|
-
|
|
342
|
+
const reactNativeStyles = options.stylesType === 'react-native' && componentHasStyles
|
|
357
343
|
? (0, react_native_1.collectReactNativeStyles)(json)
|
|
358
344
|
: undefined;
|
|
359
|
-
|
|
360
|
-
|
|
345
|
+
const propType = json.propsTypeRef || 'any';
|
|
346
|
+
const componentArgs = [`props${options.typescript ? `:${propType}` : ''}`, options.forwardRef]
|
|
361
347
|
.filter(Boolean)
|
|
362
348
|
.join(',');
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
349
|
+
const componentBody = (0, dedent_1.dedent) `
|
|
350
|
+
${options.contextType === 'prop-drill'
|
|
351
|
+
? `const ${exports.contextPropDrillingKey} = { ...props['${exports.contextPropDrillingKey}'] };`
|
|
352
|
+
: ''}
|
|
353
|
+
${hasStateArgument ? '' : refsString}
|
|
354
|
+
${hasState
|
|
366
355
|
? options.stateType === 'mobx'
|
|
367
|
-
?
|
|
356
|
+
? `const state = useLocalObservable(() => (${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json)}));`
|
|
368
357
|
: options.stateType === 'useState'
|
|
369
358
|
? useStateCode
|
|
370
359
|
: options.stateType === 'solid'
|
|
371
|
-
?
|
|
360
|
+
? `const state = useMutable(${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json)});`
|
|
372
361
|
: options.stateType === 'builder'
|
|
373
|
-
?
|
|
362
|
+
? `const state = useBuilderState(${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json)});`
|
|
374
363
|
: options.stateType === 'variables'
|
|
375
364
|
? (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
376
365
|
format: 'variables',
|
|
377
366
|
keyPrefix: 'const',
|
|
378
|
-
valueMapper:
|
|
367
|
+
valueMapper: (code, type, _, key) => {
|
|
379
368
|
if (type === 'getter')
|
|
380
|
-
return
|
|
369
|
+
return `${key} = function ${code.replace('get ', '')}`;
|
|
381
370
|
if (type === 'function')
|
|
382
|
-
return
|
|
371
|
+
return `${key} = function ${code}`;
|
|
383
372
|
return code;
|
|
384
373
|
},
|
|
385
374
|
})
|
|
386
|
-
:
|
|
387
|
-
: ''
|
|
388
|
-
|
|
375
|
+
: `const state = useLocalProxy(${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json)});`
|
|
376
|
+
: ''}
|
|
377
|
+
${hasStateArgument ? refsString : ''}
|
|
378
|
+
${getContextString(json, options)}
|
|
379
|
+
${((_g = json.hooks.init) === null || _g === void 0 ? void 0 : _g.code) ? (0, state_2.processHookCode)({ str: (_h = json.hooks.init) === null || _h === void 0 ? void 0 : _h.code, options }) : ''}
|
|
380
|
+
${contextStr || ''}
|
|
381
|
+
|
|
382
|
+
${((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code)
|
|
383
|
+
? `
|
|
384
|
+
const hasInitialized = useRef(false);
|
|
385
|
+
if (!hasInitialized.current) {
|
|
386
|
+
${(0, state_2.processHookCode)({
|
|
389
387
|
str: json.hooks.onInit.code,
|
|
390
|
-
options
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
388
|
+
options,
|
|
389
|
+
})}
|
|
390
|
+
hasInitialized.current = true;
|
|
391
|
+
}
|
|
392
|
+
`
|
|
393
|
+
: ''}
|
|
394
|
+
|
|
395
|
+
${json.hooks.onEvent
|
|
396
|
+
.map((hook) => {
|
|
397
|
+
const eventName = `"${hook.eventName}"`;
|
|
398
|
+
const handlerName = (0, on_event_1.getOnEventHandlerName)(hook);
|
|
399
|
+
return `
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
${hook.refName}.current?.addEventListener(${eventName}, ${handlerName});
|
|
402
|
+
return () => ${hook.refName}.current?.removeEventListener(${eventName}, ${handlerName});
|
|
403
|
+
}, []);
|
|
404
|
+
`;
|
|
404
405
|
})
|
|
405
|
-
.join('\n')
|
|
406
|
-
|
|
406
|
+
.join('\n')}
|
|
407
|
+
|
|
408
|
+
${json.hooks.onMount
|
|
409
|
+
.map((hook) => `useEffect(() => {
|
|
410
|
+
${(0, state_2.processHookCode)({
|
|
411
|
+
str: hook.code,
|
|
412
|
+
options,
|
|
413
|
+
})}
|
|
414
|
+
}, [])`)
|
|
415
|
+
.join('\n')}
|
|
416
|
+
|
|
417
|
+
${(_l = (_k = json.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.map((hook) => `useEffect(() => {
|
|
418
|
+
${(0, state_2.processHookCode)({ str: hook.code, options })}
|
|
419
|
+
},
|
|
420
|
+
${hook.deps ? (0, state_2.processHookCode)({ str: hook.deps, options }) : ''})`).join(';')) !== null && _l !== void 0 ? _l : ''}
|
|
421
|
+
|
|
422
|
+
${((_m = json.hooks.onUnMount) === null || _m === void 0 ? void 0 : _m.code)
|
|
423
|
+
? `useEffect(() => {
|
|
424
|
+
return () => {
|
|
425
|
+
${(0, state_2.processHookCode)({
|
|
407
426
|
str: json.hooks.onUnMount.code,
|
|
408
|
-
options
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
: ''
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
427
|
+
options,
|
|
428
|
+
})}
|
|
429
|
+
}
|
|
430
|
+
}, [])`
|
|
431
|
+
: ''}
|
|
432
|
+
|
|
433
|
+
return (
|
|
434
|
+
${wrap ? (0, helpers_2.openFrag)(options) : ''}
|
|
435
|
+
${json.children.map((item) => (0, blocks_1.blockToReact)(item, options, json, wrap, [])).join('\n')}
|
|
436
|
+
${componentHasStyles && options.stylesType === 'styled-jsx'
|
|
437
|
+
? `<style jsx>{\`${css}\`}</style>`
|
|
438
|
+
: ''}
|
|
439
|
+
${componentHasStyles && options.stylesType === 'style-tag'
|
|
440
|
+
? `<style>{\`${css}\`}</style>`
|
|
441
|
+
: ''}
|
|
442
|
+
${shouldInjectCustomStyles ? `<style>{\`${json.style}\`}</style>` : ''}
|
|
443
|
+
${wrap ? (0, helpers_2.closeFrag)(options) : ''}
|
|
444
|
+
);
|
|
445
|
+
`;
|
|
446
|
+
const shouldAddUseClientDirective = checkShouldAddUseClientDirective(json, options);
|
|
447
|
+
const str = (0, dedent_1.dedent) `
|
|
448
|
+
${shouldAddUseClientDirective ? `'use client';` : ''}
|
|
449
|
+
${getDefaultImport(json, options)}
|
|
450
|
+
${styledComponentsCode ? `import styled from 'styled-components';\n` : ''}
|
|
451
|
+
${reactLibImports.size
|
|
452
|
+
? `import { ${Array.from(reactLibImports).join(', ')} } from '${options.preact ? 'preact/hooks' : 'react'}'`
|
|
453
|
+
: ''}
|
|
454
|
+
${options.stylesType === 'twrnc' ? `import tw from 'twrnc';\n` : ''}
|
|
455
|
+
${componentHasStyles && options.stylesType === 'emotion' && options.format !== 'lite'
|
|
456
|
+
? `/** @jsx jsx */
|
|
457
|
+
import { jsx } from '@emotion/react'`.trim()
|
|
458
|
+
: ''}
|
|
459
|
+
${!hasState
|
|
421
460
|
? ''
|
|
422
461
|
: options.stateType === 'valtio'
|
|
423
|
-
?
|
|
462
|
+
? `import { useLocalProxy } from 'valtio/utils';`
|
|
424
463
|
: options.stateType === 'solid'
|
|
425
|
-
?
|
|
464
|
+
? `import { useMutable } from 'react-solid-state';`
|
|
426
465
|
: options.stateType === 'mobx'
|
|
427
|
-
?
|
|
428
|
-
: ''
|
|
466
|
+
? `import { useLocalObservable, observer } from 'mobx-react-lite';`
|
|
467
|
+
: ''}
|
|
468
|
+
${json.types && options.typescript ? json.types.join('\n') : ''}
|
|
469
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
429
470
|
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
430
471
|
component: json,
|
|
431
472
|
target: options.type === 'native' ? 'reactNative' : 'react',
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
|
|
473
|
+
})}
|
|
474
|
+
${isForwardRef ? `const ${json.name} = forwardRef${forwardRefType}(` : ''}function ${json.name}(${componentArgs}) {
|
|
475
|
+
${componentBody}
|
|
476
|
+
}${isForwardRef ? ')' : ''}
|
|
477
|
+
|
|
478
|
+
${getPropsDefinition({ json })}
|
|
479
|
+
|
|
480
|
+
${reactNativeStyles
|
|
481
|
+
? `const styles = StyleSheet.create(${json5_1.default.stringify(reactNativeStyles)});`
|
|
482
|
+
: ''}
|
|
483
|
+
|
|
484
|
+
${styledComponentsCode !== null && styledComponentsCode !== void 0 ? styledComponentsCode : ''}
|
|
485
|
+
${isSubComponent
|
|
435
486
|
? ''
|
|
436
487
|
: options.stateType === 'mobx'
|
|
437
|
-
?
|
|
438
|
-
|
|
488
|
+
? `
|
|
489
|
+
const observed${json.name} = observer(${json.name});
|
|
490
|
+
export default observed${json.name};
|
|
491
|
+
`
|
|
492
|
+
: `export default ${json.name};`}
|
|
493
|
+
|
|
494
|
+
`;
|
|
439
495
|
return (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(str);
|
|
440
496
|
};
|
|
441
|
-
var templateObject_1, templateObject_2;
|