@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,101 +1,100 @@
|
|
|
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.componentToLit = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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_refs_1 = require("../../helpers/get-refs");
|
|
10
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
11
|
+
const has_1 = require("../../helpers/has");
|
|
12
|
+
const indent_1 = require("../../helpers/indent");
|
|
13
|
+
const is_upper_case_1 = require("../../helpers/is-upper-case");
|
|
14
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
15
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
16
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
17
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
18
|
+
const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
19
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
20
|
+
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
21
|
+
const lodash_1 = require("lodash");
|
|
22
|
+
const standalone_1 = require("prettier/standalone");
|
|
23
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
24
|
+
const plugins_1 = require("../../modules/plugins");
|
|
25
|
+
const on_mount_1 = require("../helpers/on-mount");
|
|
26
|
+
const collect_class_string_1 = require("./collect-class-string");
|
|
27
|
+
const getCustomTagName = (name, options) => {
|
|
32
28
|
if (!name || !(0, is_upper_case_1.isUpperCase)(name[0])) {
|
|
33
29
|
return name;
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
const kebabCaseName = (0, dash_case_1.dashCase)(name);
|
|
36
32
|
if (!kebabCaseName.includes('-')) {
|
|
37
33
|
// TODO: option to choose your prefix
|
|
38
34
|
return 'my-' + kebabCaseName;
|
|
39
35
|
}
|
|
40
36
|
return kebabCaseName;
|
|
41
37
|
};
|
|
42
|
-
|
|
38
|
+
const blockToLit = (json, options = {}) => {
|
|
43
39
|
var _a, _b, _c, _d;
|
|
44
|
-
if (options === void 0) { options = {}; }
|
|
45
40
|
if (json.properties._text) {
|
|
46
41
|
return json.properties._text;
|
|
47
42
|
}
|
|
48
43
|
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
49
|
-
return
|
|
44
|
+
return `\${${processBinding((_b = json.bindings) === null || _b === void 0 ? void 0 : _b._text.code)}}`;
|
|
50
45
|
}
|
|
51
46
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
52
|
-
return
|
|
47
|
+
return `\${${processBinding((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code)}?.map((${json.scope.forName}, index) => (
|
|
48
|
+
html\`${json.children
|
|
53
49
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
54
|
-
.map(
|
|
55
|
-
.join('\n')
|
|
50
|
+
.map((item) => blockToLit(item, options))
|
|
51
|
+
.join('\n')}\`
|
|
52
|
+
))}`;
|
|
56
53
|
}
|
|
57
54
|
else if (json.name === 'Show') {
|
|
58
|
-
return
|
|
55
|
+
return `\${${processBinding((_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code)} ?
|
|
56
|
+
html\`${json.children
|
|
59
57
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
60
|
-
.map(
|
|
61
|
-
.join('\n')
|
|
58
|
+
.map((item) => blockToLit(item, options))
|
|
59
|
+
.join('\n')}\`
|
|
60
|
+
: ${!json.meta.else ? 'null' : `html\`${blockToLit(json.meta.else, options)}\``}}`;
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
str +=
|
|
66
|
-
|
|
62
|
+
let str = '';
|
|
63
|
+
const tagName = getCustomTagName(json.name, options);
|
|
64
|
+
str += `<${tagName} `;
|
|
65
|
+
const classString = (0, collect_class_string_1.collectClassString)(json);
|
|
67
66
|
if (classString) {
|
|
68
|
-
str +=
|
|
67
|
+
str += ` class=${classString} `;
|
|
69
68
|
}
|
|
70
|
-
for (
|
|
71
|
-
|
|
72
|
-
str +=
|
|
69
|
+
for (const key in json.properties) {
|
|
70
|
+
const value = json.properties[key];
|
|
71
|
+
str += ` ${key}="${value}" `;
|
|
73
72
|
}
|
|
74
|
-
for (
|
|
75
|
-
|
|
73
|
+
for (const key in json.bindings) {
|
|
74
|
+
const { code, arguments: cusArgs = ['event'], type } = json.bindings[key];
|
|
76
75
|
if (type === 'spread') {
|
|
77
|
-
str +=
|
|
76
|
+
str += ` \${spread(${code})} `;
|
|
78
77
|
}
|
|
79
78
|
else if (key === 'ref') {
|
|
80
79
|
// TODO: maybe use ref directive instead
|
|
81
80
|
// https://lit.dev/docs/templates/directives/#ref
|
|
82
|
-
str +=
|
|
81
|
+
str += ` ref="${code}" `;
|
|
83
82
|
}
|
|
84
83
|
else if (key.startsWith('on')) {
|
|
85
|
-
|
|
84
|
+
let useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
86
85
|
useKey = '@' + useKey.substring(2).toLowerCase();
|
|
87
|
-
str +=
|
|
86
|
+
str += ` ${useKey}=\${${cusArgs.join(',')} => ${processBinding(code)}} `;
|
|
88
87
|
}
|
|
89
88
|
else {
|
|
90
|
-
|
|
89
|
+
const value = processBinding(code);
|
|
91
90
|
// If they key includes a '-' it's an attribute, not a property
|
|
92
91
|
if (key.includes('-')) {
|
|
93
|
-
str +=
|
|
92
|
+
str += ` ${key}=\${${value}} `;
|
|
94
93
|
}
|
|
95
94
|
else {
|
|
96
95
|
// TODO: handle boolean attributes too by matching list of html boolean attributes
|
|
97
96
|
// https://lit.dev/docs/templates/expressions/#boolean-attribute-expressions
|
|
98
|
-
str +=
|
|
97
|
+
str += ` .${key}=\${${value}} `;
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
}
|
|
@@ -104,122 +103,168 @@ var blockToLit = function (json, options) {
|
|
|
104
103
|
}
|
|
105
104
|
str += '>';
|
|
106
105
|
if (json.children) {
|
|
107
|
-
str += json.children.map(
|
|
106
|
+
str += json.children.map((item) => blockToLit(item, options)).join('\n');
|
|
108
107
|
}
|
|
109
|
-
str +=
|
|
108
|
+
str += `</${tagName}>`;
|
|
110
109
|
return str;
|
|
111
110
|
};
|
|
112
111
|
function processBinding(code) {
|
|
113
112
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: 'this.' });
|
|
114
113
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
const componentToLit = (_options = {}) => ({ component }) => {
|
|
115
|
+
var _a, _b, _c;
|
|
116
|
+
const options = (0, merge_options_1.initializeOptions)({ target: 'lit', component, defaults: _options });
|
|
117
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
118
|
+
if (options.plugins) {
|
|
119
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
120
|
+
}
|
|
121
|
+
const props = (0, get_props_1.getProps)(component);
|
|
122
|
+
let css = (0, collect_css_1.collectCss)(json);
|
|
123
|
+
const domRefs = (0, get_refs_1.getRefs)(json);
|
|
124
|
+
(0, map_refs_1.mapRefs)(component, (refName) => `this.${(0, lodash_1.camelCase)(refName)}`);
|
|
125
|
+
if (options.plugins) {
|
|
126
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
127
|
+
}
|
|
128
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
129
|
+
const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
130
|
+
format: 'class',
|
|
131
|
+
data: true,
|
|
132
|
+
functions: false,
|
|
133
|
+
getters: false,
|
|
134
|
+
keyPrefix: '@state() ',
|
|
135
|
+
valueMapper: (code) => processBinding(code),
|
|
136
|
+
});
|
|
137
|
+
const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
138
|
+
format: 'class',
|
|
139
|
+
data: false,
|
|
140
|
+
functions: true,
|
|
141
|
+
getters: true,
|
|
142
|
+
valueMapper: (code) => processBinding(code),
|
|
143
|
+
});
|
|
144
|
+
if (options.prettier !== false) {
|
|
145
|
+
try {
|
|
146
|
+
css = (0, standalone_1.format)(css, {
|
|
147
|
+
parser: 'css',
|
|
148
|
+
plugins: [require('prettier/parser-postcss')],
|
|
149
|
+
});
|
|
124
150
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var domRefs = (0, get_refs_1.getRefs)(json);
|
|
128
|
-
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.".concat((0, lodash_1.camelCase)(refName)); });
|
|
129
|
-
if (options.plugins) {
|
|
130
|
-
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
151
|
+
catch (err) {
|
|
152
|
+
console.warn('Could not format css', err);
|
|
131
153
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
142
|
-
format: 'class',
|
|
143
|
-
data: false,
|
|
144
|
-
functions: true,
|
|
145
|
-
getters: true,
|
|
146
|
-
valueMapper: function (code) { return processBinding(code); },
|
|
147
|
-
});
|
|
148
|
-
if (options.prettier !== false) {
|
|
149
|
-
try {
|
|
150
|
-
css = (0, standalone_1.format)(css, {
|
|
151
|
-
parser: 'css',
|
|
152
|
-
plugins: [require('prettier/parser-postcss')],
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
catch (err) {
|
|
156
|
-
console.warn('Could not format css', err);
|
|
157
|
-
}
|
|
154
|
+
}
|
|
155
|
+
let html = json.children.map((item) => blockToLit(item, options)).join('\n');
|
|
156
|
+
const hasSpread = (0, has_1.has)(json, (node) => (0, lodash_1.some)(node.bindings, { type: 'spread' }));
|
|
157
|
+
if (options.prettier !== false) {
|
|
158
|
+
try {
|
|
159
|
+
css = (0, standalone_1.format)(css, {
|
|
160
|
+
parser: 'css',
|
|
161
|
+
plugins: [require('prettier/parser-postcss')],
|
|
162
|
+
});
|
|
158
163
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (options.prettier !== false) {
|
|
162
|
-
try {
|
|
163
|
-
css = (0, standalone_1.format)(css, {
|
|
164
|
-
parser: 'css',
|
|
165
|
-
plugins: [require('prettier/parser-postcss')],
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
console.warn('Could not format css', err);
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
html = (0, standalone_1.format)(html, {
|
|
173
|
-
parser: 'html',
|
|
174
|
-
plugins: [require('prettier/parser-html')],
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
catch (err) {
|
|
178
|
-
// If can't format HTML (this can happen with lit given it is tagged template strings),
|
|
179
|
-
// at least remove excess space
|
|
180
|
-
html = html.replace(/\n{3,}/g, '\n\n');
|
|
181
|
-
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
console.warn('Could not format css', err);
|
|
182
166
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
? "\n const spread = (properties) =>\n directive((part) => {\n for (const property in properties) {\n const value = properties[attr];\n part.element[property] = value;\n }\n });\n "
|
|
189
|
-
: '', ((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName) || getCustomTagName(json.name, options), json.name, options.useShadowDom
|
|
190
|
-
? ''
|
|
191
|
-
: "\n createRenderRoot() {\n return this;\n }\n ", options.useShadowDom && css.length
|
|
192
|
-
? "static styles = css`\n ".concat((0, indent_1.indent)(css, 8), "`;")
|
|
193
|
-
: '', Array.from(domRefs)
|
|
194
|
-
.map(function (refName) { return "\n @query('[ref=\"".concat(refName, "\"]')\n ").concat((0, lodash_1.camelCase)(refName), "!: HTMLElement;\n "); })
|
|
195
|
-
.join('\n'), Array.from(props)
|
|
196
|
-
.map(function (item) { return "@property() ".concat(item, ": any"); })
|
|
197
|
-
.join('\n'), dataString, methodsString, json.hooks.onMount.length === 0
|
|
198
|
-
? ''
|
|
199
|
-
: "connectedCallback() { ".concat(processBinding((0, on_mount_1.stringifySingleScopeOnMount)(json)), " }"), !((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code)
|
|
200
|
-
? ''
|
|
201
|
-
: "disconnectedCallback() { ".concat(processBinding(json.hooks.onUnMount.code), " }"), !((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length)
|
|
202
|
-
? ''
|
|
203
|
-
: "updated() { \n ".concat(json.hooks.onUpdate.map(function (hook) { return processBinding(hook.code); }).join('\n\n'), " \n }"), options.useShadowDom || !css.length ? '' : "<style>".concat(css, "</style>"), (0, indent_1.indent)(html, 8));
|
|
204
|
-
if (options.plugins) {
|
|
205
|
-
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
167
|
+
try {
|
|
168
|
+
html = (0, standalone_1.format)(html, {
|
|
169
|
+
parser: 'html',
|
|
170
|
+
plugins: [require('prettier/parser-html')],
|
|
171
|
+
});
|
|
206
172
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
plugins: [require('prettier/parser-typescript')],
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
console.warn('Could not format Lit typescript', err);
|
|
216
|
-
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
// If can't format HTML (this can happen with lit given it is tagged template strings),
|
|
175
|
+
// at least remove excess space
|
|
176
|
+
html = html.replace(/\n{3,}/g, '\n\n');
|
|
217
177
|
}
|
|
218
|
-
|
|
219
|
-
|
|
178
|
+
}
|
|
179
|
+
let str = (0, dedent_1.dedent) `
|
|
180
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
181
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
182
|
+
component: json,
|
|
183
|
+
target: 'lit',
|
|
184
|
+
})}
|
|
185
|
+
import { LitElement, html, css } from 'lit';
|
|
186
|
+
import { customElement, property, state, query } from 'lit/decorators.js';
|
|
187
|
+
|
|
188
|
+
${json.types ? json.types.join('\n') : ''}
|
|
189
|
+
${hasSpread
|
|
190
|
+
? `
|
|
191
|
+
const spread = (properties) =>
|
|
192
|
+
directive((part) => {
|
|
193
|
+
for (const property in properties) {
|
|
194
|
+
const value = properties[attr];
|
|
195
|
+
part.element[property] = value;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
`
|
|
199
|
+
: ''}
|
|
200
|
+
|
|
201
|
+
@customElement('${((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.tagName) || getCustomTagName(json.name, options)}')
|
|
202
|
+
export default class ${json.name} extends LitElement {
|
|
203
|
+
${options.useShadowDom
|
|
204
|
+
? ''
|
|
205
|
+
: `
|
|
206
|
+
createRenderRoot() {
|
|
207
|
+
return this;
|
|
220
208
|
}
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
`}
|
|
210
|
+
|
|
211
|
+
${options.useShadowDom && css.length
|
|
212
|
+
? `static styles = css\`
|
|
213
|
+
${(0, indent_1.indent)(css, 8)}\`;`
|
|
214
|
+
: ''}
|
|
215
|
+
|
|
216
|
+
${Array.from(domRefs)
|
|
217
|
+
.map((refName) => `
|
|
218
|
+
@query('[ref="${refName}"]')
|
|
219
|
+
${(0, lodash_1.camelCase)(refName)}!: HTMLElement;
|
|
220
|
+
`)
|
|
221
|
+
.join('\n')}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
${Array.from(props)
|
|
225
|
+
.map((item) => `@property() ${item}: any`)
|
|
226
|
+
.join('\n')}
|
|
227
|
+
|
|
228
|
+
${dataString}
|
|
229
|
+
${methodsString}
|
|
230
|
+
|
|
231
|
+
${json.hooks.onMount.length === 0
|
|
232
|
+
? ''
|
|
233
|
+
: `connectedCallback() { ${processBinding((0, on_mount_1.stringifySingleScopeOnMount)(json))} }`}
|
|
234
|
+
${!((_b = json.hooks.onUnMount) === null || _b === void 0 ? void 0 : _b.code)
|
|
235
|
+
? ''
|
|
236
|
+
: `disconnectedCallback() { ${processBinding(json.hooks.onUnMount.code)} }`}
|
|
237
|
+
${!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)
|
|
238
|
+
? ''
|
|
239
|
+
: `updated() {
|
|
240
|
+
${json.hooks.onUpdate.map((hook) => processBinding(hook.code)).join('\n\n')}
|
|
241
|
+
}`}
|
|
242
|
+
|
|
243
|
+
render() {
|
|
244
|
+
return html\`
|
|
245
|
+
${options.useShadowDom || !css.length ? '' : `<style>${css}</style>`}
|
|
246
|
+
${(0, indent_1.indent)(html, 8)}
|
|
247
|
+
\`
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
`;
|
|
251
|
+
if (options.plugins) {
|
|
252
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
253
|
+
}
|
|
254
|
+
if (options.prettier !== false) {
|
|
255
|
+
try {
|
|
256
|
+
str = (0, standalone_1.format)(str, {
|
|
257
|
+
parser: 'typescript',
|
|
258
|
+
plugins: [require('prettier/parser-typescript')],
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
console.warn('Could not format Lit typescript', err);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (options.plugins) {
|
|
266
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
267
|
+
}
|
|
268
|
+
return str;
|
|
223
269
|
};
|
|
224
270
|
exports.componentToLit = componentToLit;
|
|
225
|
-
var templateObject_1;
|