@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,19 +1,10 @@
|
|
|
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.renderHandlers = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
const component_1 = require("../component");
|
|
5
|
+
const src_generator_1 = require("../src-generator");
|
|
6
|
+
const IIF_START = '(() => {';
|
|
7
|
+
const IIF_END = '})()';
|
|
17
8
|
function extractJSBlock(binding) {
|
|
18
9
|
if (typeof binding == 'string') {
|
|
19
10
|
if (binding.startsWith('{') &&
|
|
@@ -29,33 +20,33 @@ function extractJSBlock(binding) {
|
|
|
29
20
|
return null;
|
|
30
21
|
}
|
|
31
22
|
function renderHandlers(file, componentName, children) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
let id = 0;
|
|
24
|
+
const map = new Map();
|
|
25
|
+
const nodes = [...children];
|
|
35
26
|
while (nodes.length) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (
|
|
27
|
+
const node = nodes.shift();
|
|
28
|
+
const bindings = node.bindings;
|
|
29
|
+
for (const key in bindings) {
|
|
39
30
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
40
|
-
|
|
31
|
+
const { code: binding } = bindings[key];
|
|
41
32
|
if (binding != null) {
|
|
42
33
|
if (isEventName(key)) {
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
let block = extractJSBlock(binding) || binding;
|
|
35
|
+
const symbol = `${componentName}_${key}_${id++}`;
|
|
45
36
|
map.set(binding, symbol);
|
|
46
37
|
renderHandler(file, symbol, block);
|
|
47
38
|
}
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
41
|
}
|
|
51
|
-
nodes.push
|
|
42
|
+
nodes.push(...node.children);
|
|
52
43
|
}
|
|
53
44
|
return map;
|
|
54
45
|
}
|
|
55
46
|
exports.renderHandlers = renderHandlers;
|
|
56
47
|
function renderHandler(file, symbol, code) {
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
const body = [code];
|
|
49
|
+
const shouldRenderStateRestore = code.indexOf('state') !== -1;
|
|
59
50
|
if (shouldRenderStateRestore) {
|
|
60
51
|
body.unshift((0, component_1.renderUseLexicalScope)(file));
|
|
61
52
|
}
|
|
@@ -6,7 +6,7 @@ exports.stableInject = void 0;
|
|
|
6
6
|
* This is needed for our `MitosisState` values which are JS expressions stored as strings.
|
|
7
7
|
*/
|
|
8
8
|
function stableInject(obj) {
|
|
9
|
-
|
|
9
|
+
const output = [];
|
|
10
10
|
_serialize(output, obj);
|
|
11
11
|
return output.join('');
|
|
12
12
|
}
|
|
@@ -18,8 +18,8 @@ function _serialize(output, obj) {
|
|
|
18
18
|
else if (typeof obj === 'object') {
|
|
19
19
|
if (Array.isArray(obj)) {
|
|
20
20
|
output.push('[');
|
|
21
|
-
|
|
22
|
-
for (
|
|
21
|
+
let sep = '';
|
|
22
|
+
for (let i = 0; i < obj.length; i++) {
|
|
23
23
|
output.push(sep);
|
|
24
24
|
_serialize(output, obj[i]);
|
|
25
25
|
sep = ',';
|
|
@@ -27,12 +27,11 @@ function _serialize(output, obj) {
|
|
|
27
27
|
output.push(']');
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
|
|
30
|
+
const keys = Object.keys(obj).sort();
|
|
31
31
|
output.push('{');
|
|
32
|
-
|
|
33
|
-
for (
|
|
34
|
-
|
|
35
|
-
var value = obj[key];
|
|
32
|
+
let sep = '';
|
|
33
|
+
for (const key of keys) {
|
|
34
|
+
const value = obj[key];
|
|
36
35
|
if (value !== undefined) {
|
|
37
36
|
output.push(sep);
|
|
38
37
|
output.push(JSON.stringify(key));
|
|
@@ -7,7 +7,7 @@ exports.stableJSONserialize = void 0;
|
|
|
7
7
|
* @returns JSON serialized string
|
|
8
8
|
*/
|
|
9
9
|
function stableJSONserialize(obj) {
|
|
10
|
-
|
|
10
|
+
const output = [];
|
|
11
11
|
_serialize(output, obj);
|
|
12
12
|
return output.join('');
|
|
13
13
|
}
|
|
@@ -19,8 +19,8 @@ function _serialize(output, obj) {
|
|
|
19
19
|
else if (typeof obj === 'object') {
|
|
20
20
|
if (Array.isArray(obj)) {
|
|
21
21
|
output.push('[');
|
|
22
|
-
|
|
23
|
-
for (
|
|
22
|
+
let sep = '';
|
|
23
|
+
for (let i = 0; i < obj.length; i++) {
|
|
24
24
|
output.push(sep);
|
|
25
25
|
_serialize(output, obj[i]);
|
|
26
26
|
sep = ',';
|
|
@@ -28,12 +28,11 @@ function _serialize(output, obj) {
|
|
|
28
28
|
output.push(']');
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
|
|
31
|
+
const keys = Object.keys(obj).sort();
|
|
32
32
|
output.push('{');
|
|
33
|
-
|
|
34
|
-
for (
|
|
35
|
-
|
|
36
|
-
var value = obj[key];
|
|
33
|
+
let sep = '';
|
|
34
|
+
for (const key of keys) {
|
|
35
|
+
const value = obj[key];
|
|
37
36
|
if (value !== undefined) {
|
|
38
37
|
output.push(sep);
|
|
39
38
|
output.push(JSON.stringify(key));
|
|
@@ -1,61 +1,51 @@
|
|
|
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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.getStateMethodsAndGetters = exports.getLexicalScopeVars = exports.emitStateMethodsAndRewriteBindings = exports.emitUseStore = void 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const babel_transform_1 = require("../../../helpers/babel-transform");
|
|
9
|
+
const convert_method_to_function_1 = require("./convert-method-to-function");
|
|
10
|
+
const stable_inject_1 = require("./stable-inject");
|
|
20
11
|
/**
|
|
21
12
|
* @param file
|
|
22
13
|
* @param stateInit
|
|
23
14
|
*/
|
|
24
|
-
function emitUseStore(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var hasState = state && Object.keys(state).length > 0;
|
|
15
|
+
function emitUseStore({ file, stateInit, isDeep, }) {
|
|
16
|
+
const state = stateInit[0];
|
|
17
|
+
const hasState = state && Object.keys(state).length > 0;
|
|
28
18
|
if (hasState) {
|
|
29
19
|
file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName);
|
|
30
20
|
if (file.options.isTypeScript) {
|
|
31
21
|
file.src.emit('<any>');
|
|
32
22
|
}
|
|
33
|
-
|
|
34
|
-
file.src.emit(
|
|
23
|
+
const fnArgs = [(0, stable_inject_1.stableInject)(state), isDeep ? '{deep: true}' : undefined].filter(Boolean);
|
|
24
|
+
file.src.emit(`(${fnArgs});`);
|
|
35
25
|
}
|
|
36
26
|
else {
|
|
37
27
|
// TODO hack for now so that `state` variable is defined, even though it is never read.
|
|
38
|
-
file.src.emit(
|
|
28
|
+
file.src.emit(`const state${file.options.isTypeScript ? ': any' : ''} = {};`);
|
|
39
29
|
}
|
|
40
30
|
}
|
|
41
31
|
exports.emitUseStore = emitUseStore;
|
|
42
32
|
function emitStateMethods(file, componentState, lexicalArgs) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
for (
|
|
47
|
-
|
|
33
|
+
const stateValues = {};
|
|
34
|
+
const stateInit = [stateValues];
|
|
35
|
+
const methodMap = getStateMethodsAndGetters(componentState);
|
|
36
|
+
for (const key in componentState) {
|
|
37
|
+
const stateValue = componentState[key];
|
|
48
38
|
switch (stateValue === null || stateValue === void 0 ? void 0 : stateValue.type) {
|
|
49
39
|
case 'method':
|
|
50
40
|
case 'function':
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
let code = stateValue.code;
|
|
42
|
+
let prefixIdx = 0;
|
|
53
43
|
if (stateValue.type === 'function') {
|
|
54
44
|
prefixIdx += 'function '.length;
|
|
55
45
|
}
|
|
56
46
|
code = code.substring(prefixIdx);
|
|
57
|
-
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(',
|
|
58
|
-
|
|
47
|
+
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', `(${lexicalArgs.join(',')},`);
|
|
48
|
+
const functionName = code.split(/\(/)[0];
|
|
59
49
|
if (!file.options.isTypeScript) {
|
|
60
50
|
// Erase type information
|
|
61
51
|
code = (0, babel_transform_1.convertTypeScriptToJS)(code);
|
|
@@ -71,41 +61,44 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
71
61
|
}
|
|
72
62
|
function emitStateMethodsAndRewriteBindings(file, component, metadata) {
|
|
73
63
|
var _a;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
const lexicalArgs = getLexicalScopeVars(component);
|
|
65
|
+
const state = emitStateMethods(file, component.state, lexicalArgs);
|
|
66
|
+
const methodMap = getStateMethodsAndGetters(component.state);
|
|
77
67
|
rewriteCodeExpr(component, methodMap, lexicalArgs, (_a = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _a === void 0 ? void 0 : _a.replace);
|
|
78
68
|
return state;
|
|
79
69
|
}
|
|
80
70
|
exports.emitStateMethodsAndRewriteBindings = emitStateMethodsAndRewriteBindings;
|
|
81
|
-
|
|
71
|
+
const checkIsObjectWithCodeBlock = (obj) => {
|
|
82
72
|
return typeof obj == 'object' && (obj === null || obj === void 0 ? void 0 : obj.code) && typeof obj.code === 'string';
|
|
83
73
|
};
|
|
84
74
|
function getLexicalScopeVars(component) {
|
|
85
|
-
|
|
75
|
+
const newLocal = [
|
|
86
76
|
'props',
|
|
87
|
-
'state'
|
|
88
|
-
|
|
77
|
+
'state',
|
|
78
|
+
// all `useComputed` values
|
|
79
|
+
...Object.keys(component.state).filter((k) => component.state[k].type === 'getter'),
|
|
80
|
+
...Object.keys(component.refs),
|
|
81
|
+
...Object.keys(component.context.get),
|
|
82
|
+
];
|
|
89
83
|
return newLocal;
|
|
90
84
|
}
|
|
91
85
|
exports.getLexicalScopeVars = getLexicalScopeVars;
|
|
92
|
-
function rewriteCodeExpr(component, methodMap, lexicalArgs, replace) {
|
|
93
|
-
if (replace === void 0) { replace = {}; }
|
|
86
|
+
function rewriteCodeExpr(component, methodMap, lexicalArgs, replace = {}) {
|
|
94
87
|
(0, legacy_1.default)(component).forEach(function (item) {
|
|
95
88
|
if (!checkIsObjectWithCodeBlock(item)) {
|
|
96
89
|
return;
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
Object.keys(replace).forEach(
|
|
91
|
+
let code = (0, convert_method_to_function_1.convertMethodToFunction)(item.code, methodMap, lexicalArgs);
|
|
92
|
+
Object.keys(replace).forEach((key) => {
|
|
100
93
|
code = code.replace(key, replace[key]);
|
|
101
94
|
});
|
|
102
95
|
item.code = code;
|
|
103
96
|
});
|
|
104
97
|
}
|
|
105
98
|
function getStateMethodsAndGetters(state) {
|
|
106
|
-
|
|
107
|
-
Object.keys(state).forEach(
|
|
108
|
-
|
|
99
|
+
const methodMap = {};
|
|
100
|
+
Object.keys(state).forEach((key) => {
|
|
101
|
+
const stateVal = state[key];
|
|
109
102
|
if ((stateVal === null || stateVal === void 0 ? void 0 : stateVal.type) === 'getter' || (stateVal === null || stateVal === void 0 ? void 0 : stateVal.type) === 'method') {
|
|
110
103
|
methodMap[key] = stateVal.type;
|
|
111
104
|
}
|
|
@@ -1,40 +1,20 @@
|
|
|
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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.renderStyles = exports.collectStyles = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
const json5_1 = __importDefault(require("json5"));
|
|
8
|
+
const dash_case_1 = require("../../../helpers/dash-case");
|
|
29
9
|
function collectStyles(children, styleMap) {
|
|
30
10
|
var _a;
|
|
31
|
-
|
|
11
|
+
const nodes = [...children];
|
|
32
12
|
while (nodes.length) {
|
|
33
|
-
|
|
34
|
-
nodes.push
|
|
35
|
-
|
|
13
|
+
const child = nodes.shift();
|
|
14
|
+
nodes.push(...child.children);
|
|
15
|
+
const css = (_a = child.bindings.css) === null || _a === void 0 ? void 0 : _a.code;
|
|
36
16
|
if (css && typeof css == 'string') {
|
|
37
|
-
|
|
17
|
+
const value = { CLASS_NAME: 'c' + hashCode(css), ...json5_1.default.parse(css) };
|
|
38
18
|
styleMap.set(css, value);
|
|
39
19
|
}
|
|
40
20
|
}
|
|
@@ -54,32 +34,31 @@ function hashCode(text) {
|
|
|
54
34
|
}
|
|
55
35
|
function renderStyles(styles) {
|
|
56
36
|
return function () {
|
|
57
|
-
var _this = this;
|
|
58
37
|
this.emit('`');
|
|
59
|
-
|
|
60
|
-
styles.forEach(
|
|
61
|
-
|
|
62
|
-
for (
|
|
38
|
+
const mediaStyles = [];
|
|
39
|
+
styles.forEach((styles) => {
|
|
40
|
+
this.emit('.', styles.CLASS_NAME, /*'.🏷️�', WS,*/ '{');
|
|
41
|
+
for (const key in styles) {
|
|
63
42
|
if (key !== 'CLASS_NAME' && Object.prototype.hasOwnProperty.call(styles, key)) {
|
|
64
|
-
|
|
43
|
+
const value = styles[key];
|
|
65
44
|
if (value && typeof value == 'object') {
|
|
66
45
|
mediaStyles.push(styles.CLASS_NAME, key, value);
|
|
67
46
|
}
|
|
68
47
|
else {
|
|
69
|
-
|
|
48
|
+
this.emit((0, dash_case_1.dashCase)(key), ':', value, ';');
|
|
70
49
|
}
|
|
71
50
|
}
|
|
72
51
|
}
|
|
73
|
-
|
|
52
|
+
this.emit('}');
|
|
74
53
|
});
|
|
75
54
|
while (mediaStyles.length) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
const className = mediaStyles.shift();
|
|
56
|
+
const mediaKey = mediaStyles.shift();
|
|
57
|
+
const mediaObj = mediaStyles.shift();
|
|
79
58
|
this.emit(mediaKey, '{.', className, /*'.🏷️�',*/ '{');
|
|
80
|
-
for (
|
|
59
|
+
for (const key in mediaObj) {
|
|
81
60
|
if (Object.prototype.hasOwnProperty.call(mediaObj, key)) {
|
|
82
|
-
|
|
61
|
+
const value = mediaObj[key];
|
|
83
62
|
this.emit((0, dash_case_1.dashCase)(key), ':', value, ';');
|
|
84
63
|
}
|
|
85
64
|
}
|
|
@@ -1,29 +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
|
-
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.renderJSXNodes = void 0;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
5
|
+
const directives_1 = require("./directives");
|
|
6
|
+
const src_generator_1 = require("./src-generator");
|
|
27
7
|
/**
|
|
28
8
|
* Convert a Mitosis nodes to a JSX nodes.
|
|
29
9
|
*
|
|
@@ -37,61 +17,59 @@ var src_generator_1 = require("./src-generator");
|
|
|
37
17
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
38
18
|
* @returns
|
|
39
19
|
*/
|
|
40
|
-
function renderJSXNodes(file, directives, handlers, children, styles, key, parentSymbolBindings, root) {
|
|
41
|
-
if (root === void 0) { root = true; }
|
|
20
|
+
function renderJSXNodes(file, directives, handlers, children, styles, key, parentSymbolBindings, root = true) {
|
|
42
21
|
return function () {
|
|
43
|
-
|
|
44
|
-
var srcBuilder = this;
|
|
22
|
+
const srcBuilder = this;
|
|
45
23
|
if (children.length == 0)
|
|
46
24
|
return;
|
|
47
25
|
if (root)
|
|
48
26
|
this.emit('(');
|
|
49
|
-
|
|
27
|
+
const needsFragment = root &&
|
|
50
28
|
(children.length > 1 ||
|
|
51
29
|
(children.length && (isInlinedDirective(children[0]) || isTextNode(children[0]))));
|
|
52
30
|
file.import(file.qwikModule, 'h');
|
|
53
|
-
|
|
31
|
+
const fragmentSymbol = file.import(file.qwikModule, 'Fragment');
|
|
54
32
|
if (needsFragment) {
|
|
55
33
|
this.jsxBeginFragment(fragmentSymbol);
|
|
56
34
|
}
|
|
57
|
-
children.forEach(
|
|
35
|
+
children.forEach((child) => {
|
|
58
36
|
var _a, _b;
|
|
59
37
|
if (isEmptyTextNode(child))
|
|
60
38
|
return;
|
|
61
39
|
if (isTextNode(child)) {
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
const text = child.properties._text;
|
|
41
|
+
const textExpr = (_a = child.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
|
|
64
42
|
if (typeof text == 'string') {
|
|
65
|
-
|
|
43
|
+
this.isJSX ? this.emit(text) : this.jsxTextBinding((0, src_generator_1.quote)(text));
|
|
66
44
|
}
|
|
67
45
|
else if (typeof textExpr == 'string') {
|
|
68
|
-
|
|
46
|
+
this.isJSX ? this.emit('{', textExpr, '}') : this.jsxTextBinding(textExpr);
|
|
69
47
|
}
|
|
70
48
|
}
|
|
71
49
|
else if (isSlotProjection(child)) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
this.file.import(this.file.qwikModule, 'Slot');
|
|
51
|
+
this.jsxBegin('Slot', {}, {});
|
|
52
|
+
this.jsxEnd('Slot');
|
|
75
53
|
}
|
|
76
54
|
else {
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
let childName = child.name;
|
|
56
|
+
const directive = directives_1.DIRECTIVES[childName];
|
|
79
57
|
if (typeof directive == 'function') {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
Object.keys(
|
|
83
|
-
|
|
58
|
+
const blockFn = mitosisNodeToRenderBlock(child.children);
|
|
59
|
+
const meta = child.meta;
|
|
60
|
+
Object.keys(meta).forEach((key) => {
|
|
61
|
+
const value = meta[key];
|
|
84
62
|
if ((0, is_mitosis_node_1.isMitosisNode)(value)) {
|
|
85
|
-
|
|
63
|
+
blockFn[key] = mitosisNodeToRenderBlock([value]);
|
|
86
64
|
}
|
|
87
65
|
});
|
|
88
|
-
|
|
89
|
-
!
|
|
66
|
+
this.emit(directive(child, blockFn));
|
|
67
|
+
!this.isJSX && this.emit(',');
|
|
90
68
|
includedHelperDirectives(directive.toString(), directives);
|
|
91
69
|
}
|
|
92
70
|
else {
|
|
93
71
|
if (childName === 'Slot') {
|
|
94
|
-
|
|
72
|
+
this.file.import(this.file.qwikModule, 'Slot');
|
|
95
73
|
}
|
|
96
74
|
else {
|
|
97
75
|
if (typeof directive == 'string') {
|
|
@@ -104,19 +82,19 @@ function renderJSXNodes(file, directives, handlers, children, styles, key, paren
|
|
|
104
82
|
if (isSymbol(childName)) {
|
|
105
83
|
// TODO(misko): We are hard coding './med.js' which is not right.
|
|
106
84
|
!file.imports.hasImport(childName) && file.import('./med.js', childName);
|
|
107
|
-
|
|
85
|
+
let exportedChildName = file.exports.get(childName);
|
|
108
86
|
if (exportedChildName) {
|
|
109
87
|
childName = exportedChildName;
|
|
110
88
|
}
|
|
111
89
|
}
|
|
112
90
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
let props = child.properties;
|
|
92
|
+
const css = (_b = child.bindings.css) === null || _b === void 0 ? void 0 : _b.code;
|
|
93
|
+
const specialBindings = {};
|
|
116
94
|
if (css) {
|
|
117
|
-
props =
|
|
118
|
-
|
|
119
|
-
|
|
95
|
+
props = { ...props };
|
|
96
|
+
const styleProps = styles.get(css);
|
|
97
|
+
const imageMaxWidth = childName == 'Image' && styleProps.maxWidth;
|
|
120
98
|
if (imageMaxWidth && imageMaxWidth.endsWith('px')) {
|
|
121
99
|
// special case for Images. We want to make sure that we include the maxWidth in a srcset
|
|
122
100
|
specialBindings.srcsetSizes = Number.parseInt(imageMaxWidth);
|
|
@@ -128,13 +106,20 @@ function renderJSXNodes(file, directives, handlers, children, styles, key, paren
|
|
|
128
106
|
key = props['builder-id'] || key;
|
|
129
107
|
if (props.innerHTML) {
|
|
130
108
|
// Special case. innerHTML requires `key` in Qwik
|
|
131
|
-
props =
|
|
109
|
+
props = {
|
|
110
|
+
key: key || 'default',
|
|
111
|
+
...props,
|
|
112
|
+
};
|
|
132
113
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
114
|
+
const symbolBindings = {};
|
|
115
|
+
const bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
|
|
116
|
+
this.jsxBegin(childName, props, {
|
|
117
|
+
...bindings,
|
|
118
|
+
...parentSymbolBindings,
|
|
119
|
+
...specialBindings,
|
|
120
|
+
});
|
|
121
|
+
renderJSXNodes(file, directives, handlers, child.children, styles, key, symbolBindings, false).call(this);
|
|
122
|
+
this.jsxEnd(childName);
|
|
138
123
|
}
|
|
139
124
|
}
|
|
140
125
|
});
|
|
@@ -144,9 +129,9 @@ function renderJSXNodes(file, directives, handlers, children, styles, key, paren
|
|
|
144
129
|
if (root)
|
|
145
130
|
this.emit(')');
|
|
146
131
|
function mitosisNodeToRenderBlock(children) {
|
|
147
|
-
return
|
|
148
|
-
children = children.filter(
|
|
149
|
-
|
|
132
|
+
return () => {
|
|
133
|
+
children = children.filter((c) => !isEmptyTextNode(c));
|
|
134
|
+
const childNeedsFragment = children.length > 1 || (children.length && isTextNode(children[0]));
|
|
150
135
|
childNeedsFragment && srcBuilder.jsxBeginFragment(fragmentSymbol);
|
|
151
136
|
renderJSXNodes(file, directives, handlers, children, styles, null, {}, false).call(srcBuilder);
|
|
152
137
|
childNeedsFragment && srcBuilder.jsxEndFragment();
|
|
@@ -156,9 +141,9 @@ function renderJSXNodes(file, directives, handlers, children, styles, key, paren
|
|
|
156
141
|
}
|
|
157
142
|
exports.renderJSXNodes = renderJSXNodes;
|
|
158
143
|
function includedHelperDirectives(directive, directives) {
|
|
159
|
-
Array.from(directive.matchAll(/(__[\w]+__)/g)).forEach(
|
|
160
|
-
|
|
161
|
-
|
|
144
|
+
Array.from(directive.matchAll(/(__[\w]+__)/g)).forEach((match) => {
|
|
145
|
+
const name = match[0];
|
|
146
|
+
const code = directives_1.DIRECTIVES[name];
|
|
162
147
|
typeof code == 'string' && directives.set(name, code);
|
|
163
148
|
});
|
|
164
149
|
}
|
|
@@ -168,7 +153,7 @@ function isSymbol(name) {
|
|
|
168
153
|
!name.includes('.'));
|
|
169
154
|
}
|
|
170
155
|
function addClass(className, existingClass) {
|
|
171
|
-
return
|
|
156
|
+
return [className, ...(existingClass ? existingClass.split(' ') : [])].join(' ');
|
|
172
157
|
}
|
|
173
158
|
function isEmptyTextNode(child) {
|
|
174
159
|
var _a;
|
|
@@ -179,7 +164,7 @@ function isTextNode(child) {
|
|
|
179
164
|
if (child.properties._text !== undefined) {
|
|
180
165
|
return true;
|
|
181
166
|
}
|
|
182
|
-
|
|
167
|
+
const code = (_a = child.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
|
|
183
168
|
if (code !== undefined && code !== 'props.children') {
|
|
184
169
|
return true;
|
|
185
170
|
}
|
|
@@ -202,17 +187,17 @@ function isSlotProjection(child) {
|
|
|
202
187
|
* @returns
|
|
203
188
|
*/
|
|
204
189
|
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
205
|
-
|
|
206
|
-
for (
|
|
190
|
+
const outBindings = {};
|
|
191
|
+
for (let key in bindings) {
|
|
207
192
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
193
|
+
const bindingValue = bindings[key];
|
|
194
|
+
let bindingExpr = bindingValue.code;
|
|
195
|
+
const handlerBlock = handlers.get(bindingExpr);
|
|
211
196
|
if (key == 'css') {
|
|
212
197
|
continue;
|
|
213
198
|
}
|
|
214
199
|
else if (handlerBlock) {
|
|
215
|
-
key =
|
|
200
|
+
key = `${key}$`;
|
|
216
201
|
bindingExpr = (0, src_generator_1.invoke)(file.import(file.qwikModule, 'qrl'), [
|
|
217
202
|
(0, src_generator_1.quote)(file.qrlPrefix + 'high.js'),
|
|
218
203
|
(0, src_generator_1.quote)(handlerBlock),
|
|
@@ -225,7 +210,10 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
|
225
210
|
else if (key.startsWith('component.options.')) {
|
|
226
211
|
key = (0, src_generator_1.lastProperty)(key);
|
|
227
212
|
}
|
|
228
|
-
outBindings[key] =
|
|
213
|
+
outBindings[key] = {
|
|
214
|
+
...bindingValue,
|
|
215
|
+
code: bindingExpr,
|
|
216
|
+
};
|
|
229
217
|
}
|
|
230
218
|
}
|
|
231
219
|
return outBindings;
|