@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,38 +1,27 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.blockToReact = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Slot
|
|
7
|
+
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
8
|
+
const is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
9
|
+
const is_root_text_node_1 = require("../../helpers/is-root-text-node");
|
|
10
|
+
const is_valid_attribute_name_1 = require("../../helpers/is-valid-attribute-name");
|
|
11
|
+
const for_1 = require("../../helpers/nodes/for");
|
|
12
|
+
const slots_1 = require("../../helpers/slots");
|
|
13
|
+
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
14
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
15
|
+
const helpers_1 = require("./helpers");
|
|
16
|
+
const state_1 = require("./state");
|
|
17
|
+
const NODE_MAPPERS = {
|
|
18
|
+
Slot(json, options, component, _insideJsx, parentSlots) {
|
|
30
19
|
var _a, _b;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
const slotName = ((_a = json.bindings.name) === null || _a === void 0 ? void 0 : _a.code) || json.properties.name;
|
|
21
|
+
const hasChildren = json.children.length;
|
|
22
|
+
const renderChildren = () => {
|
|
34
23
|
var _a;
|
|
35
|
-
|
|
24
|
+
const childrenStr = (_a = json.children) === null || _a === void 0 ? void 0 : _a.map((item) => (0, exports.blockToReact)(item, options, component, true)).join('\n').trim();
|
|
36
25
|
/**
|
|
37
26
|
* Ad-hoc way of figuring out if the children defaultProp is:
|
|
38
27
|
* - a JSX element, e.g. `<div>foo</div>`
|
|
@@ -41,151 +30,158 @@ var NODE_MAPPERS = {
|
|
|
41
30
|
*
|
|
42
31
|
* and correctly wrapping it in quotes when appropriate.
|
|
43
32
|
*/
|
|
44
|
-
if (childrenStr.startsWith(
|
|
33
|
+
if (childrenStr.startsWith(`<`) && childrenStr.endsWith(`>`)) {
|
|
45
34
|
return childrenStr;
|
|
46
35
|
}
|
|
47
36
|
else if (['false', 'true', 'null', 'undefined'].includes(childrenStr)) {
|
|
48
37
|
return childrenStr;
|
|
49
38
|
}
|
|
50
39
|
else {
|
|
51
|
-
return "
|
|
40
|
+
return `"${childrenStr}"`;
|
|
52
41
|
}
|
|
53
42
|
};
|
|
54
43
|
if (!slotName) {
|
|
55
44
|
// TODO: update MitosisNode for simple code
|
|
56
|
-
|
|
45
|
+
const key = Object.keys(json.bindings).find(Boolean);
|
|
57
46
|
if (key && parentSlots) {
|
|
58
|
-
parentSlots.push({ key
|
|
47
|
+
parentSlots.push({ key, value: (_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code });
|
|
59
48
|
return '';
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
return
|
|
50
|
+
const children = (0, helpers_1.processBinding)('props.children', options);
|
|
51
|
+
return `<>{${children} ${hasChildren ? `|| (${renderChildren()})` : ''}}</>`;
|
|
63
52
|
}
|
|
64
|
-
|
|
53
|
+
let slotProp = (0, helpers_1.processBinding)(slotName, options).replace('name=', '');
|
|
65
54
|
if (!slotProp.startsWith('props.')) {
|
|
66
|
-
slotProp =
|
|
55
|
+
slotProp = `props.${slotProp}`;
|
|
67
56
|
}
|
|
68
|
-
return
|
|
57
|
+
return `<>{${slotProp} ${hasChildren ? `|| (${renderChildren()})` : ''}}</>`;
|
|
69
58
|
},
|
|
70
|
-
Fragment
|
|
71
|
-
|
|
72
|
-
return
|
|
73
|
-
.map(
|
|
74
|
-
.join('\n')
|
|
59
|
+
Fragment(json, options, component) {
|
|
60
|
+
const wrap = (0, helpers_1.wrapInFragment)(json) || (0, is_root_text_node_1.isRootTextNode)(json);
|
|
61
|
+
return `${wrap ? (0, helpers_1.getFragment)('open', options) : ''}${json.children
|
|
62
|
+
.map((item) => (0, exports.blockToReact)(item, options, component, wrap))
|
|
63
|
+
.join('\n')}${wrap ? (0, helpers_1.getFragment)('close', options) : ''}`;
|
|
75
64
|
},
|
|
76
|
-
For
|
|
65
|
+
For(_json, options, component, insideJsx) {
|
|
77
66
|
var _a;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
const json = _json;
|
|
68
|
+
const wrap = (0, helpers_1.wrapInFragment)(json);
|
|
69
|
+
const forArguments = (0, for_1.getForArguments)(json).join(', ');
|
|
70
|
+
const expression = `${(0, helpers_1.processBinding)((_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code, options)}?.map((${forArguments}) => (
|
|
71
|
+
${wrap ? (0, helpers_1.openFrag)(options) : ''}${json.children
|
|
82
72
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
83
|
-
.map(
|
|
84
|
-
.join('\n')
|
|
73
|
+
.map((item) => (0, exports.blockToReact)(item, options, component, wrap))
|
|
74
|
+
.join('\n')}${wrap ? (0, helpers_1.closeFrag)(options) : ''}
|
|
75
|
+
))`;
|
|
85
76
|
if (insideJsx) {
|
|
86
|
-
return
|
|
77
|
+
return `{${expression}}`;
|
|
87
78
|
}
|
|
88
79
|
else {
|
|
89
80
|
return expression;
|
|
90
81
|
}
|
|
91
82
|
},
|
|
92
|
-
Show
|
|
83
|
+
Show(json, options, component, insideJsx) {
|
|
93
84
|
var _a;
|
|
94
|
-
|
|
85
|
+
const wrap = (0, helpers_1.wrapInFragment)(json) ||
|
|
95
86
|
(0, is_root_text_node_1.isRootTextNode)(json) ||
|
|
96
87
|
component.children[0] === json ||
|
|
97
88
|
// when `<Show><For>...</For></Show>`, we need to wrap the For generated code in a fragment
|
|
98
89
|
// since it's a `.map()` call
|
|
99
90
|
(json.children.length === 1 && ['For', 'Show'].includes(json.children[0].name));
|
|
100
|
-
|
|
91
|
+
const wrapElse = !!(json.meta.else &&
|
|
101
92
|
((0, helpers_1.wrapInFragment)(json.meta.else) || (0, mitosis_node_1.checkIsForNode)(json.meta.else)));
|
|
102
|
-
|
|
93
|
+
const expression = `${(0, helpers_1.processBinding)((_a = json.bindings.when) === null || _a === void 0 ? void 0 : _a.code, options)} ? (
|
|
94
|
+
${wrap ? (0, helpers_1.openFrag)(options) : ''}${json.children
|
|
103
95
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
104
|
-
.map(
|
|
105
|
-
.join('\n')
|
|
96
|
+
.map((item) => (0, exports.blockToReact)(item, options, component, wrap))
|
|
97
|
+
.join('\n')}${wrap ? (0, helpers_1.closeFrag)(options) : ''}
|
|
98
|
+
) : ${!json.meta.else
|
|
106
99
|
? 'null'
|
|
107
100
|
: (wrapElse ? (0, helpers_1.openFrag)(options) : '') +
|
|
108
101
|
(0, exports.blockToReact)(json.meta.else, options, component, wrapElse) +
|
|
109
|
-
(wrapElse ? (0, helpers_1.closeFrag)(options) : '')
|
|
102
|
+
(wrapElse ? (0, helpers_1.closeFrag)(options) : '')}`;
|
|
110
103
|
if (insideJsx) {
|
|
111
|
-
return
|
|
104
|
+
return `{${expression}}`;
|
|
112
105
|
}
|
|
113
106
|
else {
|
|
114
107
|
return expression;
|
|
115
108
|
}
|
|
116
109
|
},
|
|
117
110
|
};
|
|
118
|
-
|
|
111
|
+
const ATTTRIBUTE_MAPPERS = {
|
|
119
112
|
spellcheck: 'spellCheck',
|
|
120
113
|
autocapitalize: 'autoCapitalize',
|
|
121
114
|
autocomplete: 'autoComplete',
|
|
122
115
|
for: 'htmlFor',
|
|
123
116
|
};
|
|
124
117
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
125
|
-
|
|
118
|
+
const BINDING_MAPPERS = {
|
|
119
|
+
ref(ref, value, options) {
|
|
126
120
|
if (options === null || options === void 0 ? void 0 : options.preact) {
|
|
127
121
|
return [ref, value];
|
|
128
122
|
}
|
|
129
|
-
|
|
123
|
+
const regexp = /(.+)?props\.(.+)( |\)|;|\()?$/m;
|
|
130
124
|
if (regexp.test(value)) {
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
const match = regexp.exec(value);
|
|
126
|
+
const prop = match === null || match === void 0 ? void 0 : match[2];
|
|
133
127
|
if (prop) {
|
|
134
128
|
return [ref, prop];
|
|
135
129
|
}
|
|
136
130
|
}
|
|
137
131
|
return [ref, value];
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
},
|
|
133
|
+
innerHTML(_key, value) {
|
|
134
|
+
return ['dangerouslySetInnerHTML', `{__html: ${value.replace(/\s+/g, ' ')}}`];
|
|
135
|
+
},
|
|
136
|
+
...ATTTRIBUTE_MAPPERS,
|
|
137
|
+
};
|
|
138
|
+
const NATIVE_EVENT_MAPPER = {
|
|
142
139
|
onClick: 'onPress',
|
|
143
140
|
};
|
|
144
|
-
|
|
141
|
+
const blockToReact = (json, options, component, insideJsx, parentSlots = []) => {
|
|
145
142
|
var _a, _b, _c, _d;
|
|
146
|
-
|
|
147
|
-
var needsToRenderSlots = [];
|
|
143
|
+
const needsToRenderSlots = [];
|
|
148
144
|
if (NODE_MAPPERS[json.name]) {
|
|
149
145
|
return NODE_MAPPERS[json.name](json, options, component, insideJsx, parentSlots);
|
|
150
146
|
}
|
|
151
147
|
if (json.properties._text) {
|
|
152
|
-
|
|
148
|
+
const text = json.properties._text;
|
|
153
149
|
if (options.type === 'native' && text.trim().length) {
|
|
154
|
-
return
|
|
150
|
+
return `<Text>${text}</Text>`;
|
|
155
151
|
}
|
|
156
152
|
return text;
|
|
157
153
|
}
|
|
158
154
|
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
159
|
-
|
|
155
|
+
const processed = (0, helpers_1.processBinding)(json.bindings._text.code, options);
|
|
160
156
|
if (options.type === 'native' &&
|
|
161
157
|
!(0, is_children_1.default)({ node: json }) &&
|
|
162
158
|
!(0, slots_1.isSlotProperty)(json.bindings._text.code.split('.')[1] || '')) {
|
|
163
|
-
return
|
|
159
|
+
return `<Text>{${processed}}</Text>`;
|
|
164
160
|
}
|
|
165
|
-
return
|
|
161
|
+
return `{${processed}}`;
|
|
166
162
|
}
|
|
167
|
-
|
|
168
|
-
str +=
|
|
169
|
-
for (
|
|
170
|
-
|
|
163
|
+
let str = '';
|
|
164
|
+
str += `<${json.name} `;
|
|
165
|
+
for (const key in json.properties) {
|
|
166
|
+
const value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
171
167
|
// Handle src for Image
|
|
172
168
|
// Handle src for Image
|
|
173
169
|
if (json.name === 'Image' && key === 'src') {
|
|
174
|
-
|
|
175
|
-
|
|
170
|
+
let src;
|
|
171
|
+
const imageSource = json.properties.src;
|
|
176
172
|
if (imageSource) {
|
|
177
|
-
|
|
178
|
-
src = isUrl ?
|
|
179
|
-
str +=
|
|
173
|
+
const isUrl = /^(http|https):\/\/[^ "]+$/.test(imageSource);
|
|
174
|
+
src = isUrl ? `{ uri: '${imageSource}' }` : `require('${imageSource}')`;
|
|
175
|
+
str += `source={${src}} `;
|
|
180
176
|
continue; // Skip further processing for 'src' in Image
|
|
181
177
|
}
|
|
182
178
|
}
|
|
183
179
|
// Handle href for TouchableOpacity
|
|
184
180
|
if (json.name === 'TouchableOpacity' && key === 'href') {
|
|
185
|
-
|
|
181
|
+
const hrefValue = (0, helpers_1.processBinding)(value, options);
|
|
186
182
|
if (hrefValue) {
|
|
187
|
-
|
|
188
|
-
str +=
|
|
183
|
+
const onPress = `() => Linking.openURL(${JSON.stringify(hrefValue)})`;
|
|
184
|
+
str += ` onPress={${onPress}} `;
|
|
189
185
|
}
|
|
190
186
|
continue; // Skip further processing for 'href' in TouchableOpacity
|
|
191
187
|
}
|
|
@@ -194,49 +190,49 @@ var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
|
194
190
|
continue; // Skip further processing for 'target' in TouchableOpacity
|
|
195
191
|
}
|
|
196
192
|
if (key === 'class') {
|
|
197
|
-
str =
|
|
193
|
+
str = `${str.trim()} className="${value}" `;
|
|
198
194
|
}
|
|
199
195
|
else if (BINDING_MAPPERS[key]) {
|
|
200
|
-
|
|
196
|
+
const mapper = BINDING_MAPPERS[key];
|
|
201
197
|
if (typeof mapper === 'function') {
|
|
202
|
-
|
|
203
|
-
str +=
|
|
198
|
+
const [newKey, newValue] = mapper(key, value, options);
|
|
199
|
+
str += ` ${newKey}={${newValue}} `;
|
|
204
200
|
}
|
|
205
201
|
else {
|
|
206
|
-
str +=
|
|
202
|
+
str += ` ${BINDING_MAPPERS[key]}="${value}" `;
|
|
207
203
|
}
|
|
208
204
|
}
|
|
209
205
|
else {
|
|
210
206
|
if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
|
|
211
|
-
str +=
|
|
207
|
+
str += ` ${key}="${value.replace(/"/g, '"')}" `;
|
|
212
208
|
}
|
|
213
209
|
}
|
|
214
210
|
}
|
|
215
|
-
for (
|
|
211
|
+
for (const key in json.bindings) {
|
|
216
212
|
// ignore duplicate slot attribute
|
|
217
213
|
if ((_b = json.slots) === null || _b === void 0 ? void 0 : _b[key]) {
|
|
218
214
|
continue;
|
|
219
215
|
}
|
|
220
|
-
|
|
216
|
+
const value = String((_c = json.bindings[key]) === null || _c === void 0 ? void 0 : _c.code);
|
|
221
217
|
if (key === 'css' && value.trim() === '{}') {
|
|
222
218
|
continue;
|
|
223
219
|
}
|
|
224
|
-
|
|
220
|
+
const useBindingValue = (0, helpers_1.processBinding)(value, options);
|
|
225
221
|
if (json.name === 'Image' && key === 'src') {
|
|
226
|
-
|
|
227
|
-
|
|
222
|
+
let src;
|
|
223
|
+
const imageSource = (0, helpers_1.processBinding)(value, options);
|
|
228
224
|
if (imageSource) {
|
|
229
|
-
src =
|
|
230
|
-
str +=
|
|
225
|
+
src = `{ uri: ${imageSource} }`;
|
|
226
|
+
str += `source={${src}} `;
|
|
231
227
|
continue; // Skip further processing for 'src' in Image
|
|
232
228
|
}
|
|
233
229
|
}
|
|
234
230
|
// Handle href for TouchableOpacity
|
|
235
231
|
if (json.name === 'TouchableOpacity' && key === 'href') {
|
|
236
|
-
|
|
232
|
+
const hrefValue = (0, helpers_1.processBinding)(value, options);
|
|
237
233
|
if (hrefValue) {
|
|
238
|
-
|
|
239
|
-
str +=
|
|
234
|
+
const onPress = `() => Linking.openURL(${hrefValue})`;
|
|
235
|
+
str += ` onPress={${onPress}} `;
|
|
240
236
|
continue; // Skip further processing for 'href' in TouchableOpacity
|
|
241
237
|
}
|
|
242
238
|
}
|
|
@@ -245,59 +241,59 @@ var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
|
245
241
|
continue; // Skip further processing for 'target' in TouchableOpacity
|
|
246
242
|
}
|
|
247
243
|
if (((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) === 'spread') {
|
|
248
|
-
str +=
|
|
244
|
+
str += ` {...(${value})} `;
|
|
249
245
|
}
|
|
250
246
|
else if (key.startsWith('on')) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
str +=
|
|
247
|
+
const { arguments: cusArgs = ['event'] } = json.bindings[key];
|
|
248
|
+
const eventName = options.type === 'native' ? NATIVE_EVENT_MAPPER[key] || key : key;
|
|
249
|
+
str += ` ${eventName}={(${cusArgs.join(',')}) => ${(0, state_1.updateStateSettersInCode)(useBindingValue, options)} } `;
|
|
254
250
|
}
|
|
255
251
|
else if (key.startsWith('slot')) {
|
|
256
252
|
// <Component slotProjected={<AnotherComponent />} />
|
|
257
|
-
str +=
|
|
253
|
+
str += ` ${key}={${value}} `;
|
|
258
254
|
}
|
|
259
255
|
else if (key === 'class') {
|
|
260
|
-
str +=
|
|
256
|
+
str += ` className={${useBindingValue}} `;
|
|
261
257
|
}
|
|
262
258
|
else if (BINDING_MAPPERS[key]) {
|
|
263
|
-
|
|
259
|
+
const mapper = BINDING_MAPPERS[key];
|
|
264
260
|
if (typeof mapper === 'function') {
|
|
265
|
-
|
|
266
|
-
str +=
|
|
261
|
+
const [newKey, newValue] = mapper(key, useBindingValue, options);
|
|
262
|
+
str += ` ${newKey}={${newValue}} `;
|
|
267
263
|
}
|
|
268
264
|
else {
|
|
269
265
|
if (useBindingValue === 'true') {
|
|
270
|
-
str +=
|
|
266
|
+
str += ` ${BINDING_MAPPERS[key]} `;
|
|
271
267
|
}
|
|
272
268
|
else {
|
|
273
|
-
str +=
|
|
269
|
+
str += ` ${BINDING_MAPPERS[key]}={${useBindingValue}} `;
|
|
274
270
|
}
|
|
275
271
|
}
|
|
276
272
|
}
|
|
277
273
|
else if (key === 'style' && options.type === 'native' && json.name === 'ScrollView') {
|
|
278
274
|
// React Native's ScrollView has a different prop for styles: `contentContainerStyle`
|
|
279
|
-
str +=
|
|
275
|
+
str += ` contentContainerStyle={${useBindingValue}} `;
|
|
280
276
|
}
|
|
281
277
|
else {
|
|
282
278
|
if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
|
|
283
279
|
if (useBindingValue === 'true') {
|
|
284
|
-
str +=
|
|
280
|
+
str += ` ${key} `;
|
|
285
281
|
}
|
|
286
282
|
else {
|
|
287
|
-
str +=
|
|
283
|
+
str += ` ${key}={${useBindingValue}} `;
|
|
288
284
|
}
|
|
289
285
|
}
|
|
290
286
|
}
|
|
291
287
|
}
|
|
292
288
|
if (json.slots) {
|
|
293
|
-
for (
|
|
294
|
-
|
|
289
|
+
for (const key in json.slots) {
|
|
290
|
+
const value = json.slots[key];
|
|
295
291
|
if (!(value === null || value === void 0 ? void 0 : value.length)) {
|
|
296
292
|
continue;
|
|
297
293
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
str +=
|
|
294
|
+
const reactComponents = value.map((node) => (0, exports.blockToReact)(node, options, component, true));
|
|
295
|
+
const slotStringValue = reactComponents.length === 1 ? reactComponents[0] : `<>${reactComponents.join('\n')}</>`;
|
|
296
|
+
str += ` ${key}={${slotStringValue}} `;
|
|
301
297
|
}
|
|
302
298
|
}
|
|
303
299
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
@@ -309,22 +305,21 @@ var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
|
309
305
|
return str;
|
|
310
306
|
}
|
|
311
307
|
// TODO: update MitosisNode for simple code
|
|
312
|
-
|
|
308
|
+
let childrenNodes = '';
|
|
313
309
|
if (json.children) {
|
|
314
310
|
childrenNodes = json.children
|
|
315
|
-
.map(
|
|
311
|
+
.map((item) => (0, exports.blockToReact)(item, options, component, true, needsToRenderSlots))
|
|
316
312
|
.join('');
|
|
317
313
|
}
|
|
318
314
|
if (needsToRenderSlots.length) {
|
|
319
|
-
needsToRenderSlots.forEach(
|
|
320
|
-
|
|
321
|
-
str += " ".concat(key, "={").concat(value, "} ");
|
|
315
|
+
needsToRenderSlots.forEach(({ key, value }) => {
|
|
316
|
+
str += ` ${key}={${value}} `;
|
|
322
317
|
});
|
|
323
318
|
}
|
|
324
319
|
str = str.trim() + '>';
|
|
325
320
|
if (json.children) {
|
|
326
321
|
str += childrenNodes;
|
|
327
322
|
}
|
|
328
|
-
return str +
|
|
323
|
+
return str + `</${json.name}>`;
|
|
329
324
|
};
|
|
330
325
|
exports.blockToReact = blockToReact;
|