@builder.io/mitosis 0.0.73 → 0.0.75
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/generators/angular.js +6 -3
- package/dist/src/generators/lit/generate.js +0 -3
- package/dist/src/generators/marko/generate.js +0 -3
- package/dist/src/generators/qwik/component-generator.js +9 -8
- package/dist/src/generators/qwik/directives.js +4 -0
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +5 -9
- package/dist/src/generators/react/generator.js +15 -11
- package/dist/src/generators/solid/index.js +24 -26
- package/dist/src/generators/stencil/generate.js +0 -3
- package/dist/src/generators/svelte/blocks.d.ts +10 -0
- package/dist/src/generators/svelte/blocks.js +188 -0
- package/dist/src/generators/svelte/helpers.d.ts +2 -0
- package/dist/src/generators/svelte/helpers.js +11 -0
- package/dist/src/generators/svelte/index.d.ts +1 -0
- package/dist/src/generators/svelte/index.js +5 -0
- package/dist/src/generators/svelte/svelte.d.ts +3 -0
- package/dist/src/generators/svelte/svelte.js +250 -0
- package/dist/src/generators/svelte/types.d.ts +4 -0
- package/dist/src/generators/svelte/types.js +2 -0
- package/dist/src/generators/vue/blocks.js +13 -23
- package/dist/src/generators/vue/compositionApi.js +23 -83
- package/dist/src/generators/vue/helpers.d.ts +10 -4
- package/dist/src/generators/vue/helpers.js +100 -18
- package/dist/src/generators/vue/optionsApi.js +6 -28
- package/dist/src/generators/vue/types.d.ts +5 -2
- package/dist/src/generators/vue/vue.d.ts +1 -4
- package/dist/src/generators/vue/vue.js +70 -49
- package/dist/src/helpers/is-children.js +3 -2
- package/dist/src/helpers/merge-options.d.ts +7 -0
- package/dist/src/helpers/merge-options.js +31 -0
- package/dist/src/helpers/plugins/process-code.d.ts +8 -0
- package/dist/src/helpers/plugins/process-code.js +69 -0
- package/dist/src/helpers/replace-identifiers.js +18 -8
- package/dist/src/helpers/typescript.d.ts +1 -1
- package/dist/src/parsers/angular.js +4 -3
- package/dist/src/parsers/builder.d.ts +2 -2
- package/dist/src/parsers/jsx/ast.d.ts +2 -0
- package/dist/src/parsers/jsx/component-types.d.ts +2 -0
- package/dist/src/parsers/jsx/element-parser.d.ts +3 -1
- package/dist/src/parsers/jsx/exports.d.ts +4 -2
- package/dist/src/parsers/jsx/function-parser.d.ts +2 -0
- package/dist/src/parsers/jsx/helpers.d.ts +2 -0
- package/dist/src/parsers/jsx/imports.d.ts +2 -0
- package/dist/src/parsers/jsx/metadata.d.ts +2 -0
- package/dist/src/parsers/jsx/state.d.ts +2 -0
- package/dist/src/targets.d.ts +1 -1
- package/dist/src/types/mitosis-component.d.ts +8 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/src/generators/svelte.d.ts +0 -14
- package/dist/src/generators/svelte.js +0 -455
|
@@ -53,6 +53,7 @@ var slots_1 = require("../helpers/slots");
|
|
|
53
53
|
var get_custom_imports_1 = require("../helpers/get-custom-imports");
|
|
54
54
|
var get_components_used_1 = require("../helpers/get-components-used");
|
|
55
55
|
var is_upper_case_1 = require("../helpers/is-upper-case");
|
|
56
|
+
var html_tags_1 = require("../constants/html_tags");
|
|
56
57
|
var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment']);
|
|
57
58
|
var mappers = {
|
|
58
59
|
Fragment: function (json, options, blockOptions) {
|
|
@@ -92,6 +93,7 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
92
93
|
var outputVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.outputVars) || [];
|
|
93
94
|
var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
94
95
|
var domRefs = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.domRefs) || [];
|
|
96
|
+
var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name.trim());
|
|
95
97
|
if (mappers[json.name]) {
|
|
96
98
|
return mappers[json.name](json, options, blockOptions);
|
|
97
99
|
}
|
|
@@ -191,11 +193,12 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
191
193
|
else if (BINDINGS_MAPPER[key]) {
|
|
192
194
|
str += " [".concat(BINDINGS_MAPPER[key], "]=\"").concat(useValue, "\" ");
|
|
193
195
|
}
|
|
194
|
-
else if (key.includes('-')) {
|
|
196
|
+
else if (isValidHtmlTag || key.includes('-')) {
|
|
197
|
+
// standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
|
|
195
198
|
str += " [attr.".concat(key, "]=\"").concat(useValue, "\" ");
|
|
196
199
|
}
|
|
197
200
|
else {
|
|
198
|
-
str += "
|
|
201
|
+
str += "[".concat(key, "]=\"").concat(useValue, "\" ");
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
204
|
if (jsx_1.selfClosingTags.has(json.name)) {
|
|
@@ -380,7 +383,7 @@ var componentToAngular = function (userOptions) {
|
|
|
380
383
|
outputVars: outputVars,
|
|
381
384
|
}), "\n "), "\n }\n "), !hasOnMount
|
|
382
385
|
? ''
|
|
383
|
-
: "ngOnInit() {\n
|
|
386
|
+
: "ngOnInit() {\n\n ".concat(!((_k = json.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
|
|
384
387
|
? ''
|
|
385
388
|
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_l = json.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, {
|
|
386
389
|
replaceWith: 'this.',
|
|
@@ -74,9 +74,6 @@ var blockToLit = function (json, options) {
|
|
|
74
74
|
}
|
|
75
75
|
for (var key in json.bindings) {
|
|
76
76
|
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
|
|
77
|
-
if (key === '_forName') {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
77
|
if (type === 'spread') {
|
|
81
78
|
str += " ${spread(".concat(code, ")} ");
|
|
82
79
|
}
|
|
@@ -79,9 +79,6 @@ var blockToMarko = function (json, options) {
|
|
|
79
79
|
}
|
|
80
80
|
for (var key in json.bindings) {
|
|
81
81
|
var _f = json.bindings[key], code = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g, type = _f.type;
|
|
82
|
-
if (key === '_forName') {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
82
|
if (type === 'spread') {
|
|
86
83
|
str += " ...(".concat(code, ") ");
|
|
87
84
|
}
|
|
@@ -53,6 +53,7 @@ var componentToQwik = function (userOptions) {
|
|
|
53
53
|
try {
|
|
54
54
|
emitImports(file, component);
|
|
55
55
|
emitTypes(file, component);
|
|
56
|
+
emitExports(file, component);
|
|
56
57
|
var metadata = component.meta.useMetadata || {};
|
|
57
58
|
var isLightComponent = ((_c = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
|
|
58
59
|
var mutable_1 = ((_d = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _d === void 0 ? void 0 : _d.mutable) || [];
|
|
@@ -97,6 +98,13 @@ var componentToQwik = function (userOptions) {
|
|
|
97
98
|
};
|
|
98
99
|
};
|
|
99
100
|
exports.componentToQwik = componentToQwik;
|
|
101
|
+
function emitExports(file, component) {
|
|
102
|
+
component.exports &&
|
|
103
|
+
Object.keys(component.exports).forEach(function (key) {
|
|
104
|
+
var exportObj = component.exports[key];
|
|
105
|
+
file.src.emit(exportObj.code);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
100
108
|
function emitTagNameHack(file, component, metadataValue) {
|
|
101
109
|
if (typeof metadataValue === 'string' && metadataValue) {
|
|
102
110
|
file.src.emit(metadataValue, '=', (0, convert_method_to_function_1.convertMethodToFunction)(metadataValue, stateToMethodOrGetter(component.state), getLexicalScopeVars(component)), ';');
|
|
@@ -144,14 +152,7 @@ function emitJSX(file, component, mutable) {
|
|
|
144
152
|
var handlers = new Map();
|
|
145
153
|
var styles = new Map();
|
|
146
154
|
var parentSymbolBindings = {};
|
|
147
|
-
|
|
148
|
-
? function (code) {
|
|
149
|
-
return !!mutable.find(function (txt) {
|
|
150
|
-
return code.indexOf(txt) !== -1;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
: undefined;
|
|
154
|
-
file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings, mutablePredicate));
|
|
155
|
+
file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings));
|
|
155
156
|
}
|
|
156
157
|
function emitUseContextProvider(file, component) {
|
|
157
158
|
Object.keys(component.context.set).forEach(function (ctxKey) {
|
|
@@ -70,6 +70,10 @@ function Image(props) {
|
|
|
70
70
|
loading: isPixel ? 'eager' : 'lazy',
|
|
71
71
|
srcset: undefined,
|
|
72
72
|
};
|
|
73
|
+
var qwikBugWorkaround = function (imgProps) {
|
|
74
|
+
return Object.keys(imgProps).forEach(function (k) { return imgProps[k] === undefined && delete imgProps[k]; });
|
|
75
|
+
};
|
|
76
|
+
qwikBugWorkaround(imgProps);
|
|
73
77
|
if (isBuilderIoImage) {
|
|
74
78
|
var webpImage_1 = updateQueryParam(image, 'format', 'webp');
|
|
75
79
|
var srcset = ['100', '200', '400', '800', '1200', '1600', '2000']
|
|
@@ -13,4 +13,4 @@ import { CssStyles } from './styles';
|
|
|
13
13
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>,
|
|
16
|
+
export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, root?: boolean): any;
|
|
@@ -36,7 +36,7 @@ var src_generator_1 = require("./src-generator");
|
|
|
36
36
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
37
37
|
* @returns
|
|
38
38
|
*/
|
|
39
|
-
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings,
|
|
39
|
+
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, root) {
|
|
40
40
|
if (root === void 0) { root = true; }
|
|
41
41
|
return function () {
|
|
42
42
|
var _this = this;
|
|
@@ -121,9 +121,9 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
var symbolBindings = {};
|
|
124
|
-
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings
|
|
124
|
+
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
|
|
125
125
|
_this.jsxBegin(childName, props, __assign(__assign(__assign({}, bindings), parentSymbolBindings), specialBindings));
|
|
126
|
-
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings,
|
|
126
|
+
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, false).call(_this);
|
|
127
127
|
_this.jsxEnd(childName);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -138,7 +138,7 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
138
138
|
children = children.filter(function (c) { return !isEmptyTextNode(c); });
|
|
139
139
|
var childNeedsFragment = children.length > 1 || (children.length && isTextNode(children[0]));
|
|
140
140
|
childNeedsFragment && srcBuilder.jsxBeginFragment(fragmentSymbol);
|
|
141
|
-
renderJSXNodes(file, directives, handlers, children, styles, {},
|
|
141
|
+
renderJSXNodes(file, directives, handlers, children, styles, {}, false).call(srcBuilder);
|
|
142
142
|
childNeedsFragment && srcBuilder.jsxEndFragment();
|
|
143
143
|
};
|
|
144
144
|
}
|
|
@@ -182,7 +182,7 @@ function isSlotProjection(child) {
|
|
|
182
182
|
* @param symbolBindings Options record which will receive the symbol bindings
|
|
183
183
|
* @returns
|
|
184
184
|
*/
|
|
185
|
-
function rewriteHandlers(file, handlers, bindings, symbolBindings
|
|
185
|
+
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
186
186
|
var _a, _b;
|
|
187
187
|
var outBindings = {};
|
|
188
188
|
for (var key in bindings) {
|
|
@@ -207,10 +207,6 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredic
|
|
|
207
207
|
else if (key.startsWith('component.options.')) {
|
|
208
208
|
key = (0, src_generator_1.lastProperty)(key);
|
|
209
209
|
}
|
|
210
|
-
if (mutablePredicate && bindingExpr && mutablePredicate(bindingExpr)) {
|
|
211
|
-
file.import(file.qwikModule, 'mutable');
|
|
212
|
-
bindingExpr = "mutable(".concat(bindingExpr, ")");
|
|
213
|
-
}
|
|
214
210
|
outBindings[key] = { code: bindingExpr, type: (_b = bindings === null || bindings === void 0 ? void 0 : bindings[key]) === null || _b === void 0 ? void 0 : _b.type };
|
|
215
211
|
}
|
|
216
212
|
}
|
|
@@ -107,9 +107,13 @@ var NODE_MAPPERS = {
|
|
|
107
107
|
.join('\n')).concat(wrap ? closeFrag(options) : '', "\n ) : ").concat(!json.meta.else ? 'null' : (0, exports.blockToReact)(json.meta.else, options), "}");
|
|
108
108
|
},
|
|
109
109
|
};
|
|
110
|
+
var ATTTRIBUTE_MAPPERS = {
|
|
111
|
+
spellcheck: 'spellCheck',
|
|
112
|
+
autocapitalize: 'autoCapitalize',
|
|
113
|
+
autocomplete: 'autoComplete',
|
|
114
|
+
};
|
|
110
115
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
111
|
-
var BINDING_MAPPERS = {
|
|
112
|
-
ref: function (ref, value, options) {
|
|
116
|
+
var BINDING_MAPPERS = __assign({ ref: function (ref, value, options) {
|
|
113
117
|
var regexp = /(.+)?props\.(.+)( |\)|;|\()?$/m;
|
|
114
118
|
if (regexp.test(value)) {
|
|
115
119
|
var match = regexp.exec(value);
|
|
@@ -119,11 +123,9 @@ var BINDING_MAPPERS = {
|
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
return [ref, value];
|
|
122
|
-
},
|
|
123
|
-
innerHTML: function (_key, value) {
|
|
126
|
+
}, innerHTML: function (_key, value) {
|
|
124
127
|
return ['dangerouslySetInnerHTML', "{__html: ".concat(value.replace(/\s+/g, ' '), "}")];
|
|
125
|
-
},
|
|
126
|
-
};
|
|
128
|
+
} }, ATTTRIBUTE_MAPPERS);
|
|
127
129
|
var blockToReact = function (json, options, parentSlots) {
|
|
128
130
|
var _a, _b, _c;
|
|
129
131
|
if (NODE_MAPPERS[json.name]) {
|
|
@@ -425,7 +427,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
425
427
|
var _o = getRefsString(json, allRefs, options), hasStateArgument = _o[0], refsString = _o[1];
|
|
426
428
|
var nativeStyles = stylesType === 'react-native' && componentHasStyles && (0, react_native_1.collectReactNativeStyles)(json);
|
|
427
429
|
var propsArgs = "props: ".concat(json.propsTypeRef || 'any');
|
|
428
|
-
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n "])), options.preact
|
|
430
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "", "", "function ", "(", "", ") {\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n "])), options.preact
|
|
429
431
|
? "\n /** @jsx h */\n import { h, Fragment } from 'preact';\n "
|
|
430
432
|
: options.type !== 'native'
|
|
431
433
|
? "import * as React from 'react';"
|
|
@@ -434,11 +436,11 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
434
436
|
: '', componentHasStyles && stylesType === 'emotion' && options.format !== 'lite'
|
|
435
437
|
? "/** @jsx jsx */\n import { jsx } from '@emotion/react'".trim()
|
|
436
438
|
: '', hasState && stateType === 'valtio' ? "import { useLocalProxy } from 'valtio/utils';" : '', hasState && stateType === 'solid' ? "import { useMutable } from 'react-solid-state';" : '', stateType === 'mobx' && hasState
|
|
437
|
-
? "import { useLocalObservable } from 'mobx-react-lite';"
|
|
439
|
+
? "import { useLocalObservable, observer } from 'mobx-react-lite';"
|
|
438
440
|
: '', json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
439
441
|
component: json,
|
|
440
442
|
target: options.type === 'native' ? 'reactNative' : 'react',
|
|
441
|
-
}), isSubComponent ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', options.contextType === 'prop-drill'
|
|
443
|
+
}), stateType === 'mobx' && isForwardRef ? "const ".concat(json.name || 'MyComponent', " = ") : "", isSubComponent || stateType === 'mobx' ? '' : 'export default ', isForwardRef ? "forwardRef".concat(forwardRefType ? "<".concat(forwardRefType, ">") : '', "(") : '', json.name || 'MyComponent', propsArgs, isForwardRef ? ", ".concat(options.forwardRef) : '', options.contextType === 'prop-drill'
|
|
442
444
|
? "const ".concat(exports.contextPropDrillingKey, " = { ...props['").concat(exports.contextPropDrillingKey, "'] };")
|
|
443
445
|
: '', hasStateArgument ? '' : refsString, hasState
|
|
444
446
|
? stateType === 'mobx'
|
|
@@ -462,7 +464,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
462
464
|
str: json.hooks.onMount.code,
|
|
463
465
|
options: options,
|
|
464
466
|
}), "\n }, [])")
|
|
465
|
-
: '', (_k = (_j = json.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.map(function (hook) { return "useEffect(() => {\n ".concat((0, state_2.processHookCode)({ str: hook.code, options: options }), "\n }
|
|
467
|
+
: '', (_k = (_j = json.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.map(function (hook) { return "useEffect(() => {\n ".concat((0, state_2.processHookCode)({ str: hook.code, options: options }), "\n },\n ").concat(hook.deps ? (0, state_2.processHookCode)({ str: hook.deps, options: options }) : '', ")"); }).join(';')) !== null && _k !== void 0 ? _k : '', ((_l = json.hooks.onUnMount) === null || _l === void 0 ? void 0 : _l.code)
|
|
466
468
|
? "useEffect(() => {\n return () => {\n ".concat((0, state_2.processHookCode)({
|
|
467
469
|
str: json.hooks.onUnMount.code,
|
|
468
470
|
options: options,
|
|
@@ -475,7 +477,9 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
475
477
|
? ''
|
|
476
478
|
: "".concat(json.name || 'MyComponent', ".defaultProps = ").concat(json5_1.default.stringify(json.defaultProps), ";"), !nativeStyles
|
|
477
479
|
? ''
|
|
478
|
-
: "\n const styles = StyleSheet.create(".concat(json5_1.default.stringify(nativeStyles), ");\n "), styledComponentsCode ? styledComponentsCode : ''
|
|
480
|
+
: "\n const styles = StyleSheet.create(".concat(json5_1.default.stringify(nativeStyles), ");\n "), styledComponentsCode ? styledComponentsCode : '', stateType === 'mobx'
|
|
481
|
+
? "\n const observed".concat(json.name || 'MyComponent', " = observer(").concat(json.name || 'MyComponent', ");\n export default observed").concat(json.name || 'MyComponent', ";\n ")
|
|
482
|
+
: '');
|
|
479
483
|
str = (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(str);
|
|
480
484
|
return str;
|
|
481
485
|
};
|
|
@@ -78,10 +78,8 @@ var hash_sum_1 = __importDefault(require("hash-sum"));
|
|
|
78
78
|
var Array_1 = require("fp-ts/lib/Array");
|
|
79
79
|
var S = __importStar(require("fp-ts/string"));
|
|
80
80
|
var helpers_2 = require("./state/helpers");
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
stylesType: 'styled-components',
|
|
84
|
-
};
|
|
81
|
+
var merge_options_1 = require("../../helpers/merge-options");
|
|
82
|
+
var process_code_1 = require("../../helpers/plugins/process-code");
|
|
85
83
|
// Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
|
|
86
84
|
function processDynamicComponents(json, options) {
|
|
87
85
|
var found = false;
|
|
@@ -168,7 +166,6 @@ var preProcessBlockCode = function (_a) {
|
|
|
168
166
|
var blockToSolid = function (_a) {
|
|
169
167
|
var _b, _c;
|
|
170
168
|
var json = _a.json, options = _a.options, component = _a.component;
|
|
171
|
-
preProcessBlockCode({ json: json, options: options, component: component });
|
|
172
169
|
if (json.properties._text) {
|
|
173
170
|
return json.properties._text;
|
|
174
171
|
}
|
|
@@ -203,9 +200,6 @@ var blockToSolid = function (_a) {
|
|
|
203
200
|
}
|
|
204
201
|
for (var key in json.bindings) {
|
|
205
202
|
var _d = json.bindings[key], code = _d.code, _e = _d.arguments, cusArg = _e === void 0 ? ['event'] : _e, type = _d.type;
|
|
206
|
-
if (key === '_forName') {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
203
|
if (!code)
|
|
210
204
|
continue;
|
|
211
205
|
if (type === 'spread') {
|
|
@@ -278,29 +272,34 @@ function addProviderComponents(json, options) {
|
|
|
278
272
|
];
|
|
279
273
|
}
|
|
280
274
|
}
|
|
281
|
-
var
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
json.hooks.onMount.code = processCode(json.hooks.onMount.code);
|
|
286
|
-
}
|
|
287
|
-
if (json.hooks.onUpdate) {
|
|
288
|
-
for (var _i = 0, _b = json.hooks.onUpdate; _i < _b.length; _i++) {
|
|
289
|
-
var hook = _b[_i];
|
|
290
|
-
hook.code = processCode(hook.code);
|
|
291
|
-
if (hook.deps) {
|
|
292
|
-
hook.deps = processCode(hook.deps);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
275
|
+
var DEFAULT_OPTIONS = {
|
|
276
|
+
state: 'signals',
|
|
277
|
+
stylesType: 'styled-components',
|
|
278
|
+
plugins: [],
|
|
296
279
|
};
|
|
297
280
|
var componentToSolid = function (passedOptions) {
|
|
298
|
-
if (passedOptions === void 0) { passedOptions = DEFAULT_OPTIONS; }
|
|
299
281
|
return function (_a) {
|
|
300
282
|
var _b, _c, _d, _e, _f, _g;
|
|
301
283
|
var component = _a.component;
|
|
302
|
-
var options = __assign(__assign({}, DEFAULT_OPTIONS), passedOptions);
|
|
303
284
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
285
|
+
var options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, passedOptions);
|
|
286
|
+
options.plugins = __spreadArray(__spreadArray([], (options.plugins || []), true), [
|
|
287
|
+
(0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
|
|
288
|
+
switch (codeType) {
|
|
289
|
+
case 'state':
|
|
290
|
+
return function (c) { return c; };
|
|
291
|
+
case 'bindings':
|
|
292
|
+
case 'hooks':
|
|
293
|
+
case 'hooks-deps':
|
|
294
|
+
case 'properties':
|
|
295
|
+
return (0, helpers_2.updateStateCode)({
|
|
296
|
+
component: json,
|
|
297
|
+
options: options,
|
|
298
|
+
updateSetters: codeType === 'properties' ? false : true,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}),
|
|
302
|
+
], false);
|
|
304
303
|
if (options.plugins) {
|
|
305
304
|
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
306
305
|
}
|
|
@@ -310,7 +309,6 @@ var componentToSolid = function (passedOptions) {
|
|
|
310
309
|
if (options.plugins) {
|
|
311
310
|
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
312
311
|
}
|
|
313
|
-
preProcessComponentCode(json, options);
|
|
314
312
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
315
313
|
var foundDynamicComponents = processDynamicComponents(json, options);
|
|
316
314
|
var css = options.stylesType === 'style-tag' &&
|
|
@@ -62,9 +62,6 @@ var blockToStencil = function (json, options) {
|
|
|
62
62
|
}
|
|
63
63
|
for (var key in json.bindings) {
|
|
64
64
|
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
|
|
65
|
-
if (key === '_forName') {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
65
|
if (type === 'spread') {
|
|
69
66
|
str += " {...(".concat(code, ")} ");
|
|
70
67
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
|
+
import { BaseNode, MitosisNode } from '../../types/mitosis-node';
|
|
3
|
+
import { ToSvelteOptions } from './types';
|
|
4
|
+
declare type BlockToSvelte<T extends BaseNode = MitosisNode> = (props: {
|
|
5
|
+
json: T;
|
|
6
|
+
options: ToSvelteOptions;
|
|
7
|
+
parentComponent: MitosisComponent;
|
|
8
|
+
}) => string;
|
|
9
|
+
export declare const blockToSvelte: BlockToSvelte;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.blockToSvelte = void 0;
|
|
7
|
+
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
8
|
+
var jsx_1 = require("../../parsers/jsx");
|
|
9
|
+
var is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
10
|
+
var remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
|
|
11
|
+
var slots_1 = require("../../helpers/slots");
|
|
12
|
+
var html_tags_1 = require("../../constants/html_tags");
|
|
13
|
+
var is_upper_case_1 = require("../../helpers/is-upper-case");
|
|
14
|
+
var for_1 = require("../../helpers/nodes/for");
|
|
15
|
+
var helpers_1 = require("./helpers");
|
|
16
|
+
var mappers = {
|
|
17
|
+
Fragment: function (_a) {
|
|
18
|
+
var _b;
|
|
19
|
+
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
20
|
+
if ((_b = json.bindings.innerHTML) === null || _b === void 0 ? void 0 : _b.code) {
|
|
21
|
+
return BINDINGS_MAPPER.innerHTML(json, options);
|
|
22
|
+
}
|
|
23
|
+
else if (json.children.length > 0) {
|
|
24
|
+
return "".concat(json.children
|
|
25
|
+
.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
|
|
26
|
+
.join('\n'));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
For: function (_a) {
|
|
33
|
+
var _b, _c;
|
|
34
|
+
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
35
|
+
var firstChild = json.children[0];
|
|
36
|
+
var keyValue = firstChild.properties.key || ((_b = firstChild.bindings.key) === null || _b === void 0 ? void 0 : _b.code);
|
|
37
|
+
if (keyValue) {
|
|
38
|
+
// we remove extraneous prop which Svelte does not use
|
|
39
|
+
delete firstChild.properties.key;
|
|
40
|
+
delete firstChild.bindings.key;
|
|
41
|
+
}
|
|
42
|
+
var args = (0, for_1.getForArguments)(json, { excludeCollectionName: true }).join(', ');
|
|
43
|
+
return "\n{#each ".concat((0, helpers_1.stripStateAndProps)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, options), " as ").concat(args, " ").concat(keyValue ? "(".concat(keyValue, ")") : '', "}\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
|
|
44
|
+
},
|
|
45
|
+
Show: function (_a) {
|
|
46
|
+
var _b;
|
|
47
|
+
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
48
|
+
return "\n{#if ".concat((0, helpers_1.stripStateAndProps)((_b = json.bindings.when) === null || _b === void 0 ? void 0 : _b.code, options), " }\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n\n ").concat(json.meta.else
|
|
49
|
+
? "\n {:else}\n ".concat((0, exports.blockToSvelte)({
|
|
50
|
+
json: json.meta.else,
|
|
51
|
+
options: options,
|
|
52
|
+
parentComponent: parentComponent,
|
|
53
|
+
}), "\n ")
|
|
54
|
+
: '', "\n{/if}");
|
|
55
|
+
},
|
|
56
|
+
Slot: function (_a) {
|
|
57
|
+
var _b, _c;
|
|
58
|
+
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
59
|
+
if (!json.bindings.name) {
|
|
60
|
+
var key = Object.keys(json.bindings).find(Boolean);
|
|
61
|
+
if (!key)
|
|
62
|
+
return '<slot />';
|
|
63
|
+
return "\n <span #".concat(key, ">\n ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code), "\n </span>\n ");
|
|
64
|
+
}
|
|
65
|
+
var strippedTextCode = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.name.code);
|
|
66
|
+
return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\">").concat((_c = json.children) === null || _c === void 0 ? void 0 : _c.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "</slot>");
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
var BINDINGS_MAPPER = {
|
|
70
|
+
innerHTML: function (json, options) { var _a; return "{@html ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code), "}"); },
|
|
71
|
+
};
|
|
72
|
+
var SVELTE_SPECIAL_TAGS = {
|
|
73
|
+
COMPONENT: 'svelte:component',
|
|
74
|
+
ELEMENT: 'svelte:element',
|
|
75
|
+
SELF: 'svelte:self',
|
|
76
|
+
};
|
|
77
|
+
var getTagName = function (_a) {
|
|
78
|
+
var json = _a.json, parentComponent = _a.parentComponent;
|
|
79
|
+
if (parentComponent && json.name === parentComponent.name) {
|
|
80
|
+
return SVELTE_SPECIAL_TAGS.SELF;
|
|
81
|
+
}
|
|
82
|
+
var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name);
|
|
83
|
+
var isSpecialSvelteTag = json.name.startsWith('svelte:');
|
|
84
|
+
// Check if any import matches `json.name`
|
|
85
|
+
var hasMatchingImport = parentComponent.imports.some(function (_a) {
|
|
86
|
+
var imports = _a.imports;
|
|
87
|
+
return Object.keys(imports).some(function (name) { return name === json.name; });
|
|
88
|
+
});
|
|
89
|
+
// TO-DO: no way to decide between <svelte:component> and <svelte:element>...need to do that through metadata
|
|
90
|
+
// overrides for now
|
|
91
|
+
if (!isValidHtmlTag && !isSpecialSvelteTag && !hasMatchingImport) {
|
|
92
|
+
json.bindings.this = { code: json.name };
|
|
93
|
+
return SVELTE_SPECIAL_TAGS.COMPONENT;
|
|
94
|
+
}
|
|
95
|
+
return json.name;
|
|
96
|
+
};
|
|
97
|
+
var stringifyBinding = function (options) {
|
|
98
|
+
return function (_a) {
|
|
99
|
+
var key = _a[0], binding = _a[1];
|
|
100
|
+
if (key === 'innerHTML' || !binding) {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
var code = binding.code, _b = binding.arguments, cusArgs = _b === void 0 ? ['event'] : _b, type = binding.type;
|
|
104
|
+
var useValue = (0, helpers_1.stripStateAndProps)(code, options);
|
|
105
|
+
if (type === 'spread') {
|
|
106
|
+
var spreadValue = key === 'props' ? '$$props' : useValue;
|
|
107
|
+
return " {...".concat(spreadValue, "} ");
|
|
108
|
+
}
|
|
109
|
+
else if (key.startsWith('on')) {
|
|
110
|
+
var event_1 = key.replace('on', '').toLowerCase();
|
|
111
|
+
// TODO: handle quotes in event handler values
|
|
112
|
+
var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
|
|
113
|
+
if (valueWithoutBlock === key) {
|
|
114
|
+
return " on:".concat(event_1, "={").concat(valueWithoutBlock, "} ");
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat(valueWithoutBlock, "}}\" ");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (key === 'ref') {
|
|
121
|
+
return " bind:this={".concat(useValue, "} ");
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return " ".concat(key, "={").concat(useValue, "} ");
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
var blockToSvelte = function (_a) {
|
|
129
|
+
var _b, _c, _d, _e;
|
|
130
|
+
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
131
|
+
if (mappers[json.name]) {
|
|
132
|
+
return mappers[json.name]({
|
|
133
|
+
json: json,
|
|
134
|
+
options: options,
|
|
135
|
+
parentComponent: parentComponent,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
var tagName = getTagName({ json: json, parentComponent: parentComponent });
|
|
139
|
+
if ((0, is_children_1.default)(json)) {
|
|
140
|
+
return "<slot></slot>";
|
|
141
|
+
}
|
|
142
|
+
if (json.properties._text) {
|
|
143
|
+
return json.properties._text;
|
|
144
|
+
}
|
|
145
|
+
var textCode = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code;
|
|
146
|
+
if (textCode) {
|
|
147
|
+
var strippedTextCode = (0, helpers_1.stripStateAndProps)(textCode, options);
|
|
148
|
+
if ((0, slots_1.isSlotProperty)(strippedTextCode)) {
|
|
149
|
+
return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\"/>");
|
|
150
|
+
}
|
|
151
|
+
return "{".concat(strippedTextCode, "}");
|
|
152
|
+
}
|
|
153
|
+
var str = '';
|
|
154
|
+
str += "<".concat(tagName, " ");
|
|
155
|
+
var isComponent = Boolean(tagName[0] && (0, is_upper_case_1.isUpperCase)(tagName[0]));
|
|
156
|
+
if ((((_c = json.bindings.style) === null || _c === void 0 ? void 0 : _c.code) || json.properties.style) && !isComponent) {
|
|
157
|
+
var useValue = (0, helpers_1.stripStateAndProps)(((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style, options);
|
|
158
|
+
str += "use:mitosis_styling={".concat(useValue, "}");
|
|
159
|
+
delete json.bindings.style;
|
|
160
|
+
delete json.properties.style;
|
|
161
|
+
}
|
|
162
|
+
for (var key in json.properties) {
|
|
163
|
+
var value = json.properties[key];
|
|
164
|
+
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
165
|
+
}
|
|
166
|
+
var stringifiedBindings = Object.entries(json.bindings).map(stringifyBinding(options)).join('');
|
|
167
|
+
str += stringifiedBindings;
|
|
168
|
+
// if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
|
|
169
|
+
// we use the innerHTML content as children and don't render the self-closing tag.
|
|
170
|
+
if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
|
|
171
|
+
str += '>';
|
|
172
|
+
str += BINDINGS_MAPPER.innerHTML(json, options);
|
|
173
|
+
str += "</".concat(tagName, ">");
|
|
174
|
+
return str;
|
|
175
|
+
}
|
|
176
|
+
if (jsx_1.selfClosingTags.has(tagName)) {
|
|
177
|
+
return str + ' />';
|
|
178
|
+
}
|
|
179
|
+
str += '>';
|
|
180
|
+
if (json.children) {
|
|
181
|
+
str += json.children
|
|
182
|
+
.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
|
|
183
|
+
.join('');
|
|
184
|
+
}
|
|
185
|
+
str += "</".concat(tagName, ">");
|
|
186
|
+
return str;
|
|
187
|
+
};
|
|
188
|
+
exports.blockToSvelte = blockToSvelte;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripStateAndProps = void 0;
|
|
4
|
+
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
5
|
+
var stripStateAndProps = function (code, options) {
|
|
6
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
7
|
+
includeState: options.stateType === 'variables',
|
|
8
|
+
replaceWith: function (name) { return (name === 'children' ? '$$slots.default' : name); },
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
exports.stripStateAndProps = stripStateAndProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { componentToSvelte } from './svelte';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentToSvelte = void 0;
|
|
4
|
+
var svelte_1 = require("./svelte");
|
|
5
|
+
Object.defineProperty(exports, "componentToSvelte", { enumerable: true, get: function () { return svelte_1.componentToSvelte; } });
|