@builder.io/mitosis 0.0.133 → 0.0.135
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 +1 -0
- package/dist/src/generators/helpers/on-mount.js +1 -1
- package/dist/src/generators/html.js +5 -1
- package/dist/src/generators/lit/generate.js +5 -1
- package/dist/src/generators/marko/generate.js +5 -1
- package/dist/src/generators/mitosis.js +18 -1
- package/dist/src/generators/qwik/component-generator.js +1 -0
- package/dist/src/generators/react/generator.js +1 -0
- package/dist/src/generators/solid/index.js +5 -1
- package/dist/src/generators/stencil/generate.js +5 -1
- package/dist/src/generators/svelte/svelte.js +5 -1
- package/dist/src/generators/vue/vue.js +1 -0
- package/dist/src/helpers/component-file-extensions.d.ts +3 -1
- package/dist/src/helpers/component-file-extensions.js +3 -2
- package/dist/src/helpers/render-imports.d.ts +20 -21
- package/dist/src/helpers/render-imports.js +16 -11
- package/dist/src/helpers/styles/helpers.js +11 -5
- package/dist/src/types/config.d.ts +2 -3
- package/dist/src/types/transpiler.d.ts +13 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -395,6 +395,7 @@ var componentToAngular = function (userOptions) {
|
|
|
395
395
|
return "const defaultProps = {".concat(defalutPropsString, "};\n");
|
|
396
396
|
};
|
|
397
397
|
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_f = options === null || options === void 0 ? void 0 : options.experimental) === null || _f === void 0 ? void 0 : _f.inject) ? 'Inject, forwardRef,' : '', domRefs.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', getPropsDefinition({ json: json }), (0, render_imports_1.renderPreComponent)({
|
|
398
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
398
399
|
component: json,
|
|
399
400
|
target: 'angular',
|
|
400
401
|
excludeMitosisComponents: !options.standalone && !options.preserveImports,
|
|
@@ -14,7 +14,7 @@ var stringifySingleScopeOnMount = function (json) {
|
|
|
14
14
|
return hooks
|
|
15
15
|
.map(function (hook, i) {
|
|
16
16
|
var hookFnName = "onMountHook_".concat(i);
|
|
17
|
-
return "\n
|
|
17
|
+
return "\n const ".concat(hookFnName, " = () => {\n ").concat(hook.code, "\n }\n ").concat(hookFnName, "();");
|
|
18
18
|
})
|
|
19
19
|
.join('');
|
|
20
20
|
};
|
|
@@ -611,7 +611,11 @@ var componentToCustomElement = function (_options) {
|
|
|
611
611
|
console.warn('Could not prettify', { string: html }, err);
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
|
-
var str = "\n ".concat(json.types ? json.types.join('\n') : '', "\n ").concat((0, render_imports_1.renderPreComponent)({
|
|
614
|
+
var str = "\n ".concat(json.types ? json.types.join('\n') : '', "\n ").concat((0, render_imports_1.renderPreComponent)({
|
|
615
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
616
|
+
component: json,
|
|
617
|
+
target: 'customElement',
|
|
618
|
+
}), "\n /**\n * Usage:\n * \n * <").concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(ComponentName, " extends ").concat(((_j = options === null || options === void 0 ? void 0 : options.experimental) === null || _j === void 0 ? void 0 : _j.classExtends)
|
|
615
619
|
? (_k = options === null || options === void 0 ? void 0 : options.experimental) === null || _k === void 0 ? void 0 : _k.classExtends(json, options)
|
|
616
620
|
: 'HTMLElement', " {\n ").concat(Array.from(domRefs)
|
|
617
621
|
.map(function (ref) {
|
|
@@ -180,7 +180,11 @@ var componentToLit = function (_options) {
|
|
|
180
180
|
html = html.replace(/\n{3,}/g, '\n\n');
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state, query } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html`\n ", "\n ", "\n `\n }\n }\n "], ["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state, query } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html\\`\n ", "\n ", "\n \\`\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
183
|
+
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state, query } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html`\n ", "\n ", "\n `\n }\n }\n "], ["\n ", "\n import { LitElement, html, css } from 'lit';\n import { customElement, property, state, query } from 'lit/decorators.js';\n\n ", "\n ", "\n\n @customElement('", "')\n export default class ", " extends LitElement {\n ", "\n\n ", "\n\n ", "\n \n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return html\\`\n ", "\n ", "\n \\`\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
184
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
185
|
+
component: json,
|
|
186
|
+
target: 'lit',
|
|
187
|
+
}), json.types ? json.types.join('\n') : '', hasSpread
|
|
184
188
|
? "\n const spread = (properties) =>\n directive((part) => {\n for (const property in properties) {\n const value = properties[attr];\n part.element[property] = value;\n }\n });\n "
|
|
185
189
|
: '', ((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName) || getCustomTagName(json.name, options), json.name, options.useShadowDom
|
|
186
190
|
? ''
|
|
@@ -182,7 +182,11 @@ var componentToMarko = function (userOptions) {
|
|
|
182
182
|
console.warn('Could not format css', err);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
var jsString = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n class {\n ", "\n\n ", "\n\n ", "\n \n ", "\n ", "\n ", "\n }\n "], ["\n ", "\n\n class {\n ", "\n\n ", "\n\n ", "\n \n ", "\n ", "\n ", "\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
185
|
+
var jsString = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n class {\n ", "\n\n ", "\n\n ", "\n \n ", "\n ", "\n ", "\n }\n "], ["\n ", "\n\n class {\n ", "\n\n ", "\n\n ", "\n \n ", "\n ", "\n ", "\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
186
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
187
|
+
component: json,
|
|
188
|
+
target: 'marko',
|
|
189
|
+
}), methodsString, !hasState
|
|
186
190
|
? ''
|
|
187
191
|
: "onCreate(".concat(thisHasProps ? 'input' : '', ") {\n this.state = ").concat(dataString, "\n }"), Array.from(domRefs)
|
|
188
192
|
.map(function (refName) { return "get ".concat((0, lodash_1.camelCase)(refName), "() { \n return this.getEl('").concat((0, lodash_1.camelCase)(refName), "')\n }"); })
|
|
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.componentToMitosis = exports.blockToMitosis = exports.DEFAULT_FORMAT = void 0;
|
|
31
|
+
var plugins_1 = require("../modules/plugins");
|
|
31
32
|
var json5_1 = __importDefault(require("json5"));
|
|
32
33
|
var standalone_1 = require("prettier/standalone");
|
|
33
34
|
var hooks_1 = require("../constants/hooks");
|
|
@@ -143,6 +144,9 @@ var componentToMitosis = function (toMitosisOptions) {
|
|
|
143
144
|
})({ component: component });
|
|
144
145
|
}
|
|
145
146
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
147
|
+
if (options.plugins) {
|
|
148
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
149
|
+
}
|
|
146
150
|
var domRefs = (0, get_refs_1.getRefs)(component);
|
|
147
151
|
// grab refs not used for bindings
|
|
148
152
|
var jsRefs = Object.keys(component.refs).filter(function (ref) { return domRefs.has(ref); });
|
|
@@ -154,15 +158,25 @@ var componentToMitosis = function (toMitosisOptions) {
|
|
|
154
158
|
var components = Array.from((0, get_components_1.getComponents)(json));
|
|
155
159
|
var mitosisComponents = components.filter(function (item) { return mitosisCoreComponents.includes(item); });
|
|
156
160
|
var otherComponents = components.filter(function (item) { return !mitosisCoreComponents.includes(item); });
|
|
161
|
+
if (options.plugins) {
|
|
162
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
163
|
+
}
|
|
157
164
|
var hasState = (0, state_1.checkHasState)(component);
|
|
158
165
|
var needsMitosisCoreImport = Boolean(hasState || refs.length || mitosisComponents.length);
|
|
159
166
|
var stringifiedUseMetadata = json5_1.default.stringify(component.meta.useMetadata);
|
|
160
167
|
// TODO: smart only pull in imports as needed
|
|
161
168
|
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n export default function ", "(props) {\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "], ["\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n export default function ", "(props) {\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "])), !needsMitosisCoreImport
|
|
162
169
|
? ''
|
|
163
|
-
: "import { ".concat(!hasState ? '' : 'useStore, ', " ").concat(!refs.length ? '' : 'useRef, ', " ").concat(mitosisComponents.join(', '), " } from '..';"), !otherComponents.length ? '' : "import { ".concat(otherComponents.join(','), " } from '@components';"), json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
170
|
+
: "import { ".concat(!hasState ? '' : 'useStore, ', " ").concat(!refs.length ? '' : 'useRef, ', " ").concat(mitosisComponents.join(', '), " } from '..';"), !otherComponents.length ? '' : "import { ".concat(otherComponents.join(','), " } from '@components';"), json.types ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
171
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
172
|
+
component: json,
|
|
173
|
+
target: 'mitosis',
|
|
174
|
+
}), stringifiedUseMetadata && stringifiedUseMetadata !== '{}'
|
|
164
175
|
? "".concat(hooks_1.HOOKS.METADATA, "(").concat(stringifiedUseMetadata, ")")
|
|
165
176
|
: '', component.name, !hasState ? '' : "const state = useStore(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");"), getRefsString(json, refs), json.hooks.onMount.map(function (hook) { return "onMount(() => { ".concat(hook.code, " })"); }), !((_b = json.hooks.onUnMount) === null || _b === void 0 ? void 0 : _b.code) ? '' : "onUnMount(() => { ".concat(json.hooks.onUnMount.code, " })"), addWrapper ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToMitosis)(item, options, component); }).join('\n'), addWrapper ? '</>' : '');
|
|
177
|
+
if (options.plugins) {
|
|
178
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
179
|
+
}
|
|
166
180
|
if (options.prettier !== false) {
|
|
167
181
|
try {
|
|
168
182
|
str = (0, standalone_1.format)(str, {
|
|
@@ -177,6 +191,9 @@ var componentToMitosis = function (toMitosisOptions) {
|
|
|
177
191
|
throw err;
|
|
178
192
|
}
|
|
179
193
|
}
|
|
194
|
+
if (options.plugins) {
|
|
195
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
196
|
+
}
|
|
180
197
|
return str;
|
|
181
198
|
};
|
|
182
199
|
};
|
|
@@ -429,6 +429,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
429
429
|
: options.stateType === 'mobx'
|
|
430
430
|
? "import { useLocalObservable, observer } from 'mobx-react-lite';"
|
|
431
431
|
: '', json.types && options.typescript ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
432
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
432
433
|
component: json,
|
|
433
434
|
target: options.type === 'native' ? 'reactNative' : 'react',
|
|
434
435
|
}), isForwardRef ? "const ".concat(json.name, " = forwardRef").concat(forwardRefType, "(") : '', json.name, componentArgs, componentBody, isForwardRef ? ')' : '', getPropsDefinition({ json: json }), reactNativeStyles
|
|
@@ -191,7 +191,11 @@ var componentToSolid = function (passedOptions) {
|
|
|
191
191
|
var propsArgs = "props".concat(options.typescript ? ":".concat(propType) : '');
|
|
192
192
|
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), solidJSImports.length > 0 ? "import { ".concat(solidJSImports.join(', '), " } from 'solid-js';") : '', !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", storeImports.length > 0 ? "import { ".concat(storeImports.join(', '), " } from 'solid-js/store';") : '', !componentHasStyles && options.stylesType === 'styled-components'
|
|
193
193
|
? ''
|
|
194
|
-
: "import { css } from \"solid-styled-components\";", json.types && options.typescript ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
194
|
+
: "import { css } from \"solid-styled-components\";", json.types && options.typescript ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
|
|
195
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
196
|
+
component: json,
|
|
197
|
+
target: 'solid',
|
|
198
|
+
}), json.name, propsArgs, (_f = state === null || state === void 0 ? void 0 : state.str) !== null && _f !== void 0 ? _f : '', getRefsString(json, options), getContextString(json, options), json.hooks.onMount.map(function (hook) { return "onMount(() => { ".concat(hook.code, " })"); }).join('\n'), json.hooks.onUpdate
|
|
195
199
|
? json.hooks.onUpdate
|
|
196
200
|
.map(function (hook, index) {
|
|
197
201
|
if (hook.deps) {
|
|
@@ -142,7 +142,11 @@ var componentToStencil = function (_options) {
|
|
|
142
142
|
*
|
|
143
143
|
* export default function ...
|
|
144
144
|
*/
|
|
145
|
-
, "',\n ", "\n })\n export default class ", " {\n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return (", "\n \n ", "\n\n ", ")\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
145
|
+
, "',\n ", "\n })\n export default class ", " {\n \n ", "\n\n ", "\n ", "\n \n ", "\n ", "\n ", "\n \n render() {\n return (", "\n \n ", "\n\n ", ")\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
146
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
147
|
+
component: json,
|
|
148
|
+
target: 'stencil',
|
|
149
|
+
}),
|
|
146
150
|
/**
|
|
147
151
|
* You can set the tagName in your Mitosis component as
|
|
148
152
|
*
|
|
@@ -275,7 +275,11 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
275
275
|
// make sure this is after all other state/code is initialized
|
|
276
276
|
, "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), !svelteStoreImports.length
|
|
277
277
|
? ''
|
|
278
|
-
: "import { ".concat(svelteStoreImports.sort().join(', '), " } from 'svelte/store'"), (0, render_imports_1.renderPreComponent)({
|
|
278
|
+
: "import { ".concat(svelteStoreImports.sort().join(', '), " } from 'svelte/store'"), (0, render_imports_1.renderPreComponent)({
|
|
279
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
280
|
+
component: json,
|
|
281
|
+
target: 'svelte',
|
|
282
|
+
}), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
|
|
279
283
|
.map(function (name) {
|
|
280
284
|
var _a, _b, _c;
|
|
281
285
|
if (name === 'children') {
|
|
@@ -220,6 +220,7 @@ var componentToVue = function (userOptions) {
|
|
|
220
220
|
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n\n <script ", " ", ">\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "], ["\n ", "\n\n\n <script ", " ", ">\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "])), template.trim().length > 0
|
|
221
221
|
? "<template>\n ".concat(template, "\n </template>")
|
|
222
222
|
: '', options.api === 'composition' ? 'setup' : '', tsLangAttribute, vueImports.length ? "import { ".concat((0, lodash_1.uniq)(vueImports).sort().join(', '), " } from \"vue\"") : '', (0, render_imports_1.renderPreComponent)({
|
|
223
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
223
224
|
component: component,
|
|
224
225
|
target: 'vue',
|
|
225
226
|
asyncComponentImports: options.asyncComponentImports,
|
|
@@ -12,9 +12,10 @@ export declare const renameComponentFile: ({ path, target, options, }: {
|
|
|
12
12
|
target: Target;
|
|
13
13
|
options: MitosisConfig;
|
|
14
14
|
}) => string;
|
|
15
|
-
export declare const renameImport: ({ importPath, target }: {
|
|
15
|
+
export declare const renameImport: ({ importPath, target, explicitImportFileExtension, }: {
|
|
16
16
|
importPath: string;
|
|
17
17
|
target: Target;
|
|
18
|
+
explicitImportFileExtension: boolean;
|
|
18
19
|
}) => string;
|
|
19
20
|
declare type Args = {
|
|
20
21
|
target: Target;
|
|
@@ -23,6 +24,7 @@ declare type Args = {
|
|
|
23
24
|
* Whether we are rendering an import statement or a filename.
|
|
24
25
|
*/
|
|
25
26
|
type: 'import';
|
|
27
|
+
explicitImportFileExtension: boolean;
|
|
26
28
|
} | {
|
|
27
29
|
/**
|
|
28
30
|
* Whether we are rendering an import statement or a filename.
|
|
@@ -39,10 +39,11 @@ exports.renameComponentFile = renameComponentFile;
|
|
|
39
39
|
*/
|
|
40
40
|
var INPUT_EXTENSION_IMPORT_REGEX = /\.(svelte|(lite(\.tsx|\.jsx)?))(?<quote>['"])/g;
|
|
41
41
|
var renameImport = function (_a) {
|
|
42
|
-
var importPath = _a.importPath, target = _a.target;
|
|
42
|
+
var importPath = _a.importPath, target = _a.target, explicitImportFileExtension = _a.explicitImportFileExtension;
|
|
43
43
|
return importPath.replace(INPUT_EXTENSION_IMPORT_REGEX, "".concat((0, exports.getComponentFileExtensionForTarget)({
|
|
44
44
|
type: 'import',
|
|
45
45
|
target: target,
|
|
46
|
+
explicitImportFileExtension: explicitImportFileExtension,
|
|
46
47
|
}), "$4"));
|
|
47
48
|
};
|
|
48
49
|
exports.renameImport = renameImport;
|
|
@@ -87,7 +88,7 @@ var getComponentFileExtensionForTarget = function (args) {
|
|
|
87
88
|
switch (args.type) {
|
|
88
89
|
case 'import':
|
|
89
90
|
// we can't have `.jsx`/`.tsx` extensions in the import paths, so we stick with implicit file extensions.
|
|
90
|
-
return '';
|
|
91
|
+
return args.explicitImportFileExtension ? '.js' : '';
|
|
91
92
|
case 'filename':
|
|
92
93
|
return args.isTypescript ? '.tsx' : '.jsx';
|
|
93
94
|
}
|
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
import { Target } from '../types/config';
|
|
2
2
|
import { MitosisComponent, MitosisImport } from '../types/mitosis-component';
|
|
3
3
|
export declare const checkIsComponentImport: (theImport: MitosisImport) => boolean;
|
|
4
|
-
export declare const transformImportPath: ({ theImport, target, preserveFileExtensions, }: {
|
|
4
|
+
export declare const transformImportPath: ({ theImport, target, preserveFileExtensions, explicitImportFileExtension, }: {
|
|
5
5
|
theImport: MitosisImport;
|
|
6
6
|
target: Target;
|
|
7
7
|
preserveFileExtensions: boolean;
|
|
8
|
+
explicitImportFileExtension: boolean;
|
|
8
9
|
}) => string;
|
|
9
|
-
|
|
10
|
-
theImport: MitosisImport;
|
|
10
|
+
declare type ImportArgs = {
|
|
11
11
|
target: Target;
|
|
12
12
|
asyncComponentImports: boolean;
|
|
13
|
-
preserveFileExtensions?: boolean
|
|
13
|
+
preserveFileExtensions?: boolean;
|
|
14
14
|
component?: MitosisComponent | null | undefined;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export declare const renderImports: ({ imports, target, asyncComponentImports, excludeMitosisComponents, preserveFileExtensions, component, componentsUsed, importMapper, }: {
|
|
19
|
-
imports: MitosisImport[];
|
|
20
|
-
target: Target;
|
|
21
|
-
asyncComponentImports: boolean;
|
|
22
|
-
excludeMitosisComponents?: boolean | undefined;
|
|
23
|
-
preserveFileExtensions?: boolean | undefined;
|
|
24
|
-
component: MitosisComponent;
|
|
25
|
-
componentsUsed?: string[] | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* This is only used by Angular generator, and will be deprecated in the future.
|
|
17
|
+
*/
|
|
26
18
|
importMapper?: Function | null | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* This is only used by Angular generator, and will be deprecated in the future.
|
|
21
|
+
*/
|
|
22
|
+
explicitImportFileExtension?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* This is only used by Angular generator, and will be deprecated in the future.
|
|
25
|
+
*/
|
|
26
|
+
componentsUsed?: string[];
|
|
27
|
+
};
|
|
28
|
+
export declare const renderImport: ({ theImport, target, asyncComponentImports, preserveFileExtensions, component, componentsUsed, importMapper, explicitImportFileExtension, }: ImportArgs & {
|
|
29
|
+
theImport: MitosisImport;
|
|
27
30
|
}) => string;
|
|
28
|
-
export declare const renderPreComponent: ({ component, target, excludeMitosisComponents, asyncComponentImports, preserveFileExtensions, componentsUsed, importMapper, }: {
|
|
31
|
+
export declare const renderPreComponent: ({ component, target, excludeMitosisComponents, asyncComponentImports, preserveFileExtensions, componentsUsed, importMapper, explicitImportFileExtension, }: Omit<ImportArgs, "asyncComponentImports" | "explicitImportFileExtension"> & Partial<Pick<ImportArgs, "asyncComponentImports" | "explicitImportFileExtension">> & {
|
|
29
32
|
component: MitosisComponent;
|
|
30
33
|
target: Target;
|
|
31
|
-
asyncComponentImports?: boolean | undefined;
|
|
32
34
|
excludeMitosisComponents?: boolean | undefined;
|
|
33
|
-
preserveFileExtensions?: boolean | undefined;
|
|
34
|
-
componentsUsed?: string[] | undefined;
|
|
35
|
-
importMapper?: Function | null | undefined;
|
|
36
35
|
}) => string;
|
|
37
|
-
export
|
|
36
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.renderPreComponent = exports.renderImport = exports.transformImportPath = exports.checkIsComponentImport = void 0;
|
|
4
4
|
var component_file_extensions_1 = require("./component-file-extensions");
|
|
5
5
|
var DEFAULT_IMPORT = 'default';
|
|
6
6
|
var STAR_IMPORT = '*';
|
|
@@ -34,7 +34,7 @@ var checkIsComponentImport = function (theImport) {
|
|
|
34
34
|
};
|
|
35
35
|
exports.checkIsComponentImport = checkIsComponentImport;
|
|
36
36
|
var transformImportPath = function (_a) {
|
|
37
|
-
var theImport = _a.theImport, target = _a.target, preserveFileExtensions = _a.preserveFileExtensions;
|
|
37
|
+
var theImport = _a.theImport, target = _a.target, preserveFileExtensions = _a.preserveFileExtensions, explicitImportFileExtension = _a.explicitImportFileExtension;
|
|
38
38
|
// We need to drop the `.lite` from context files, because the context generator does so as well.
|
|
39
39
|
if (checkIsContextImport(theImport)) {
|
|
40
40
|
var path_1 = theImport.path;
|
|
@@ -48,7 +48,7 @@ var transformImportPath = function (_a) {
|
|
|
48
48
|
if (preserveFileExtensions)
|
|
49
49
|
return theImport.path;
|
|
50
50
|
if ((0, exports.checkIsComponentImport)(theImport)) {
|
|
51
|
-
return theImport.path.replace(component_file_extensions_1.INPUT_EXTENSION_REGEX, (0, component_file_extensions_1.getComponentFileExtensionForTarget)({ target: target, type: 'import' }));
|
|
51
|
+
return theImport.path.replace(component_file_extensions_1.INPUT_EXTENSION_REGEX, (0, component_file_extensions_1.getComponentFileExtensionForTarget)({ target: target, type: 'import', explicitImportFileExtension: explicitImportFileExtension }));
|
|
52
52
|
}
|
|
53
53
|
return theImport.path;
|
|
54
54
|
};
|
|
@@ -88,9 +88,14 @@ var getImportValue = function (_a) {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
var renderImport = function (_a) {
|
|
91
|
-
var theImport = _a.theImport, target = _a.target, asyncComponentImports = _a.asyncComponentImports, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b, _c = _a.component, component = _c === void 0 ? undefined : _c, _d = _a.componentsUsed, componentsUsed = _d === void 0 ? [] : _d, importMapper = _a.importMapper;
|
|
91
|
+
var theImport = _a.theImport, target = _a.target, asyncComponentImports = _a.asyncComponentImports, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b, _c = _a.component, component = _c === void 0 ? undefined : _c, _d = _a.componentsUsed, componentsUsed = _d === void 0 ? [] : _d, importMapper = _a.importMapper, _e = _a.explicitImportFileExtension, explicitImportFileExtension = _e === void 0 ? false : _e;
|
|
92
92
|
var importedValues = getImportedValues({ theImport: theImport });
|
|
93
|
-
var path = (0, exports.transformImportPath)({
|
|
93
|
+
var path = (0, exports.transformImportPath)({
|
|
94
|
+
theImport: theImport,
|
|
95
|
+
target: target,
|
|
96
|
+
preserveFileExtensions: preserveFileExtensions,
|
|
97
|
+
explicitImportFileExtension: explicitImportFileExtension,
|
|
98
|
+
});
|
|
94
99
|
var importValue = getImportValue(importedValues);
|
|
95
100
|
var isComponentImport = (0, exports.checkIsComponentImport)(theImport);
|
|
96
101
|
var shouldBeAsyncImport = asyncComponentImports && isComponentImport;
|
|
@@ -118,7 +123,7 @@ var renderImport = function (_a) {
|
|
|
118
123
|
};
|
|
119
124
|
exports.renderImport = renderImport;
|
|
120
125
|
var renderImports = function (_a) {
|
|
121
|
-
var imports = _a.imports, target = _a.target, asyncComponentImports = _a.asyncComponentImports, excludeMitosisComponents = _a.excludeMitosisComponents, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b, component = _a.component, componentsUsed = _a.componentsUsed, importMapper = _a.importMapper;
|
|
126
|
+
var imports = _a.imports, target = _a.target, asyncComponentImports = _a.asyncComponentImports, excludeMitosisComponents = _a.excludeMitosisComponents, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b, component = _a.component, componentsUsed = _a.componentsUsed, importMapper = _a.importMapper, explicitImportFileExtension = _a.explicitImportFileExtension;
|
|
122
127
|
return imports
|
|
123
128
|
.filter(function (theImport) {
|
|
124
129
|
if (
|
|
@@ -144,15 +149,15 @@ var renderImports = function (_a) {
|
|
|
144
149
|
component: component,
|
|
145
150
|
componentsUsed: componentsUsed,
|
|
146
151
|
importMapper: importMapper,
|
|
152
|
+
explicitImportFileExtension: explicitImportFileExtension,
|
|
147
153
|
});
|
|
148
154
|
})
|
|
149
155
|
.join('\n');
|
|
150
156
|
};
|
|
151
|
-
exports.renderImports = renderImports;
|
|
152
157
|
var renderPreComponent = function (_a) {
|
|
153
158
|
var _b;
|
|
154
|
-
var component = _a.component, target = _a.target, excludeMitosisComponents = _a.excludeMitosisComponents, _c = _a.asyncComponentImports, asyncComponentImports = _c === void 0 ? false : _c, _d = _a.preserveFileExtensions, preserveFileExtensions = _d === void 0 ? false : _d, _e = _a.componentsUsed, componentsUsed = _e === void 0 ? [] : _e, importMapper = _a.importMapper;
|
|
155
|
-
return "\n ".concat(
|
|
159
|
+
var component = _a.component, target = _a.target, excludeMitosisComponents = _a.excludeMitosisComponents, _c = _a.asyncComponentImports, asyncComponentImports = _c === void 0 ? false : _c, _d = _a.preserveFileExtensions, preserveFileExtensions = _d === void 0 ? false : _d, _e = _a.componentsUsed, componentsUsed = _e === void 0 ? [] : _e, importMapper = _a.importMapper, _f = _a.explicitImportFileExtension, explicitImportFileExtension = _f === void 0 ? false : _f;
|
|
160
|
+
return "\n ".concat(renderImports({
|
|
156
161
|
imports: component.imports,
|
|
157
162
|
target: target,
|
|
158
163
|
asyncComponentImports: asyncComponentImports,
|
|
@@ -161,7 +166,8 @@ var renderPreComponent = function (_a) {
|
|
|
161
166
|
component: component,
|
|
162
167
|
componentsUsed: componentsUsed,
|
|
163
168
|
importMapper: importMapper,
|
|
164
|
-
|
|
169
|
+
explicitImportFileExtension: explicitImportFileExtension,
|
|
170
|
+
}), "\n ").concat(renderExportAndLocal(component), "\n ").concat(((_b = component.hooks.preComponent) === null || _b === void 0 ? void 0 : _b.code) || '', "\n ");
|
|
165
171
|
};
|
|
166
172
|
exports.renderPreComponent = renderPreComponent;
|
|
167
173
|
var renderExportAndLocal = function (component) {
|
|
@@ -169,4 +175,3 @@ var renderExportAndLocal = function (component) {
|
|
|
169
175
|
.map(function (key) { return component.exports[key].code; })
|
|
170
176
|
.join('\n');
|
|
171
177
|
};
|
|
172
|
-
exports.renderExportAndLocal = renderExportAndLocal;
|
|
@@ -9,6 +9,7 @@ var lodash_1 = require("lodash");
|
|
|
9
9
|
var traverse_1 = __importDefault(require("traverse"));
|
|
10
10
|
var dash_case_1 = require("../dash-case");
|
|
11
11
|
var is_mitosis_node_1 = require("../is-mitosis-node");
|
|
12
|
+
var is_upper_case_1 = require("../is-upper-case");
|
|
12
13
|
var nodeHasCss = function (node) {
|
|
13
14
|
var _a;
|
|
14
15
|
return Boolean(typeof ((_a = node.bindings.css) === null || _a === void 0 ? void 0 : _a.code) === 'string' && node.bindings.css.code.trim().length > 6);
|
|
@@ -68,12 +69,17 @@ var parseCssObject = function (css) {
|
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
exports.parseCssObject = parseCssObject;
|
|
71
|
-
var
|
|
72
|
+
var getCssPropertyName = function (cssObjectKey) {
|
|
72
73
|
// Allow custom CSS properties
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
74
|
+
if (cssObjectKey.startsWith('--')) {
|
|
75
|
+
return cssObjectKey;
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
+
var str = (0, dash_case_1.dashCase)(cssObjectKey);
|
|
78
|
+
// Convert vendor prefixes like 'WebkitFoo' to '-webkit-foo'
|
|
79
|
+
if ((0, is_upper_case_1.isUpperCase)(cssObjectKey[0])) {
|
|
80
|
+
str = "-".concat(str);
|
|
81
|
+
}
|
|
82
|
+
return str;
|
|
77
83
|
};
|
|
78
84
|
var styleMapToCss = function (map) {
|
|
79
85
|
return Object.entries(map)
|
|
@@ -83,7 +89,7 @@ var styleMapToCss = function (map) {
|
|
|
83
89
|
})
|
|
84
90
|
.map(function (_a) {
|
|
85
91
|
var key = _a[0], value = _a[1];
|
|
86
|
-
return " ".concat(
|
|
92
|
+
return " ".concat(getCssPropertyName(key), ": ").concat(value, ";");
|
|
87
93
|
})
|
|
88
94
|
.join('\n');
|
|
89
95
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ParseMitosisOptions } from '../parsers/jsx/types';
|
|
2
2
|
import type { MitosisComponent } from './mitosis-component';
|
|
3
|
+
import { BaseTranspilerOptions } from './transpiler';
|
|
3
4
|
export declare type Format = 'esm' | 'cjs';
|
|
4
5
|
export declare type Language = 'js' | 'ts';
|
|
5
6
|
interface TranspilerOptions {
|
|
@@ -13,9 +14,7 @@ export declare type GeneratorOptions = {
|
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
export declare type MitosisConfig = {
|
|
16
|
-
commonOptions?:
|
|
17
|
-
typescript?: boolean;
|
|
18
|
-
};
|
|
17
|
+
commonOptions?: Omit<BaseTranspilerOptions, 'experimental'>;
|
|
19
18
|
/**
|
|
20
19
|
* List of targets to compile to.
|
|
21
20
|
*/
|
|
@@ -13,7 +13,20 @@ export interface BaseTranspilerOptions {
|
|
|
13
13
|
experimental?: {
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Runs `prettier` on generated components
|
|
18
|
+
*/
|
|
16
19
|
prettier?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Mitosis Plugins to run during codegen.
|
|
22
|
+
*/
|
|
17
23
|
plugins?: Plugin[];
|
|
24
|
+
/**
|
|
25
|
+
* Enable `typescript` output
|
|
26
|
+
*/
|
|
18
27
|
typescript?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Preserves explicit filename extensions in import statements.
|
|
30
|
+
*/
|
|
31
|
+
explicitImportFileExtension?: boolean;
|
|
19
32
|
}
|