@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,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentToLiquid = exports.isValidLiquidBinding = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const standalone_1 = require("prettier/standalone");
|
|
5
|
+
const html_tags_1 = require("../constants/html_tags");
|
|
6
|
+
const fast_clone_1 = require("../helpers/fast-clone");
|
|
7
|
+
const get_state_object_string_1 = require("../helpers/get-state-object-string");
|
|
8
|
+
const strip_meta_properties_1 = require("../helpers/strip-meta-properties");
|
|
9
|
+
const strip_state_and_props_refs_1 = require("../helpers/strip-state-and-props-refs");
|
|
10
|
+
const collect_css_1 = require("../helpers/styles/collect-css");
|
|
11
|
+
const plugins_1 = require("../modules/plugins");
|
|
12
|
+
const mitosis_node_1 = require("../types/mitosis-node");
|
|
13
13
|
/**
|
|
14
14
|
* Test if the binding expression would be likely to generate
|
|
15
15
|
* valid or invalid liquid. If we generate invalid liquid tags
|
|
16
16
|
* Shopify will reject our PUT to update the template
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var strictMatches = Boolean(
|
|
18
|
+
const isValidLiquidBinding = (str = '') => {
|
|
19
|
+
const strictMatches = Boolean(
|
|
21
20
|
// Test for our `context.shopify.liquid.*(expression), which
|
|
22
21
|
// we regex out later to transform back into valid liquid expressions
|
|
23
22
|
str.match(/(context|ctx)\s*(\.shopify\s*)?\.liquid\s*\./));
|
|
@@ -27,15 +26,14 @@ var isValidLiquidBinding = function (str) {
|
|
|
27
26
|
Boolean(str.match(/^[a-z0-9_\.\s]+$/i)));
|
|
28
27
|
};
|
|
29
28
|
exports.isValidLiquidBinding = isValidLiquidBinding;
|
|
30
|
-
|
|
31
|
-
Fragment:
|
|
32
|
-
return
|
|
29
|
+
const mappers = {
|
|
30
|
+
Fragment: (json, options) => {
|
|
31
|
+
return `<div>${json.children.map((item) => blockToLiquid(item, options)).join('\n')}</div>`;
|
|
33
32
|
},
|
|
34
33
|
};
|
|
35
34
|
// TODO: spread support
|
|
36
|
-
|
|
35
|
+
const blockToLiquid = (json, options = {}) => {
|
|
37
36
|
var _a, _b, _c, _d, _e, _f;
|
|
38
|
-
if (options === void 0) { options = {}; }
|
|
39
37
|
if (mappers[json.name]) {
|
|
40
38
|
return mappers[json.name](json, options);
|
|
41
39
|
}
|
|
@@ -47,16 +45,16 @@ var blockToLiquid = function (json, options) {
|
|
|
47
45
|
if (!(0, exports.isValidLiquidBinding)(json.bindings._text.code)) {
|
|
48
46
|
return '';
|
|
49
47
|
}
|
|
50
|
-
return
|
|
48
|
+
return `{{${(0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings._text.code)}}}`;
|
|
51
49
|
}
|
|
52
|
-
|
|
50
|
+
let str = '';
|
|
53
51
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
54
52
|
if (!((0, exports.isValidLiquidBinding)((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code) && (0, exports.isValidLiquidBinding)(json.scope.forName))) {
|
|
55
53
|
return str;
|
|
56
54
|
}
|
|
57
|
-
str +=
|
|
55
|
+
str += `{% for ${json.scope.forName} in ${(0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code)} %}`;
|
|
58
56
|
if (json.children) {
|
|
59
|
-
str += json.children.map(
|
|
57
|
+
str += json.children.map((item) => blockToLiquid(item, options)).join('\n');
|
|
60
58
|
}
|
|
61
59
|
str += '{% endfor %}';
|
|
62
60
|
}
|
|
@@ -64,34 +62,38 @@ var blockToLiquid = function (json, options) {
|
|
|
64
62
|
if (!(0, exports.isValidLiquidBinding)((_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code)) {
|
|
65
63
|
return str;
|
|
66
64
|
}
|
|
67
|
-
str +=
|
|
65
|
+
str += `{% if ${(0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_e = json.bindings.when) === null || _e === void 0 ? void 0 : _e.code)} %}`;
|
|
68
66
|
if (json.children) {
|
|
69
|
-
str += json.children.map(
|
|
67
|
+
str += json.children.map((item) => blockToLiquid(item, options)).join('\n');
|
|
70
68
|
}
|
|
71
69
|
str += '{% endif %}';
|
|
72
70
|
}
|
|
73
71
|
else {
|
|
74
|
-
str +=
|
|
72
|
+
str += `<${json.name} `;
|
|
75
73
|
if (((_f = json.bindings._spread) === null || _f === void 0 ? void 0 : _f.code) === '_spread' &&
|
|
76
74
|
(0, exports.isValidLiquidBinding)(json.bindings._spread.code)) {
|
|
77
|
-
str +=
|
|
75
|
+
str += `
|
|
76
|
+
{% for _attr in ${json.bindings._spread.code} %}
|
|
77
|
+
{{ _attr[0] }}="{{ _attr[1] }}"
|
|
78
|
+
{% endfor %}
|
|
79
|
+
`;
|
|
78
80
|
}
|
|
79
|
-
for (
|
|
80
|
-
|
|
81
|
-
str +=
|
|
81
|
+
for (const key in json.properties) {
|
|
82
|
+
const value = json.properties[key];
|
|
83
|
+
str += ` ${key}="${value}" `;
|
|
82
84
|
}
|
|
83
|
-
for (
|
|
85
|
+
for (const key in json.bindings) {
|
|
84
86
|
if (key === '_spread' || key === 'ref' || key === 'css') {
|
|
85
87
|
continue;
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
const { code: value } = json.bindings[key];
|
|
88
90
|
// TODO: proper babel transform to replace. Util for this
|
|
89
|
-
|
|
91
|
+
const useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value);
|
|
90
92
|
if (key.startsWith('on')) {
|
|
91
93
|
// Do nothing
|
|
92
94
|
}
|
|
93
95
|
else if ((0, exports.isValidLiquidBinding)(useValue)) {
|
|
94
|
-
str +=
|
|
96
|
+
str += ` ${key}="{{${useValue}}}" `;
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
@@ -99,60 +101,60 @@ var blockToLiquid = function (json, options) {
|
|
|
99
101
|
}
|
|
100
102
|
str += '>';
|
|
101
103
|
if (json.children) {
|
|
102
|
-
str += json.children.map(
|
|
104
|
+
str += json.children.map((item) => blockToLiquid(item, options)).join('\n');
|
|
103
105
|
}
|
|
104
|
-
str +=
|
|
106
|
+
str += `</${json.name}>`;
|
|
105
107
|
}
|
|
106
108
|
return str;
|
|
107
109
|
};
|
|
108
110
|
// TODO: add JS support similar to componentToHtml()
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
str += "<script reactive>\n export default {\n state: ".concat(stateObjectString, "\n }\n </script>");
|
|
130
|
-
}
|
|
111
|
+
const componentToLiquid = (options = {}) => ({ component }) => {
|
|
112
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
113
|
+
if (options.plugins) {
|
|
114
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
115
|
+
}
|
|
116
|
+
const css = (0, collect_css_1.collectCss)(json);
|
|
117
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
118
|
+
if (options.plugins) {
|
|
119
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
120
|
+
}
|
|
121
|
+
let str = json.children.map((item) => blockToLiquid(item)).join('\n');
|
|
122
|
+
if (css.trim().length) {
|
|
123
|
+
str += `<style>${css}</style>`;
|
|
124
|
+
}
|
|
125
|
+
if (options.reactive) {
|
|
126
|
+
const stateObjectString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json);
|
|
127
|
+
if (stateObjectString.trim().length > 4) {
|
|
128
|
+
str += `<script reactive>
|
|
129
|
+
export default {
|
|
130
|
+
state: ${stateObjectString}
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
132
|
+
</script>`;
|
|
134
133
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
134
|
+
}
|
|
135
|
+
if (options.plugins) {
|
|
136
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
137
|
+
}
|
|
138
|
+
if (options.prettier !== false) {
|
|
139
|
+
try {
|
|
140
|
+
str = (0, standalone_1.format)(str, {
|
|
141
|
+
parser: 'html',
|
|
142
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
143
|
+
plugins: [
|
|
144
|
+
// To support running in browsers
|
|
145
|
+
require('prettier/parser-html'),
|
|
146
|
+
require('prettier/parser-postcss'),
|
|
147
|
+
require('prettier/parser-babel'),
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
154
153
|
}
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
}
|
|
155
|
+
if (options.plugins) {
|
|
156
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
157
|
+
}
|
|
158
|
+
return str;
|
|
157
159
|
};
|
|
158
160
|
exports.componentToLiquid = componentToLiquid;
|
|
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.collectClassString = void 0;
|
|
4
4
|
// This should really be a preprocessor mapping the `class` attribute binding based on what other values have
|
|
5
5
|
// to make this more pluggable
|
|
6
|
-
function collectClassString(json, bindingOpenChar, bindingCloseChar) {
|
|
6
|
+
function collectClassString(json, bindingOpenChar = '{', bindingCloseChar = '}') {
|
|
7
7
|
var _a, _b;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var staticClasses = [];
|
|
11
|
-
var hasStaticClasses = Boolean(staticClasses.length);
|
|
8
|
+
const staticClasses = [];
|
|
9
|
+
const hasStaticClasses = Boolean(staticClasses.length);
|
|
12
10
|
if (json.properties.class) {
|
|
13
11
|
staticClasses.push(json.properties.class);
|
|
14
12
|
delete json.properties.class;
|
|
@@ -17,7 +15,7 @@ function collectClassString(json, bindingOpenChar, bindingCloseChar) {
|
|
|
17
15
|
staticClasses.push(json.properties.className);
|
|
18
16
|
delete json.properties.className;
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
const dynamicClasses = [];
|
|
21
19
|
if (typeof ((_a = json.bindings.class) === null || _a === void 0 ? void 0 : _a.code) === 'string') {
|
|
22
20
|
dynamicClasses.push(json.bindings.class.code);
|
|
23
21
|
delete json.bindings.class;
|
|
@@ -26,17 +24,17 @@ function collectClassString(json, bindingOpenChar, bindingCloseChar) {
|
|
|
26
24
|
dynamicClasses.push(json.bindings.className.code);
|
|
27
25
|
delete json.bindings.className;
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const staticClassesString = staticClasses.join(' ');
|
|
28
|
+
const dynamicClassesString = dynamicClasses.join(" + ' ' + ");
|
|
29
|
+
const hasDynamicClasses = Boolean(dynamicClasses.length);
|
|
32
30
|
if (hasStaticClasses && !hasDynamicClasses) {
|
|
33
|
-
return "
|
|
31
|
+
return `"${staticClassesString}"`;
|
|
34
32
|
}
|
|
35
33
|
if (hasDynamicClasses && !hasStaticClasses) {
|
|
36
|
-
return
|
|
34
|
+
return `${bindingOpenChar}${dynamicClassesString}${bindingCloseChar}`;
|
|
37
35
|
}
|
|
38
36
|
if (hasDynamicClasses && hasStaticClasses) {
|
|
39
|
-
return
|
|
37
|
+
return `${bindingOpenChar}"${staticClassesString} " + ${dynamicClassesString}${bindingCloseChar}`;
|
|
40
38
|
}
|
|
41
39
|
return null;
|
|
42
40
|
}
|