@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,25 +1,14 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.processTagReferences = exports.wrapInFragment = exports.getFragment = exports.closeFrag = exports.openFrag = exports.processBinding = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
8
|
+
const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
11
|
+
const processBinding = (str, options) => {
|
|
23
12
|
// fix web-component tag transform issue with dashes by not transforming it
|
|
24
13
|
if (options.stateType !== 'useState') {
|
|
25
14
|
return str;
|
|
@@ -30,35 +19,41 @@ var processBinding = function (str, options) {
|
|
|
30
19
|
});
|
|
31
20
|
};
|
|
32
21
|
exports.processBinding = processBinding;
|
|
33
|
-
|
|
22
|
+
const openFrag = (options) => getFragment('open', options);
|
|
34
23
|
exports.openFrag = openFrag;
|
|
35
|
-
|
|
24
|
+
const closeFrag = (options) => getFragment('close', options);
|
|
36
25
|
exports.closeFrag = closeFrag;
|
|
37
26
|
function getFragment(type, options) {
|
|
38
|
-
|
|
39
|
-
return type === 'open' ?
|
|
27
|
+
const tagName = options.preact ? 'Fragment' : '';
|
|
28
|
+
return type === 'open' ? `<${tagName}>` : `</${tagName}>`;
|
|
40
29
|
}
|
|
41
30
|
exports.getFragment = getFragment;
|
|
42
|
-
|
|
31
|
+
const wrapInFragment = (json) => json.children.length !== 1;
|
|
43
32
|
exports.wrapInFragment = wrapInFragment;
|
|
44
33
|
function getRefName(path) {
|
|
45
34
|
return (0, lodash_1.upperFirst)(path) + 'Ref';
|
|
46
35
|
}
|
|
47
36
|
function processTagReferences(json, options) {
|
|
48
|
-
|
|
49
|
-
(0, legacy_1.default)(json).forEach(
|
|
37
|
+
const namesFound = new Set();
|
|
38
|
+
(0, legacy_1.default)(json).forEach((el) => {
|
|
50
39
|
var _a, _b;
|
|
51
40
|
if (!(0, is_mitosis_node_1.isMitosisNode)(el)) {
|
|
52
41
|
return;
|
|
53
42
|
}
|
|
54
|
-
|
|
43
|
+
const processedRefName = el.name.includes('-') ? el.name : (0, exports.processBinding)(el.name, options);
|
|
55
44
|
if (el.name.includes('state.')) {
|
|
56
45
|
switch ((_a = json.state[processedRefName]) === null || _a === void 0 ? void 0 : _a.type) {
|
|
57
46
|
case 'getter':
|
|
58
|
-
|
|
47
|
+
const refName = getRefName(processedRefName);
|
|
59
48
|
if (!namesFound.has(el.name)) {
|
|
60
49
|
namesFound.add(el.name);
|
|
61
|
-
json.hooks.init =
|
|
50
|
+
json.hooks.init = {
|
|
51
|
+
...json.hooks.init,
|
|
52
|
+
code: `
|
|
53
|
+
${((_b = json.hooks.init) === null || _b === void 0 ? void 0 : _b.code) || ''}
|
|
54
|
+
const ${refName} = ${el.name};
|
|
55
|
+
`,
|
|
56
|
+
};
|
|
62
57
|
}
|
|
63
58
|
el.name = refName;
|
|
64
59
|
break;
|
|
@@ -67,10 +62,10 @@ function processTagReferences(json, options) {
|
|
|
67
62
|
case 'method':
|
|
68
63
|
case 'function':
|
|
69
64
|
case 'property':
|
|
70
|
-
|
|
65
|
+
const capitalizedName = (0, lodash_1.upperFirst)(processedRefName);
|
|
71
66
|
if (capitalizedName !== processedRefName) {
|
|
72
67
|
el.name = capitalizedName;
|
|
73
|
-
json.state[capitalizedName] =
|
|
68
|
+
json.state[capitalizedName] = { ...json.state[processedRefName] };
|
|
74
69
|
delete json.state[processedRefName];
|
|
75
70
|
}
|
|
76
71
|
else {
|
|
@@ -1,59 +1,42 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.updateStateSettersInCode = exports.updateStateSetters = exports.getUseStateCode = exports.processHookCode = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
const capitalize_1 = require("../../helpers/capitalize");
|
|
8
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
9
|
+
const patterns_1 = require("../../helpers/patterns");
|
|
10
|
+
const transform_state_setters_1 = require("../../helpers/transform-state-setters");
|
|
11
|
+
const core_1 = require("@babel/core");
|
|
12
|
+
const function_1 = require("fp-ts/lib/function");
|
|
13
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
14
|
+
const helpers_1 = require("./helpers");
|
|
26
15
|
/**
|
|
27
16
|
* Removes all `this.` references.
|
|
28
17
|
*/
|
|
29
|
-
|
|
18
|
+
const stripThisRefs = (str, options) => {
|
|
30
19
|
if (options.stateType !== 'useState') {
|
|
31
20
|
return str;
|
|
32
21
|
}
|
|
33
22
|
return str.replace(/this\.([a-zA-Z_\$0-9]+)/g, '$1');
|
|
34
23
|
};
|
|
35
|
-
|
|
36
|
-
var str = _a.str, options = _a.options;
|
|
37
|
-
return (0, helpers_1.processBinding)((0, exports.updateStateSettersInCode)(str, options), options);
|
|
38
|
-
};
|
|
24
|
+
const processHookCode = ({ str, options }) => (0, helpers_1.processBinding)((0, exports.updateStateSettersInCode)(str, options), options);
|
|
39
25
|
exports.processHookCode = processHookCode;
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
const valueMapper = (options) => (val) => {
|
|
27
|
+
const x = (0, exports.processHookCode)({ str: val, options });
|
|
42
28
|
return stripThisRefs(x, options);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
var key = _a[0], stateVal = _a[1];
|
|
29
|
+
};
|
|
30
|
+
const getSetStateFnName = (stateName) => `set${(0, capitalize_1.capitalize)(stateName)}`;
|
|
31
|
+
const processStateValue = (options) => {
|
|
32
|
+
const mapValue = valueMapper(options);
|
|
33
|
+
return ([key, stateVal]) => {
|
|
49
34
|
if (!stateVal) {
|
|
50
35
|
return '';
|
|
51
36
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var value = stateVal.code || '';
|
|
56
|
-
var type = stateVal.type;
|
|
37
|
+
const getDefaultCase = () => `const [${key}, ${getSetStateFnName(key)}] = useState(() => (${mapValue(value)}))`;
|
|
38
|
+
const value = stateVal.code || '';
|
|
39
|
+
const type = stateVal.type;
|
|
57
40
|
if (typeof value === 'string') {
|
|
58
41
|
switch (type) {
|
|
59
42
|
case 'getter':
|
|
@@ -71,39 +54,39 @@ var processStateValue = function (options) {
|
|
|
71
54
|
}
|
|
72
55
|
};
|
|
73
56
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
const getUseStateCode = (json, options) => {
|
|
58
|
+
const lineItemDelimiter = '\n\n\n';
|
|
59
|
+
const stringifiedState = Object.entries(json.state).map(processStateValue(options));
|
|
77
60
|
return stringifiedState.join(lineItemDelimiter);
|
|
78
61
|
};
|
|
79
62
|
exports.getUseStateCode = getUseStateCode;
|
|
80
|
-
|
|
63
|
+
const updateStateSetters = (json, options) => {
|
|
81
64
|
if (options.stateType !== 'useState') {
|
|
82
65
|
return;
|
|
83
66
|
}
|
|
84
67
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
85
68
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
86
|
-
for (
|
|
87
|
-
|
|
88
|
-
|
|
69
|
+
for (const key in item.bindings) {
|
|
70
|
+
let values = item.bindings[key];
|
|
71
|
+
const newValue = (0, exports.updateStateSettersInCode)(values === null || values === void 0 ? void 0 : values.code, options);
|
|
89
72
|
if (newValue !== (values === null || values === void 0 ? void 0 : values.code)) {
|
|
90
|
-
item.bindings[key] =
|
|
73
|
+
item.bindings[key] = {
|
|
74
|
+
...values,
|
|
75
|
+
code: newValue,
|
|
76
|
+
};
|
|
91
77
|
}
|
|
92
78
|
}
|
|
93
79
|
}
|
|
94
80
|
});
|
|
95
81
|
};
|
|
96
82
|
exports.updateStateSetters = updateStateSetters;
|
|
97
|
-
|
|
83
|
+
const updateStateSettersInCode = (value, options) => {
|
|
98
84
|
if (options.stateType !== 'useState') {
|
|
99
85
|
return value;
|
|
100
86
|
}
|
|
101
87
|
return (0, transform_state_setters_1.transformStateSetters)({
|
|
102
|
-
value
|
|
103
|
-
transformer:
|
|
104
|
-
var path = _a.path, propertyName = _a.propertyName;
|
|
105
|
-
return core_1.types.callExpression(core_1.types.identifier(getSetStateFnName(propertyName)), [path.node.right]);
|
|
106
|
-
},
|
|
88
|
+
value,
|
|
89
|
+
transformer: ({ path, propertyName }) => core_1.types.callExpression(core_1.types.identifier(getSetStateFnName(propertyName)), [path.node.right]),
|
|
107
90
|
});
|
|
108
91
|
};
|
|
109
92
|
exports.updateStateSettersInCode = updateStateSettersInCode;
|
|
@@ -1,69 +1,58 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.componentToReactNative = exports.collectReactNativeStyles = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
const bindings_1 = require("../../helpers/bindings");
|
|
8
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
9
|
+
const is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
10
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
11
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
12
|
+
const json5_1 = __importDefault(require("json5"));
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
15
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
16
|
+
const react_1 = require("../react");
|
|
17
|
+
const sanitize_react_native_block_styles_1 = require("./sanitize-react-native-block-styles");
|
|
18
|
+
const stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
|
|
19
|
+
const MEDIA_QUERY_KEY_REGEX = /^@media.*/;
|
|
20
|
+
const sanitizeStyle = (obj) => (key, value) => {
|
|
21
|
+
const propertyValue = obj[key];
|
|
33
22
|
if (key.match(MEDIA_QUERY_KEY_REGEX)) {
|
|
34
23
|
console.warn('Unsupported: skipping media queries for react-native: ', key, propertyValue);
|
|
35
24
|
delete obj[key];
|
|
36
25
|
return;
|
|
37
26
|
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
};
|
|
28
|
+
const collectReactNativeStyles = (json) => {
|
|
29
|
+
const styleMap = {};
|
|
30
|
+
const componentIndexes = {};
|
|
31
|
+
const getStyleSheetName = (item) => {
|
|
32
|
+
const componentName = (0, lodash_1.camelCase)(item.name || 'view');
|
|
44
33
|
// If we have already seen this component name, we will increment the index. Otherwise, we will set the index to 1.
|
|
45
|
-
|
|
46
|
-
return
|
|
34
|
+
const index = (componentIndexes[componentName] = (componentIndexes[componentName] || 0) + 1);
|
|
35
|
+
return `${componentName}${index}`;
|
|
47
36
|
};
|
|
48
37
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
49
38
|
var _a, _b, _c;
|
|
50
39
|
if (!(0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
51
40
|
return;
|
|
52
41
|
}
|
|
53
|
-
|
|
42
|
+
let cssValue = json5_1.default.parse(((_a = item.bindings.css) === null || _a === void 0 ? void 0 : _a.code) || '{}');
|
|
54
43
|
delete item.bindings.css;
|
|
55
44
|
if ((0, lodash_1.size)(cssValue)) {
|
|
56
45
|
// Style properties like `"20px"` need to be numbers like `20` for react native
|
|
57
|
-
for (
|
|
46
|
+
for (const key in cssValue) {
|
|
58
47
|
sanitizeStyle(cssValue)(key, cssValue[key]);
|
|
59
48
|
cssValue = (0, sanitize_react_native_block_styles_1.sanitizeReactNativeBlockStyles)(cssValue);
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
try {
|
|
63
|
-
|
|
52
|
+
let styleValue = json5_1.default.parse(((_b = item.bindings.style) === null || _b === void 0 ? void 0 : _b.code) || '{}');
|
|
64
53
|
if ((0, lodash_1.size)(styleValue)) {
|
|
65
54
|
// Style properties like `"20px"` need to be numbers like `20` for react native
|
|
66
|
-
for (
|
|
55
|
+
for (const key in styleValue) {
|
|
67
56
|
sanitizeStyle(styleValue)(key, styleValue[key]);
|
|
68
57
|
styleValue = (0, sanitize_react_native_block_styles_1.sanitizeReactNativeBlockStyles)(styleValue);
|
|
69
58
|
}
|
|
@@ -74,8 +63,8 @@ var collectReactNativeStyles = function (json) {
|
|
|
74
63
|
if (!(0, lodash_1.size)(cssValue)) {
|
|
75
64
|
return;
|
|
76
65
|
}
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
const styleSheetName = getStyleSheetName(item);
|
|
67
|
+
const styleSheetAccess = `styles.${styleSheetName}`;
|
|
79
68
|
styleMap[styleSheetName] = cssValue;
|
|
80
69
|
if (!item.bindings.style) {
|
|
81
70
|
item.bindings.style = (0, bindings_1.createSingleBinding)({
|
|
@@ -87,13 +76,16 @@ var collectReactNativeStyles = function (json) {
|
|
|
87
76
|
// run the code below only if the style binding is a JSON object
|
|
88
77
|
json5_1.default.parse(item.bindings.style.code || '{}');
|
|
89
78
|
item.bindings.style = (0, bindings_1.createSingleBinding)({
|
|
90
|
-
code: ((_c = item.bindings.style) === null || _c === void 0 ? void 0 : _c.code.replace(/}$/,
|
|
79
|
+
code: ((_c = item.bindings.style) === null || _c === void 0 ? void 0 : _c.code.replace(/}$/, `, ...${styleSheetAccess} }`)) || styleSheetAccess,
|
|
91
80
|
});
|
|
92
81
|
}
|
|
93
82
|
catch (e) {
|
|
94
83
|
// if not a JSON, then it's a property, so we should spread it.
|
|
95
84
|
item.bindings.style = (0, bindings_1.createSingleBinding)({
|
|
96
|
-
code:
|
|
85
|
+
code: `{
|
|
86
|
+
...${styleSheetAccess},
|
|
87
|
+
...${item.bindings.style.code}
|
|
88
|
+
}`,
|
|
97
89
|
});
|
|
98
90
|
}
|
|
99
91
|
});
|
|
@@ -104,14 +96,14 @@ exports.collectReactNativeStyles = collectReactNativeStyles;
|
|
|
104
96
|
* Plugin that handles necessary transformations from React to React Native:
|
|
105
97
|
* - Converts DOM tags to <View /> and <Text />
|
|
106
98
|
*/
|
|
107
|
-
|
|
99
|
+
const PROCESS_REACT_NATIVE_PLUGIN = () => ({
|
|
108
100
|
json: {
|
|
109
|
-
pre:
|
|
110
|
-
(0, legacy_1.default)(json).forEach(
|
|
101
|
+
pre: (json) => {
|
|
102
|
+
(0, legacy_1.default)(json).forEach((node) => {
|
|
111
103
|
var _a, _b, _c, _d;
|
|
112
104
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
113
105
|
// TODO: handle TextInput, Image, etc
|
|
114
|
-
if ((0, is_children_1.default)({ node
|
|
106
|
+
if ((0, is_children_1.default)({ node })) {
|
|
115
107
|
node.name = '';
|
|
116
108
|
}
|
|
117
109
|
else if (node.name.toLowerCase() === node.name && html_tags_1.VALID_HTML_TAGS.includes(node.name)) {
|
|
@@ -143,13 +135,13 @@ var PROCESS_REACT_NATIVE_PLUGIN = function () { return ({
|
|
|
143
135
|
});
|
|
144
136
|
},
|
|
145
137
|
},
|
|
146
|
-
});
|
|
138
|
+
});
|
|
147
139
|
/**
|
|
148
140
|
* Removes React Native className and class properties from the JSON
|
|
149
141
|
*/
|
|
150
|
-
|
|
142
|
+
const REMOVE_REACT_NATIVE_CLASSES_PLUGIN = () => ({
|
|
151
143
|
json: {
|
|
152
|
-
pre:
|
|
144
|
+
pre: (json) => {
|
|
153
145
|
(0, legacy_1.default)(json).forEach(function (node) {
|
|
154
146
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
155
147
|
if (node.properties.class) {
|
|
@@ -168,41 +160,41 @@ var REMOVE_REACT_NATIVE_CLASSES_PLUGIN = function () { return ({
|
|
|
168
160
|
});
|
|
169
161
|
},
|
|
170
162
|
},
|
|
171
|
-
});
|
|
163
|
+
});
|
|
172
164
|
/**
|
|
173
165
|
* Converts class and className properties to twrnc style syntax
|
|
174
166
|
*/
|
|
175
|
-
|
|
167
|
+
const TWRNC_STYLES_PLUGIN = () => ({
|
|
176
168
|
json: {
|
|
177
|
-
post:
|
|
169
|
+
post: (json) => {
|
|
178
170
|
(0, legacy_1.default)(json).forEach(function (node) {
|
|
179
171
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
180
|
-
|
|
172
|
+
let staticClasses = [node.properties.class, node.properties.className]
|
|
181
173
|
.filter(Boolean)
|
|
182
174
|
.join(' ');
|
|
183
|
-
|
|
175
|
+
let dynamicClasses = [node.bindings.class, node.bindings.className].filter(Boolean);
|
|
184
176
|
if (staticClasses || dynamicClasses.length) {
|
|
185
|
-
|
|
177
|
+
let styleCode = '';
|
|
186
178
|
if (staticClasses) {
|
|
187
|
-
styleCode =
|
|
179
|
+
styleCode = `tw\`${staticClasses}\``;
|
|
188
180
|
}
|
|
189
181
|
if (dynamicClasses.length) {
|
|
190
|
-
|
|
191
|
-
.map(
|
|
182
|
+
let dynamicCode = dynamicClasses
|
|
183
|
+
.map((dc) => (dc && dc.code ? dc.code : null))
|
|
192
184
|
.filter(Boolean)
|
|
193
185
|
.join(', ');
|
|
194
186
|
if (dynamicCode) {
|
|
195
187
|
if (styleCode) {
|
|
196
188
|
// If we have both static and dynamic classes
|
|
197
|
-
styleCode =
|
|
189
|
+
styleCode = `tw.style(${styleCode}, ${dynamicCode})`;
|
|
198
190
|
}
|
|
199
191
|
else if (dynamicClasses.length > 1) {
|
|
200
192
|
// If we have multiple dynamic classes
|
|
201
|
-
styleCode =
|
|
193
|
+
styleCode = `tw.style([${dynamicCode}])`;
|
|
202
194
|
}
|
|
203
195
|
else {
|
|
204
196
|
// If we have a single dynamic class
|
|
205
|
-
styleCode =
|
|
197
|
+
styleCode = `tw.style(${dynamicCode})`;
|
|
206
198
|
}
|
|
207
199
|
}
|
|
208
200
|
}
|
|
@@ -219,17 +211,17 @@ var TWRNC_STYLES_PLUGIN = function () { return ({
|
|
|
219
211
|
});
|
|
220
212
|
},
|
|
221
213
|
},
|
|
222
|
-
});
|
|
214
|
+
});
|
|
223
215
|
/**
|
|
224
216
|
* Converts class and className properties to native-wind style syntax
|
|
225
217
|
* Note: We only support the "with babel" setup: https://www.nativewind.dev/guides/babel
|
|
226
218
|
*/
|
|
227
|
-
|
|
219
|
+
const NATIVE_WIND_STYLES_PLUGIN = () => ({
|
|
228
220
|
json: {
|
|
229
|
-
post:
|
|
221
|
+
post: (json) => {
|
|
230
222
|
(0, legacy_1.default)(json).forEach(function (node) {
|
|
231
223
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
232
|
-
|
|
224
|
+
let combinedClasses = [
|
|
233
225
|
node.properties.class,
|
|
234
226
|
node.properties.className,
|
|
235
227
|
node.bindings.class,
|
|
@@ -256,28 +248,24 @@ var NATIVE_WIND_STYLES_PLUGIN = function () { return ({
|
|
|
256
248
|
});
|
|
257
249
|
},
|
|
258
250
|
},
|
|
259
|
-
});
|
|
260
|
-
|
|
251
|
+
});
|
|
252
|
+
const DEFAULT_OPTIONS = {
|
|
261
253
|
stateType: 'useState',
|
|
262
254
|
stylesType: 'react-native',
|
|
263
255
|
plugins: [PROCESS_REACT_NATIVE_PLUGIN],
|
|
264
256
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
options.plugins.push(REMOVE_REACT_NATIVE_CLASSES_PLUGIN);
|
|
279
|
-
}
|
|
280
|
-
return (0, react_1.componentToReact)(__assign(__assign({}, options), { type: 'native' }))({ component: json, path: path });
|
|
281
|
-
};
|
|
257
|
+
const componentToReactNative = (_options = {}) => ({ component, path }) => {
|
|
258
|
+
const json = (0, fast_clone_1.fastClone)(component);
|
|
259
|
+
const options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, _options);
|
|
260
|
+
if (options.stylesType === 'twrnc') {
|
|
261
|
+
options.plugins.push(TWRNC_STYLES_PLUGIN);
|
|
262
|
+
}
|
|
263
|
+
else if (options.stylesType === 'native-wind') {
|
|
264
|
+
options.plugins.push(NATIVE_WIND_STYLES_PLUGIN);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
options.plugins.push(REMOVE_REACT_NATIVE_CLASSES_PLUGIN);
|
|
268
|
+
}
|
|
269
|
+
return (0, react_1.componentToReact)({ ...options, type: 'native' })({ component: json, path });
|
|
282
270
|
};
|
|
283
271
|
exports.componentToReactNative = componentToReactNative;
|
|
@@ -1,20 +1,9 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.sanitizeReactNativeBlockStyles = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const propertiesThatMustBeNumber = new Set(['lineHeight']);
|
|
5
|
+
const displayValues = new Set(['flex', 'none']);
|
|
6
|
+
const normalizeNumber = (value) => {
|
|
18
7
|
if (Number.isNaN(value)) {
|
|
19
8
|
return undefined;
|
|
20
9
|
}
|
|
@@ -26,27 +15,26 @@ var normalizeNumber = function (value) {
|
|
|
26
15
|
return value;
|
|
27
16
|
}
|
|
28
17
|
};
|
|
29
|
-
|
|
30
|
-
return Object.keys(styles).reduce(
|
|
31
|
-
|
|
32
|
-
var propertyValue = styles[key];
|
|
18
|
+
const sanitizeReactNativeBlockStyles = (styles) => {
|
|
19
|
+
return Object.keys(styles).reduce((acc, key) => {
|
|
20
|
+
const propertyValue = styles[key];
|
|
33
21
|
if (key === 'display' && !displayValues.has(propertyValue)) {
|
|
34
|
-
console.warn(
|
|
22
|
+
console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
|
|
35
23
|
return acc;
|
|
36
24
|
}
|
|
37
25
|
if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
|
|
38
|
-
console.warn(
|
|
26
|
+
console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
|
|
39
27
|
return acc;
|
|
40
28
|
}
|
|
41
29
|
if (typeof propertyValue === 'string') {
|
|
42
30
|
// `px` units need to be stripped and replaced with numbers
|
|
43
31
|
// https://regexr.com/6ualn
|
|
44
|
-
|
|
32
|
+
const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
|
|
45
33
|
if (isPixelUnit) {
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
const newValue = parseFloat(propertyValue);
|
|
35
|
+
const normalizedValue = normalizeNumber(newValue);
|
|
48
36
|
if (normalizedValue) {
|
|
49
|
-
return
|
|
37
|
+
return { ...acc, [key]: normalizedValue };
|
|
50
38
|
}
|
|
51
39
|
else {
|
|
52
40
|
return acc;
|
|
@@ -54,10 +42,10 @@ var sanitizeReactNativeBlockStyles = function (styles) {
|
|
|
54
42
|
}
|
|
55
43
|
else if (propertyValue === '0') {
|
|
56
44
|
// 0 edge case needs to be handled
|
|
57
|
-
return
|
|
45
|
+
return { ...acc, [key]: 0 };
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
|
-
return
|
|
48
|
+
return { ...acc, [key]: propertyValue };
|
|
61
49
|
}, {});
|
|
62
50
|
};
|
|
63
51
|
exports.sanitizeReactNativeBlockStyles = sanitizeReactNativeBlockStyles;
|