@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
|
@@ -4,153 +4,159 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.blockToSvelte = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
const bindings_1 = require("../../helpers/bindings");
|
|
8
|
+
const is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
9
|
+
const is_upper_case_1 = require("../../helpers/is-upper-case");
|
|
10
|
+
const for_1 = require("../../helpers/nodes/for");
|
|
11
|
+
const remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
|
|
12
|
+
const slots_1 = require("../../helpers/slots");
|
|
13
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
14
|
+
const helpers_1 = require("./helpers");
|
|
15
15
|
/**
|
|
16
16
|
* blockToSvelte executed after stripStateAndProps,
|
|
17
17
|
* when stripStateAndProps is executed,
|
|
18
18
|
* SLOT_PREFIX from `slot` change to `$$slots.`
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
style:
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
props += " ".concat(key, "=\"").concat(value, "\" ");
|
|
20
|
+
const SLOT_PREFIX = '$$slots.';
|
|
21
|
+
const mappers = {
|
|
22
|
+
style: ({ json, options, parentComponent }) => {
|
|
23
|
+
var _a;
|
|
24
|
+
let props = '';
|
|
25
|
+
for (const key in json.properties) {
|
|
26
|
+
const value = json.properties[key];
|
|
27
|
+
props += ` ${key}="${value}" `;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
for (
|
|
32
|
-
|
|
29
|
+
let bindings = '';
|
|
30
|
+
for (const key in json.bindings) {
|
|
31
|
+
const value = json.bindings[key];
|
|
33
32
|
if (value && key !== 'innerHTML') {
|
|
34
|
-
bindings +=
|
|
33
|
+
bindings += ` ${key}=\${${value.code}} `;
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
|
-
|
|
36
|
+
const innerText = ((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code) || '';
|
|
38
37
|
// We have to obfuscate `"style"` due to a limitation in the svelte-preprocessor plugin.
|
|
39
38
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
40
|
-
return
|
|
39
|
+
return `{@html \`<\${'style'} ${bindings} ${props}>\${${innerText}}<\${'/style'}>\`}`;
|
|
41
40
|
},
|
|
42
|
-
script:
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
props += " ".concat(key, "=\"").concat(value, "\" ");
|
|
41
|
+
script: ({ json, options, parentComponent }) => {
|
|
42
|
+
var _a;
|
|
43
|
+
let props = '';
|
|
44
|
+
for (const key in json.properties) {
|
|
45
|
+
const value = json.properties[key];
|
|
46
|
+
props += ` ${key}="${value}" `;
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
for (
|
|
52
|
-
|
|
48
|
+
let bindings = '';
|
|
49
|
+
for (const key in json.bindings) {
|
|
50
|
+
const value = json.bindings[key];
|
|
53
51
|
if (value && key !== 'innerHTML') {
|
|
54
|
-
bindings +=
|
|
52
|
+
bindings += ` ${key}=\${${value.code}} `;
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
return
|
|
55
|
+
const innerText = ((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code) || '';
|
|
56
|
+
return `{@html \`<script ${bindings} ${props}>\${${innerText}}</script>\`}`;
|
|
59
57
|
},
|
|
60
|
-
Fragment:
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
if ((_b = json.bindings.innerHTML) === null || _b === void 0 ? void 0 : _b.code) {
|
|
58
|
+
Fragment: ({ json, options, parentComponent }) => {
|
|
59
|
+
var _a;
|
|
60
|
+
if ((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code) {
|
|
64
61
|
return BINDINGS_MAPPER.innerHTML(json, options);
|
|
65
62
|
}
|
|
66
63
|
else if (json.children.length > 0) {
|
|
67
|
-
return
|
|
68
|
-
.map(
|
|
69
|
-
.join('\n')
|
|
64
|
+
return `${json.children
|
|
65
|
+
.map((item) => (0, exports.blockToSvelte)({ json: item, options, parentComponent }))
|
|
66
|
+
.join('\n')}`;
|
|
70
67
|
}
|
|
71
68
|
else {
|
|
72
69
|
return '';
|
|
73
70
|
}
|
|
74
71
|
},
|
|
75
|
-
For:
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var keyValue = firstChild.properties.key || ((_b = firstChild.bindings.key) === null || _b === void 0 ? void 0 : _b.code);
|
|
72
|
+
For: ({ json, options, parentComponent }) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const firstChild = json.children[0];
|
|
75
|
+
const keyValue = firstChild.properties.key || ((_a = firstChild.bindings.key) === null || _a === void 0 ? void 0 : _a.code);
|
|
80
76
|
if (keyValue) {
|
|
81
77
|
// we remove extraneous prop which Svelte does not use
|
|
82
78
|
delete firstChild.properties.key;
|
|
83
79
|
delete firstChild.bindings.key;
|
|
84
80
|
}
|
|
85
|
-
|
|
86
|
-
return
|
|
81
|
+
const args = (0, for_1.getForArguments)(json, { excludeCollectionName: true }).join(', ');
|
|
82
|
+
return `
|
|
83
|
+
{#each ${(_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code} as ${args} ${keyValue ? `(${keyValue})` : ''}}
|
|
84
|
+
${json.children.map((item) => (0, exports.blockToSvelte)({ json: item, options, parentComponent })).join('\n')}
|
|
85
|
+
{/each}
|
|
86
|
+
`;
|
|
87
87
|
},
|
|
88
|
-
Show:
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
Show: ({ json, options, parentComponent }) => {
|
|
89
|
+
var _a;
|
|
90
|
+
return `
|
|
91
|
+
{#if ${(_a = json.bindings.when) === null || _a === void 0 ? void 0 : _a.code} }
|
|
92
|
+
${json.children.map((item) => (0, exports.blockToSvelte)({ json: item, options, parentComponent })).join('\n')}
|
|
93
|
+
|
|
94
|
+
${json.meta.else
|
|
95
|
+
? `
|
|
96
|
+
{:else}
|
|
97
|
+
${(0, exports.blockToSvelte)({
|
|
93
98
|
json: json.meta.else,
|
|
94
|
-
options
|
|
95
|
-
parentComponent
|
|
96
|
-
})
|
|
97
|
-
|
|
99
|
+
options,
|
|
100
|
+
parentComponent,
|
|
101
|
+
})}
|
|
102
|
+
`
|
|
103
|
+
: ''}
|
|
104
|
+
{/if}`;
|
|
98
105
|
},
|
|
99
|
-
Slot
|
|
100
|
-
var _b, _c
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
var renderChildren = function () {
|
|
106
|
+
Slot({ json, options, parentComponent }) {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
const slotName = ((_a = json.bindings.name) === null || _a === void 0 ? void 0 : _a.code) || json.properties.name;
|
|
109
|
+
const renderChildren = () => {
|
|
104
110
|
var _a;
|
|
105
|
-
return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(
|
|
111
|
+
return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map((item) => (0, exports.blockToSvelte)({ json: item, options, parentComponent })).join('\n');
|
|
106
112
|
};
|
|
107
113
|
if (!slotName) {
|
|
108
|
-
|
|
114
|
+
const key = Object.keys(json.bindings).find(Boolean);
|
|
109
115
|
if (!key) {
|
|
110
|
-
if (!((
|
|
116
|
+
if (!((_b = json.children) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
111
117
|
return '<slot/>';
|
|
112
118
|
}
|
|
113
|
-
return
|
|
119
|
+
return `<slot>${renderChildren()}</slot>`;
|
|
114
120
|
}
|
|
115
|
-
return
|
|
121
|
+
return `
|
|
122
|
+
<span #${key}>
|
|
123
|
+
${(_c = json.bindings[key]) === null || _c === void 0 ? void 0 : _c.code}
|
|
124
|
+
</span>
|
|
125
|
+
`;
|
|
116
126
|
}
|
|
117
|
-
return
|
|
127
|
+
return `<slot name="${(0, slots_1.toKebabSlot)(slotName, SLOT_PREFIX)}">${renderChildren()}</slot>`;
|
|
118
128
|
},
|
|
119
129
|
};
|
|
120
|
-
|
|
121
|
-
innerHTML:
|
|
130
|
+
const BINDINGS_MAPPER = {
|
|
131
|
+
innerHTML: (json, options) => { var _a; return `{@html ${(_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code}}`; },
|
|
122
132
|
};
|
|
123
|
-
|
|
133
|
+
const SVELTE_SPECIAL_TAGS = {
|
|
124
134
|
COMPONENT: 'svelte:component',
|
|
125
135
|
ELEMENT: 'svelte:element',
|
|
126
136
|
SELF: 'svelte:self',
|
|
127
137
|
};
|
|
128
|
-
|
|
129
|
-
var json = _a.json, parentComponent = _a.parentComponent, options = _a.options;
|
|
138
|
+
const getTagName = ({ json, parentComponent, options, }) => {
|
|
130
139
|
if (parentComponent && json.name === parentComponent.name) {
|
|
131
140
|
return SVELTE_SPECIAL_TAGS.SELF;
|
|
132
141
|
}
|
|
133
142
|
/**
|
|
134
143
|
* These are special HTML tags that svelte requires `<svelte:element this={TAG}>`
|
|
135
144
|
*/
|
|
136
|
-
|
|
145
|
+
const SPECIAL_HTML_TAGS = ['script', 'template'];
|
|
137
146
|
if (SPECIAL_HTML_TAGS.includes(json.name)) {
|
|
138
147
|
json.bindings.this = (0, bindings_1.createSingleBinding)({
|
|
139
|
-
code: "
|
|
148
|
+
code: `"${json.name}"`,
|
|
140
149
|
});
|
|
141
150
|
return SVELTE_SPECIAL_TAGS.ELEMENT;
|
|
142
151
|
}
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
const isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name);
|
|
153
|
+
const isSpecialSvelteTag = json.name.startsWith('svelte:');
|
|
145
154
|
// Check if any import matches `json.name`
|
|
146
|
-
|
|
147
|
-
var imports = _a.imports;
|
|
148
|
-
return Object.keys(imports).some(function (name) { return name === json.name; });
|
|
149
|
-
});
|
|
155
|
+
const hasMatchingImport = parentComponent.imports.some(({ imports }) => Object.keys(imports).some((name) => name === json.name));
|
|
150
156
|
// If none of these are true, then we have some type of dynamic tag name
|
|
151
157
|
if (!isValidHtmlTag && !isSpecialSvelteTag && !hasMatchingImport) {
|
|
152
158
|
json.bindings.this = (0, bindings_1.createSingleBinding)({
|
|
153
|
-
code: (0, helpers_1.stripStateAndProps)({ json: parentComponent, options
|
|
159
|
+
code: (0, helpers_1.stripStateAndProps)({ json: parentComponent, options })(json.name),
|
|
154
160
|
});
|
|
155
161
|
// TO-DO: no way to perfectly decide between <svelte:component> and <svelte:element> for dynamic
|
|
156
162
|
// values...need to do that through metadata overrides for now.
|
|
@@ -158,95 +164,91 @@ var getTagName = function (_a) {
|
|
|
158
164
|
}
|
|
159
165
|
return json.name;
|
|
160
166
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (valueWithoutBlock === key) {
|
|
179
|
-
return " on:".concat(event_1, "={").concat(valueWithoutBlock, "} ");
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
return " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat(valueWithoutBlock, "}}\" ");
|
|
183
|
-
}
|
|
167
|
+
const stringifyBinding = (node, options) => ([key, binding]) => {
|
|
168
|
+
if (key === 'innerHTML' || !binding) {
|
|
169
|
+
return '';
|
|
170
|
+
}
|
|
171
|
+
const { code, arguments: cusArgs = ['event'], type } = binding;
|
|
172
|
+
const isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(node.name) || node.name === 'svelte:element';
|
|
173
|
+
if (type === 'spread') {
|
|
174
|
+
const spreadValue = key === 'props' ? '$$props' : code;
|
|
175
|
+
return ` {...${spreadValue}} `;
|
|
176
|
+
}
|
|
177
|
+
else if (key.startsWith('on') && isValidHtmlTag) {
|
|
178
|
+
// handle html native on[event] props
|
|
179
|
+
const event = key.replace('on', '').toLowerCase();
|
|
180
|
+
// TODO: handle quotes in event handler values
|
|
181
|
+
const valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
|
|
182
|
+
if (valueWithoutBlock === key) {
|
|
183
|
+
return ` on:${event}={${valueWithoutBlock}} `;
|
|
184
184
|
}
|
|
185
|
-
else
|
|
186
|
-
|
|
187
|
-
var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
|
|
188
|
-
if (valueWithoutBlock === key) {
|
|
189
|
-
return " ".concat(key, "={").concat(valueWithoutBlock, "} ");
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
return " ".concat(key, "={(").concat(cusArgs.join(','), ") => ").concat(valueWithoutBlock, "}");
|
|
193
|
-
}
|
|
185
|
+
else {
|
|
186
|
+
return ` on:${event}="{${cusArgs.join(',')} => {${valueWithoutBlock}}}" `;
|
|
194
187
|
}
|
|
195
|
-
|
|
196
|
-
|
|
188
|
+
}
|
|
189
|
+
else if (key.startsWith('on')) {
|
|
190
|
+
// handle on[custom event] props
|
|
191
|
+
const valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
|
|
192
|
+
if (valueWithoutBlock === key) {
|
|
193
|
+
return ` ${key}={${valueWithoutBlock}} `;
|
|
197
194
|
}
|
|
198
195
|
else {
|
|
199
|
-
return
|
|
196
|
+
return ` ${key}={(${cusArgs.join(',')}) => ${valueWithoutBlock}}`;
|
|
200
197
|
}
|
|
201
|
-
}
|
|
198
|
+
}
|
|
199
|
+
else if (key === 'ref') {
|
|
200
|
+
return ` bind:this={${code}} `;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return ` ${key}={${code}} `;
|
|
204
|
+
}
|
|
202
205
|
};
|
|
203
|
-
|
|
204
|
-
var _b, _c, _d
|
|
205
|
-
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
206
|
+
const blockToSvelte = ({ json, options, parentComponent }) => {
|
|
207
|
+
var _a, _b, _c, _d;
|
|
206
208
|
if (mappers[json.name]) {
|
|
207
209
|
return mappers[json.name]({
|
|
208
210
|
json: json,
|
|
209
|
-
options
|
|
210
|
-
parentComponent
|
|
211
|
+
options,
|
|
212
|
+
parentComponent,
|
|
211
213
|
});
|
|
212
214
|
}
|
|
213
|
-
|
|
215
|
+
const tagName = getTagName({ json, parentComponent, options });
|
|
214
216
|
if ((0, is_children_1.default)({ node: json, extraMatches: ['$$slots.default'] })) {
|
|
215
|
-
return
|
|
217
|
+
return `<slot></slot>`;
|
|
216
218
|
}
|
|
217
219
|
if (json.properties._text) {
|
|
218
220
|
return json.properties._text;
|
|
219
221
|
}
|
|
220
|
-
|
|
222
|
+
const textCode = (_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
|
|
221
223
|
if (textCode) {
|
|
222
224
|
if ((0, slots_1.isSlotProperty)(textCode, SLOT_PREFIX)) {
|
|
223
|
-
return
|
|
225
|
+
return `<slot name="${(0, slots_1.stripSlotPrefix)(textCode, SLOT_PREFIX).toLowerCase()}"/>`;
|
|
224
226
|
}
|
|
225
|
-
return
|
|
227
|
+
return `{${textCode}}`;
|
|
226
228
|
}
|
|
227
|
-
|
|
228
|
-
str +=
|
|
229
|
-
|
|
230
|
-
if ((((
|
|
231
|
-
|
|
232
|
-
str +=
|
|
229
|
+
let str = '';
|
|
230
|
+
str += `<${tagName} `;
|
|
231
|
+
const isComponent = Boolean(tagName[0] && (0, is_upper_case_1.isUpperCase)(tagName[0]));
|
|
232
|
+
if ((((_b = json.bindings.style) === null || _b === void 0 ? void 0 : _b.code) || json.properties.style) && !isComponent) {
|
|
233
|
+
const useValue = ((_c = json.bindings.style) === null || _c === void 0 ? void 0 : _c.code) || json.properties.style;
|
|
234
|
+
str += `style={stringifyStyles(${useValue})}`;
|
|
233
235
|
delete json.bindings.style;
|
|
234
236
|
delete json.properties.style;
|
|
235
237
|
}
|
|
236
|
-
for (
|
|
237
|
-
|
|
238
|
-
str +=
|
|
238
|
+
for (const key in json.properties) {
|
|
239
|
+
const value = json.properties[key];
|
|
240
|
+
str += ` ${key}="${value}" `;
|
|
239
241
|
}
|
|
240
|
-
|
|
242
|
+
const stringifiedBindings = Object.entries(json.bindings)
|
|
241
243
|
.map(stringifyBinding(json, options))
|
|
242
244
|
.join('');
|
|
243
245
|
str += stringifiedBindings;
|
|
244
246
|
// if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
|
|
245
247
|
// we use the innerHTML content as children and don't render the self-closing tag.
|
|
246
|
-
if ((
|
|
248
|
+
if ((_d = json.bindings.innerHTML) === null || _d === void 0 ? void 0 : _d.code) {
|
|
247
249
|
str += '>';
|
|
248
250
|
str += BINDINGS_MAPPER.innerHTML(json, options);
|
|
249
|
-
str +=
|
|
251
|
+
str += `</${tagName}>`;
|
|
250
252
|
return str;
|
|
251
253
|
}
|
|
252
254
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(tagName)) {
|
|
@@ -255,10 +257,10 @@ var blockToSvelte = function (_a) {
|
|
|
255
257
|
str += '>';
|
|
256
258
|
if (json.children) {
|
|
257
259
|
str += json.children
|
|
258
|
-
.map(
|
|
260
|
+
.map((item) => (0, exports.blockToSvelte)({ json: item, options, parentComponent }))
|
|
259
261
|
.join('');
|
|
260
262
|
}
|
|
261
|
-
str +=
|
|
263
|
+
str += `</${tagName}>`;
|
|
262
264
|
return str;
|
|
263
265
|
};
|
|
264
266
|
exports.blockToSvelte = blockToSvelte;
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stripStateAndProps = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
: (0, slots_1.isSlotProperty)(name)
|
|
15
|
-
? (0, slots_1.replaceSlotsInString)(name, function (x) { return "$$slots.".concat(x); })
|
|
16
|
-
: name;
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
};
|
|
4
|
+
const slots_1 = require("../../helpers/slots");
|
|
5
|
+
const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
6
|
+
const stripStateAndProps = ({ options, json }) => (code) => (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
7
|
+
includeState: options.stateType === 'variables',
|
|
8
|
+
replaceWith: (name) => name === 'children'
|
|
9
|
+
? '$$slots.default'
|
|
10
|
+
: (0, slots_1.isSlotProperty)(name)
|
|
11
|
+
? (0, slots_1.replaceSlotsInString)(name, (x) => `$$slots.${x}`)
|
|
12
|
+
: name,
|
|
13
|
+
});
|
|
21
14
|
exports.stripStateAndProps = stripStateAndProps;
|