@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,93 +1,92 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.componentToStencil = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
const dash_case_1 = require("../../helpers/dash-case");
|
|
5
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
6
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
7
|
+
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
8
|
+
const get_props_1 = require("../../helpers/get-props");
|
|
9
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
10
|
+
const indent_1 = require("../../helpers/indent");
|
|
11
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
12
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
13
|
+
const for_1 = require("../../helpers/nodes/for");
|
|
14
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
15
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
16
|
+
const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
17
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
18
|
+
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
19
|
+
const standalone_1 = require("prettier/standalone");
|
|
20
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
21
|
+
const plugins_1 = require("../../modules/plugins");
|
|
22
|
+
const on_mount_1 = require("../helpers/on-mount");
|
|
23
|
+
const collect_class_string_1 = require("./collect-class-string");
|
|
24
|
+
const blockToStencil = (json, options = {}, insideJsx) => {
|
|
29
25
|
var _a, _b, _c, _d;
|
|
30
|
-
if (options === void 0) { options = {}; }
|
|
31
26
|
if (json.properties._text) {
|
|
32
27
|
return json.properties._text;
|
|
33
28
|
}
|
|
34
29
|
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
35
30
|
if (insideJsx) {
|
|
36
|
-
return
|
|
31
|
+
return `{${processBinding(json.bindings._text.code)}}`;
|
|
37
32
|
}
|
|
38
33
|
return processBinding((_b = json.bindings) === null || _b === void 0 ? void 0 : _b._text.code);
|
|
39
34
|
}
|
|
40
35
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
const wrap = json.children.length !== 1;
|
|
37
|
+
const forArgs = (0, for_1.getForArguments)(json).join(', ');
|
|
38
|
+
const expression = `${processBinding((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code)}?.map((${forArgs}) => (
|
|
39
|
+
${wrap ? '<>' : ''}${json.children
|
|
44
40
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
45
|
-
.map(
|
|
46
|
-
.join('\n')
|
|
41
|
+
.map((item) => blockToStencil(item, options, wrap))
|
|
42
|
+
.join('\n')}${wrap ? '</>' : ''}
|
|
43
|
+
))`;
|
|
47
44
|
if (insideJsx) {
|
|
48
|
-
return
|
|
45
|
+
return `{${expression}}`;
|
|
49
46
|
}
|
|
50
47
|
else {
|
|
51
48
|
return expression;
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
else if (json.name === 'Show') {
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const wrap = json.children.length !== 1;
|
|
53
|
+
const expression = `${processBinding((_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code)} ? (
|
|
54
|
+
${wrap ? '<>' : ''}${json.children
|
|
57
55
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
58
|
-
.map(
|
|
59
|
-
.join('\n')
|
|
56
|
+
.map((item) => blockToStencil(item, options, wrap))
|
|
57
|
+
.join('\n')}${wrap ? '</>' : ''}
|
|
58
|
+
) : ${!json.meta.else ? 'null' : blockToStencil(json.meta.else, options, false)}`;
|
|
60
59
|
if (insideJsx) {
|
|
61
|
-
return
|
|
60
|
+
return `{${expression}}`;
|
|
62
61
|
}
|
|
63
62
|
else {
|
|
64
63
|
return expression;
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
str +=
|
|
69
|
-
|
|
66
|
+
let str = '';
|
|
67
|
+
str += `<${json.name} `;
|
|
68
|
+
const classString = (0, collect_class_string_1.collectClassString)(json);
|
|
70
69
|
if (classString) {
|
|
71
|
-
str +=
|
|
70
|
+
str += ` class=${classString} `;
|
|
72
71
|
}
|
|
73
|
-
for (
|
|
74
|
-
|
|
75
|
-
str +=
|
|
72
|
+
for (const key in json.properties) {
|
|
73
|
+
const value = json.properties[key];
|
|
74
|
+
str += ` ${key}="${value}" `;
|
|
76
75
|
}
|
|
77
|
-
for (
|
|
78
|
-
|
|
76
|
+
for (const key in json.bindings) {
|
|
77
|
+
const { code, arguments: cusArgs = ['event'], type } = json.bindings[key];
|
|
79
78
|
if (type === 'spread') {
|
|
80
|
-
str +=
|
|
79
|
+
str += ` {...(${code})} `;
|
|
81
80
|
}
|
|
82
81
|
else if (key === 'ref') {
|
|
83
|
-
str +=
|
|
82
|
+
str += ` ref={(el) => this.${code} = el} `;
|
|
84
83
|
}
|
|
85
84
|
else if (key.startsWith('on')) {
|
|
86
|
-
|
|
87
|
-
str +=
|
|
85
|
+
const useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
86
|
+
str += ` ${useKey}={${cusArgs.join(',')} => ${processBinding(code)}} `;
|
|
88
87
|
}
|
|
89
88
|
else {
|
|
90
|
-
str +=
|
|
89
|
+
str += ` ${key}={${processBinding(code)}} `;
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
@@ -95,107 +94,121 @@ var blockToStencil = function (json, options, insideJsx) {
|
|
|
95
94
|
}
|
|
96
95
|
str += '>';
|
|
97
96
|
if (json.children) {
|
|
98
|
-
str += json.children.map(
|
|
97
|
+
str += json.children.map((item) => blockToStencil(item, options, true)).join('\n');
|
|
99
98
|
}
|
|
100
|
-
str +=
|
|
99
|
+
str += `</${json.name}>`;
|
|
101
100
|
return str;
|
|
102
101
|
};
|
|
103
102
|
function processBinding(code) {
|
|
104
103
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: 'this.' });
|
|
105
104
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
css = (0, standalone_1.format)(css, {
|
|
142
|
-
parser: 'css',
|
|
143
|
-
plugins: [require('prettier/parser-postcss')],
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
console.warn('Could not format css', err);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n import { Component, Prop, h, State, Fragment } from '@stencil/core';\n\n @Component({\n tag: '", "',\n ", "\n })\n export default class ", " {\n\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n\n render() {\n return (", "\n\n ", "\n\n ", ")\n }\n }\n "], ["\n ", "\n\n import { Component, Prop, h, State, Fragment } from '@stencil/core';\n\n @Component({\n tag: '"
|
|
151
|
-
/**
|
|
152
|
-
* You can set the tagName in your Mitosis component as
|
|
153
|
-
*
|
|
154
|
-
* useMetadata({
|
|
155
|
-
* tagName: 'my-tag
|
|
156
|
-
* })
|
|
157
|
-
*
|
|
158
|
-
* export default function ...
|
|
159
|
-
*/
|
|
160
|
-
, "',\n ", "\n })\n export default class ", " {\n\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n\n render() {\n return (", "\n\n ", "\n\n ", ")\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
161
|
-
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
162
|
-
component: json,
|
|
163
|
-
target: 'stencil',
|
|
164
|
-
}),
|
|
165
|
-
/**
|
|
166
|
-
* You can set the tagName in your Mitosis component as
|
|
167
|
-
*
|
|
168
|
-
* useMetadata({
|
|
169
|
-
* tagName: 'my-tag
|
|
170
|
-
* })
|
|
171
|
-
*
|
|
172
|
-
* export default function ...
|
|
173
|
-
*/
|
|
174
|
-
((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName) || (0, dash_case_1.dashCase)(json.name), css.length
|
|
175
|
-
? "styles: `\n ".concat((0, indent_1.indent)(css, 8), "`,")
|
|
176
|
-
: '', json.name, Array.from(props)
|
|
177
|
-
.map(function (item) { return "@Prop() ".concat(item, ": any"); })
|
|
178
|
-
.join('\n'), dataString, methodsString, !json.hooks.onMount.length
|
|
179
|
-
? ''
|
|
180
|
-
: "componentDidLoad() { ".concat(processBinding((0, on_mount_1.stringifySingleScopeOnMount)(json)), " }"), !((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code)
|
|
181
|
-
? ''
|
|
182
|
-
: "disconnectedCallback() { ".concat(processBinding(json.hooks.onUnMount.code), " }"), !((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length)
|
|
183
|
-
? ''
|
|
184
|
-
: json.hooks.onUpdate.map(function (hook) { return "componentDidUpdate() { ".concat(processBinding(hook.code), " }"); }), wrap ? '<>' : '', json.children.map(function (item) { return blockToStencil(item, options, true); }).join('\n'), wrap ? '</>' : '');
|
|
185
|
-
if (options.plugins) {
|
|
186
|
-
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
187
|
-
}
|
|
188
|
-
if (options.prettier !== false) {
|
|
189
|
-
str = (0, standalone_1.format)(str, {
|
|
190
|
-
parser: 'typescript',
|
|
191
|
-
plugins: [require('prettier/parser-typescript')],
|
|
105
|
+
const componentToStencil = (_options = {}) => ({ component }) => {
|
|
106
|
+
var _a, _b, _c;
|
|
107
|
+
const options = (0, merge_options_1.initializeOptions)({ target: 'stencil', component, defaults: _options });
|
|
108
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
109
|
+
if (options.plugins) {
|
|
110
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
111
|
+
}
|
|
112
|
+
const props = (0, get_props_1.getProps)(component);
|
|
113
|
+
let css = (0, collect_css_1.collectCss)(json);
|
|
114
|
+
(0, map_refs_1.mapRefs)(component, (refName) => `this.${refName}`);
|
|
115
|
+
if (options.plugins) {
|
|
116
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
117
|
+
}
|
|
118
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
119
|
+
const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
120
|
+
format: 'class',
|
|
121
|
+
data: true,
|
|
122
|
+
functions: false,
|
|
123
|
+
getters: false,
|
|
124
|
+
keyPrefix: '@State() ',
|
|
125
|
+
valueMapper: (code) => processBinding(code),
|
|
126
|
+
});
|
|
127
|
+
const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
128
|
+
format: 'class',
|
|
129
|
+
data: false,
|
|
130
|
+
functions: true,
|
|
131
|
+
getters: true,
|
|
132
|
+
valueMapper: (code) => processBinding(code),
|
|
133
|
+
});
|
|
134
|
+
const wrap = json.children.length !== 1;
|
|
135
|
+
if (options.prettier !== false) {
|
|
136
|
+
try {
|
|
137
|
+
css = (0, standalone_1.format)(css, {
|
|
138
|
+
parser: 'css',
|
|
139
|
+
plugins: [require('prettier/parser-postcss')],
|
|
192
140
|
});
|
|
193
141
|
}
|
|
194
|
-
|
|
195
|
-
|
|
142
|
+
catch (err) {
|
|
143
|
+
console.warn('Could not format css', err);
|
|
196
144
|
}
|
|
197
|
-
|
|
198
|
-
|
|
145
|
+
}
|
|
146
|
+
let str = (0, dedent_1.dedent) `
|
|
147
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
148
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
149
|
+
component: json,
|
|
150
|
+
target: 'stencil',
|
|
151
|
+
})}
|
|
152
|
+
|
|
153
|
+
import { Component, Prop, h, State, Fragment } from '@stencil/core';
|
|
154
|
+
|
|
155
|
+
@Component({
|
|
156
|
+
tag: '${
|
|
157
|
+
/**
|
|
158
|
+
* You can set the tagName in your Mitosis component as
|
|
159
|
+
*
|
|
160
|
+
* useMetadata({
|
|
161
|
+
* tagName: 'my-tag
|
|
162
|
+
* })
|
|
163
|
+
*
|
|
164
|
+
* export default function ...
|
|
165
|
+
*/
|
|
166
|
+
((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.tagName) || (0, dash_case_1.dashCase)(json.name)}',
|
|
167
|
+
${css.length
|
|
168
|
+
? `styles: \`
|
|
169
|
+
${(0, indent_1.indent)(css, 8)}\`,`
|
|
170
|
+
: ''}
|
|
171
|
+
})
|
|
172
|
+
export default class ${json.name} {
|
|
173
|
+
|
|
174
|
+
${Array.from(props)
|
|
175
|
+
.map((item) => `@Prop() ${item}: any`)
|
|
176
|
+
.join('\n')}
|
|
177
|
+
|
|
178
|
+
${dataString}
|
|
179
|
+
${methodsString}
|
|
180
|
+
|
|
181
|
+
${!json.hooks.onMount.length
|
|
182
|
+
? ''
|
|
183
|
+
: `componentDidLoad() { ${processBinding((0, on_mount_1.stringifySingleScopeOnMount)(json))} }`}
|
|
184
|
+
${!((_b = json.hooks.onUnMount) === null || _b === void 0 ? void 0 : _b.code)
|
|
185
|
+
? ''
|
|
186
|
+
: `disconnectedCallback() { ${processBinding(json.hooks.onUnMount.code)} }`}
|
|
187
|
+
${!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)
|
|
188
|
+
? ''
|
|
189
|
+
: json.hooks.onUpdate.map((hook) => `componentDidUpdate() { ${processBinding(hook.code)} }`)}
|
|
190
|
+
|
|
191
|
+
render() {
|
|
192
|
+
return (${wrap ? '<>' : ''}
|
|
193
|
+
|
|
194
|
+
${json.children.map((item) => blockToStencil(item, options, true)).join('\n')}
|
|
195
|
+
|
|
196
|
+
${wrap ? '</>' : ''})
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
`;
|
|
200
|
+
if (options.plugins) {
|
|
201
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
202
|
+
}
|
|
203
|
+
if (options.prettier !== false) {
|
|
204
|
+
str = (0, standalone_1.format)(str, {
|
|
205
|
+
parser: 'typescript',
|
|
206
|
+
plugins: [require('prettier/parser-typescript')],
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (options.plugins) {
|
|
210
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
211
|
+
}
|
|
212
|
+
return str;
|
|
199
213
|
};
|
|
200
214
|
exports.componentToStencil = componentToStencil;
|
|
201
|
-
var templateObject_1;
|