@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,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSignalsCode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return function (_a) {
|
|
11
|
-
var key = _a[0], stateVal = _a[1];
|
|
4
|
+
const function_1 = require("fp-ts/lib/function");
|
|
5
|
+
const patterns_1 = require("../../../helpers/patterns");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
const processSignalStateValue = ({ options, component, }) => {
|
|
8
|
+
const mapValue = (0, helpers_1.updateStateCode)({ options, component });
|
|
9
|
+
return ([key, stateVal]) => {
|
|
12
10
|
if (!stateVal) {
|
|
13
11
|
return '';
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var value = stateVal.code;
|
|
19
|
-
var type = stateVal.type;
|
|
13
|
+
const getDefaultCase = () => (0, function_1.pipe)(value, mapValue, (x) => `const [${key}, ${(0, helpers_1.getStateSetterName)(key)}] = createSignal(${x})`);
|
|
14
|
+
const value = stateVal.code;
|
|
15
|
+
const type = stateVal.type;
|
|
20
16
|
if (typeof value === 'string') {
|
|
21
17
|
switch (type) {
|
|
22
18
|
case 'getter':
|
|
23
|
-
return (0, function_1.pipe)(value, mapValue, patterns_1.extractGetterCodeBlock,
|
|
19
|
+
return (0, function_1.pipe)(value, mapValue, patterns_1.extractGetterCodeBlock, (x) => `const ${key} = createMemo(() => {${x}})`);
|
|
24
20
|
case 'function':
|
|
25
21
|
return mapValue(value);
|
|
26
22
|
case 'method':
|
|
@@ -34,27 +30,24 @@ var processSignalStateValue = function (_a) {
|
|
|
34
30
|
}
|
|
35
31
|
};
|
|
36
32
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
.join(LINE_ITEM_DELIMITER);
|
|
59
|
-
};
|
|
33
|
+
const LINE_ITEM_DELIMITER = '\n\n\n';
|
|
34
|
+
const getSignalsCode = ({ json, options, state, }) => Object.entries(state)
|
|
35
|
+
.map(processSignalStateValue({ options, component: json }))
|
|
36
|
+
/**
|
|
37
|
+
* We need to sort state so that signals are at the top.
|
|
38
|
+
*/
|
|
39
|
+
.sort((a, b) => {
|
|
40
|
+
const aHasSignal = a.includes('createSignal(');
|
|
41
|
+
const bHasSignal = b.includes('createSignal(');
|
|
42
|
+
if (aHasSignal && !bHasSignal) {
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
else if (!aHasSignal && bHasSignal) {
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.join(LINE_ITEM_DELIMITER);
|
|
60
53
|
exports.getSignalsCode = getSignalsCode;
|
|
@@ -1,64 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
-
if (ar || !(i in from)) {
|
|
16
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
-
ar[i] = from[i];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.getState = void 0;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var hasState = (0, state_1.checkHasState)(json);
|
|
4
|
+
const function_1 = require("fp-ts/lib/function");
|
|
5
|
+
const get_state_object_string_1 = require("../../../helpers/get-state-object-string");
|
|
6
|
+
const state_1 = require("../../../helpers/state");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
const signals_1 = require("./signals");
|
|
9
|
+
const store_1 = require("./store");
|
|
10
|
+
const getState = ({ json, options, }) => {
|
|
11
|
+
const hasState = (0, state_1.checkHasState)(json);
|
|
33
12
|
if (!hasState) {
|
|
34
13
|
return undefined;
|
|
35
14
|
}
|
|
36
15
|
// unbundle state in case the user provides a type override of one of the state values
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var key = _a[0], value = _a[1];
|
|
40
|
-
var stateType = (0, helpers_1.getStateTypeForValue)({ value: key, component: json, options: options });
|
|
16
|
+
const { mutable, signal, store } = Object.entries(json.state).reduce((acc, [key, value]) => {
|
|
17
|
+
const stateType = (0, helpers_1.getStateTypeForValue)({ value: key, component: json, options });
|
|
41
18
|
switch (stateType) {
|
|
42
19
|
case 'mutable':
|
|
43
|
-
return
|
|
20
|
+
return { ...acc, mutable: { ...acc.mutable, [key]: value } };
|
|
44
21
|
case 'signals':
|
|
45
|
-
return
|
|
22
|
+
return { ...acc, signal: { ...acc.signal, [key]: value } };
|
|
46
23
|
case 'store':
|
|
47
|
-
return
|
|
24
|
+
return { ...acc, store: { ...acc.store, [key]: value } };
|
|
48
25
|
}
|
|
49
|
-
}, { mutable: {}, signal: {}, store: {} })
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
? (0, function_1.pipe)(mutable, get_state_object_string_1.getMemberObjectString,
|
|
26
|
+
}, { mutable: {}, signal: {}, store: {} });
|
|
27
|
+
const hasMutableState = Object.keys(mutable).length > 0;
|
|
28
|
+
const hasSignalState = Object.keys(signal).length > 0;
|
|
29
|
+
const hasStoreState = Object.keys(store).length > 0;
|
|
30
|
+
const mutableStateStr = hasMutableState
|
|
31
|
+
? (0, function_1.pipe)(mutable, get_state_object_string_1.getMemberObjectString, (str) => `const state = createMutable(${str});`)
|
|
55
32
|
: '';
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
33
|
+
const signalStateStr = hasSignalState ? (0, signals_1.getSignalsCode)({ json, options, state: signal }) : '';
|
|
34
|
+
const storeStateStr = hasStoreState ? (0, store_1.getStoreCode)({ json, options, state: store }) : '';
|
|
35
|
+
const stateStr = `
|
|
36
|
+
${mutableStateStr}
|
|
37
|
+
${signalStateStr}
|
|
38
|
+
${storeStateStr}
|
|
39
|
+
`;
|
|
40
|
+
const importObj = {
|
|
41
|
+
store: [
|
|
42
|
+
...(hasMutableState ? ['createMutable'] : []),
|
|
43
|
+
...(hasStoreState ? ['createStore', 'reconcile'] : []),
|
|
44
|
+
],
|
|
45
|
+
solidjs: [
|
|
46
|
+
...(hasSignalState ? ['createSignal', 'createMemo'] : []),
|
|
47
|
+
...(hasStoreState ? ['createEffect', 'on'] : []),
|
|
48
|
+
],
|
|
62
49
|
};
|
|
63
50
|
return {
|
|
64
51
|
str: stateStr,
|
|
@@ -1,69 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getStoreCode = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
const function_1 = require("fp-ts/lib/function");
|
|
6
|
+
const babel_transform_1 = require("../../../helpers/babel-transform");
|
|
7
|
+
const capitalize_1 = require("../../../helpers/capitalize");
|
|
8
|
+
const patterns_1 = require("../../../helpers/patterns");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
10
|
+
const collectUsedStateAndPropsInFunction = (fnValue) => {
|
|
11
|
+
const stateUsed = new Set();
|
|
12
|
+
const propsUsed = new Set();
|
|
22
13
|
(0, babel_transform_1.babelTransformExpression)(fnValue, {
|
|
23
|
-
MemberExpression
|
|
24
|
-
|
|
14
|
+
MemberExpression(path) {
|
|
15
|
+
const { node } = path;
|
|
25
16
|
if (core_1.types.isIdentifier(node.object)) {
|
|
26
17
|
if (core_1.types.isIdentifier(node.property)) {
|
|
27
18
|
if (node.object.name === 'state') {
|
|
28
|
-
stateUsed.add(
|
|
19
|
+
stateUsed.add(`state.${node.property.name}`);
|
|
29
20
|
}
|
|
30
21
|
else if (node.object.name === 'props') {
|
|
31
|
-
propsUsed.add(
|
|
22
|
+
propsUsed.add(`props.${node.property.name}`);
|
|
32
23
|
}
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
26
|
},
|
|
36
27
|
});
|
|
37
|
-
return { stateUsed
|
|
28
|
+
return { stateUsed, propsUsed };
|
|
38
29
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var stateUpdater = function (_a) {
|
|
43
|
-
var key = _a[0], stateVal = _a[1];
|
|
30
|
+
const getStoreCode = ({ json: component, options, state, }) => {
|
|
31
|
+
const mapValue = (0, helpers_1.updateStateCode)({ options, component });
|
|
32
|
+
const stateUpdater = ([key, stateVal]) => {
|
|
44
33
|
if (!stateVal) {
|
|
45
34
|
return '';
|
|
46
35
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var value = stateVal.code;
|
|
52
|
-
var type = stateVal.type;
|
|
36
|
+
const getCreateStoreStr = (initialValue) => `const [${key}, ${(0, helpers_1.getStateSetterName)(key)}] = createStore(${initialValue})`;
|
|
37
|
+
const getDefaultCase = () => (0, function_1.pipe)(value, mapValue, getCreateStoreStr);
|
|
38
|
+
const value = stateVal.code;
|
|
39
|
+
const type = stateVal.type;
|
|
53
40
|
if (typeof value === 'string') {
|
|
54
41
|
switch (type) {
|
|
55
42
|
case 'getter':
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
43
|
+
const getterValueAsFunction = (0, patterns_1.replaceGetterWithFunction)(value);
|
|
44
|
+
const { stateUsed, propsUsed } = collectUsedStateAndPropsInFunction(getterValueAsFunction);
|
|
45
|
+
const fnValueWithMappedRefs = mapValue(getterValueAsFunction);
|
|
46
|
+
const FUNCTION_NAME = `update${(0, capitalize_1.capitalize)(key)}`;
|
|
47
|
+
const deps = [
|
|
48
|
+
...Array.from(stateUsed).map((0, helpers_1.updateStateCode)({
|
|
49
|
+
options,
|
|
50
|
+
component,
|
|
51
|
+
// there are no setters in deps
|
|
52
|
+
updateSetters: false,
|
|
53
|
+
})),
|
|
54
|
+
...Array.from(propsUsed),
|
|
55
|
+
].join(', ');
|
|
56
|
+
return `
|
|
57
|
+
const ${FUNCTION_NAME} = ${fnValueWithMappedRefs}
|
|
58
|
+
${getCreateStoreStr(`${FUNCTION_NAME}()`)}
|
|
59
|
+
createEffect(on(() => [${deps}], () => ${(0, helpers_1.getStateSetterName)(key)}(reconcile(${FUNCTION_NAME}()))))
|
|
60
|
+
`;
|
|
67
61
|
case 'function':
|
|
68
62
|
return mapValue(value);
|
|
69
63
|
case 'method':
|
|
@@ -79,4 +73,4 @@ var getStoreCode = function (_a) {
|
|
|
79
73
|
return Object.entries(state).map(stateUpdater).join(LINE_ITEM_DELIMITER);
|
|
80
74
|
};
|
|
81
75
|
exports.getStoreCode = getStoreCode;
|
|
82
|
-
|
|
76
|
+
const LINE_ITEM_DELIMITER = '\n\n\n';
|
|
@@ -3,11 +3,9 @@ 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
|
-
if (bindingCloseChar === void 0) { bindingCloseChar = '}'; }
|
|
10
|
-
var staticClasses = [];
|
|
8
|
+
const staticClasses = [];
|
|
11
9
|
if (json.properties.class) {
|
|
12
10
|
staticClasses.push(json.properties.class);
|
|
13
11
|
delete json.properties.class;
|
|
@@ -16,7 +14,7 @@ function collectClassString(json, bindingOpenChar, bindingCloseChar) {
|
|
|
16
14
|
staticClasses.push(json.properties.className);
|
|
17
15
|
delete json.properties.className;
|
|
18
16
|
}
|
|
19
|
-
|
|
17
|
+
const dynamicClasses = [];
|
|
20
18
|
if (typeof ((_a = json.bindings.class) === null || _a === void 0 ? void 0 : _a.code) === 'string') {
|
|
21
19
|
dynamicClasses.push(json.bindings.class.code);
|
|
22
20
|
delete json.bindings.class;
|
|
@@ -25,18 +23,18 @@ function collectClassString(json, bindingOpenChar, bindingCloseChar) {
|
|
|
25
23
|
dynamicClasses.push(json.bindings.className.code);
|
|
26
24
|
delete json.bindings.className;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const staticClassesString = staticClasses.join(' ');
|
|
27
|
+
const dynamicClassesString = dynamicClasses.join(" + ' ' + ");
|
|
28
|
+
const hasStaticClasses = Boolean(staticClasses.length);
|
|
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
|
}
|