@builder.io/mitosis 0.0.71 → 0.0.72-0
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.d.ts +1 -0
- package/dist/src/generators/angular.js +2 -0
- package/dist/src/generators/react/generator.js +4 -2
- package/dist/src/generators/react/types.d.ts +1 -1
- package/dist/src/generators/rsc.d.ts +4 -0
- package/dist/src/generators/rsc.js +79 -0
- package/dist/src/generators/vue/blocks.d.ts +8 -0
- package/dist/src/generators/vue/blocks.js +294 -0
- package/dist/src/generators/vue/compositionApi.d.ts +3 -0
- package/dist/src/generators/vue/compositionApi.js +107 -0
- package/dist/src/generators/vue/helpers.d.ts +16 -0
- package/dist/src/generators/vue/helpers.js +62 -0
- package/dist/src/generators/vue/index.d.ts +2 -0
- package/dist/src/generators/vue/index.js +18 -0
- package/dist/src/generators/vue/optionsApi.d.ts +3 -0
- package/dist/src/generators/vue/optionsApi.js +186 -0
- package/dist/src/generators/vue/types.d.ts +12 -0
- package/dist/src/generators/vue/types.js +2 -0
- package/dist/src/generators/vue/vue.d.ts +6 -0
- package/dist/src/generators/vue/vue.js +227 -0
- package/dist/src/helpers/render-imports.d.ts +6 -3
- package/dist/src/helpers/render-imports.js +12 -8
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/targets.d.ts +1 -0
- package/dist/src/targets.js +2 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/dist/src/generators/vue.d.ts +0 -23
- package/dist/src/generators/vue.js +0 -778
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vue"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MitosisComponent, extendedHook } from '../../types/mitosis-component';
|
|
2
|
+
import { ToVueOptions } from './types';
|
|
3
|
+
export declare function generateOptionsApiScript(component: MitosisComponent, options: ToVueOptions, path: string | undefined, template: string, props: string[], onUpdateWithDeps: extendedHook[], onUpdateWithoutDeps: extendedHook[]): string;
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.generateOptionsApiScript = void 0;
|
|
16
|
+
var json5_1 = __importDefault(require("json5"));
|
|
17
|
+
var lodash_1 = require("lodash");
|
|
18
|
+
var get_components_used_1 = require("../../helpers/get-components-used");
|
|
19
|
+
var get_custom_imports_1 = require("../../helpers/get-custom-imports");
|
|
20
|
+
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
21
|
+
var nullable_1 = require("../../helpers/nullable");
|
|
22
|
+
var patterns_1 = require("../../helpers/patterns");
|
|
23
|
+
var render_imports_1 = require("../../helpers/render-imports");
|
|
24
|
+
var helpers_1 = require("./helpers");
|
|
25
|
+
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
26
|
+
function getContextInjectString(component, options) {
|
|
27
|
+
var str = '{';
|
|
28
|
+
for (var key in component.context.get) {
|
|
29
|
+
str += "\n ".concat(key, ": \"").concat((0, helpers_1.encodeQuotes)(component.context.get[key].name), "\",\n ");
|
|
30
|
+
}
|
|
31
|
+
str += '}';
|
|
32
|
+
return str;
|
|
33
|
+
}
|
|
34
|
+
function getContextProvideString(component, options) {
|
|
35
|
+
var str = '{';
|
|
36
|
+
for (var key in component.context.set) {
|
|
37
|
+
var _a = component.context.set[key], ref = _a.ref, value = _a.value, name_1 = _a.name;
|
|
38
|
+
str += "\n ".concat(name_1, ": ").concat(value
|
|
39
|
+
? (0, get_state_object_string_1.stringifyContextValue)(value, {
|
|
40
|
+
valueMapper: function (code) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: '_this.' }); },
|
|
41
|
+
})
|
|
42
|
+
: ref
|
|
43
|
+
? (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref, { replaceWith: '_this.' })
|
|
44
|
+
: null, ",\n ");
|
|
45
|
+
}
|
|
46
|
+
str += '}';
|
|
47
|
+
return str;
|
|
48
|
+
}
|
|
49
|
+
var generateComponentImport = function (options) {
|
|
50
|
+
return function (componentName) {
|
|
51
|
+
if (options.vueVersion >= 3 && options.asyncComponentImports) {
|
|
52
|
+
return "'".concat(componentName, "': defineAsyncComponent(").concat(componentName, ")");
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return "'".concat(componentName, "': ").concat(componentName);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
var generateComponents = function (componentsUsed, options) {
|
|
60
|
+
if (componentsUsed.length === 0) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return "components: { ".concat(componentsUsed.map(generateComponentImport(options)).join(','), " },");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var appendToDataString = function (_a) {
|
|
68
|
+
var dataString = _a.dataString, newContent = _a.newContent;
|
|
69
|
+
return dataString.replace(/}$/, "".concat(newContent, "}"));
|
|
70
|
+
};
|
|
71
|
+
function generateOptionsApiScript(component, options, path, template, props, onUpdateWithDeps, onUpdateWithoutDeps) {
|
|
72
|
+
var _a, _b, _c, _d;
|
|
73
|
+
var localExports = component.exports;
|
|
74
|
+
var localVarAsData = [];
|
|
75
|
+
var localVarAsFunc = [];
|
|
76
|
+
if (localExports) {
|
|
77
|
+
Object.keys(localExports).forEach(function (key) {
|
|
78
|
+
if (localExports[key].usedInLocal) {
|
|
79
|
+
if (localExports[key].isFunction) {
|
|
80
|
+
localVarAsFunc.push(key);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
localVarAsData.push(key);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
89
|
+
data: true,
|
|
90
|
+
functions: false,
|
|
91
|
+
getters: false,
|
|
92
|
+
});
|
|
93
|
+
// Append refs to data as { foo, bar, etc }
|
|
94
|
+
dataString = appendToDataString({
|
|
95
|
+
dataString: dataString,
|
|
96
|
+
newContent: (0, get_custom_imports_1.getCustomImports)(component).join(','),
|
|
97
|
+
});
|
|
98
|
+
if (localVarAsData.length) {
|
|
99
|
+
dataString = appendToDataString({ dataString: dataString, newContent: localVarAsData.join(',') });
|
|
100
|
+
}
|
|
101
|
+
var getterString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
102
|
+
data: false,
|
|
103
|
+
getters: true,
|
|
104
|
+
functions: false,
|
|
105
|
+
valueMapper: function (code) {
|
|
106
|
+
return (0, helpers_1.processBinding)({ code: code.replace(patterns_1.GETTER, ''), options: options, json: component });
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
110
|
+
data: false,
|
|
111
|
+
getters: false,
|
|
112
|
+
functions: true,
|
|
113
|
+
valueMapper: function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); },
|
|
114
|
+
});
|
|
115
|
+
var includeClassMapHelper = template.includes('_classStringToObject');
|
|
116
|
+
if (includeClassMapHelper) {
|
|
117
|
+
functionsString = functionsString.replace(/}\s*$/, "_classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/);\n for (const name of classNames) {\n obj[name] = true;\n }\n return obj;\n } }");
|
|
118
|
+
}
|
|
119
|
+
if (localVarAsFunc.length) {
|
|
120
|
+
functionsString = functionsString.replace(/}\s*$/, "".concat(localVarAsFunc.join(','), "}"));
|
|
121
|
+
}
|
|
122
|
+
// Component references to include in `component: { YourComponent, ... }
|
|
123
|
+
var componentsUsedInTemplate = Array.from((0, get_components_used_1.getComponentsUsed)(component))
|
|
124
|
+
.filter(function (name) { return name.length && !name.includes('.') && name[0].toUpperCase() === name[0]; })
|
|
125
|
+
// Strip out components that compile away
|
|
126
|
+
.filter(function (name) { return !['For', 'Show', 'Fragment', 'Slot', component.name].includes(name); });
|
|
127
|
+
// get default imports from component files
|
|
128
|
+
var importedComponents = component.imports
|
|
129
|
+
.filter(render_imports_1.checkIsComponentImport)
|
|
130
|
+
.map(function (imp) { var _a; return (_a = Object.entries(imp.imports).find(function (_a) {
|
|
131
|
+
var _ = _a[0], value = _a[1];
|
|
132
|
+
return value === 'default';
|
|
133
|
+
})) === null || _a === void 0 ? void 0 : _a[0]; })
|
|
134
|
+
.filter(nullable_1.checkIsDefined);
|
|
135
|
+
var componentsUsed = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], componentsUsedInTemplate, true), importedComponents, true));
|
|
136
|
+
var propsDefinition = Array.from(props).filter(function (prop) { return prop !== 'children' && prop !== 'class'; });
|
|
137
|
+
// add default props (if set)
|
|
138
|
+
if (component.defaultProps) {
|
|
139
|
+
propsDefinition = propsDefinition.reduce(function (propsDefinition, curr) {
|
|
140
|
+
var _a;
|
|
141
|
+
return ((propsDefinition[curr] = ((_a = component.defaultProps) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(curr))
|
|
142
|
+
? { default: component.defaultProps[curr] }
|
|
143
|
+
: {}),
|
|
144
|
+
propsDefinition);
|
|
145
|
+
}, {});
|
|
146
|
+
}
|
|
147
|
+
return "\n export default {\n ".concat(!component.name
|
|
148
|
+
? ''
|
|
149
|
+
: "name: '".concat(path && ((_a = options.namePrefix) === null || _a === void 0 ? void 0 : _a.call(options, path)) ? ((_b = options.namePrefix) === null || _b === void 0 ? void 0 : _b.call(options, path)) + '-' : '').concat((0, lodash_1.kebabCase)(component.name), "',"), "\n ").concat(generateComponents(componentsUsed, options), "\n ").concat(props.length ? "props: ".concat(json5_1.default.stringify(propsDefinition), ",") : '', "\n ").concat(dataString.length < 4
|
|
150
|
+
? ''
|
|
151
|
+
: "\n data: () => (".concat(dataString, "),\n "), "\n\n ").concat((0, lodash_1.size)(component.context.set)
|
|
152
|
+
? "provide() {\n const _this = this;\n return ".concat(getContextProvideString(component, options), "\n },")
|
|
153
|
+
: '', "\n ").concat((0, lodash_1.size)(component.context.get)
|
|
154
|
+
? "inject: ".concat(getContextInjectString(component, options), ",")
|
|
155
|
+
: '', "\n ").concat(((_c = component.hooks.onInit) === null || _c === void 0 ? void 0 : _c.code)
|
|
156
|
+
? "created() {\n ".concat((0, helpers_1.processBinding)({ code: component.hooks.onInit.code, options: options, json: component }), "\n },")
|
|
157
|
+
: '', "\n ").concat(((_d = component.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
|
|
158
|
+
? "mounted() {\n ".concat((0, helpers_1.processBinding)({ code: component.hooks.onMount.code, options: options, json: component }), "\n },")
|
|
159
|
+
: '', "\n ").concat(onUpdateWithoutDeps.length
|
|
160
|
+
? "updated() {\n ".concat(onUpdateWithoutDeps
|
|
161
|
+
.map(function (hook) { return (0, helpers_1.processBinding)({ code: hook.code, options: options, json: component }); })
|
|
162
|
+
.join('\n'), "\n },")
|
|
163
|
+
: '', "\n ").concat(onUpdateWithDeps.length
|
|
164
|
+
? "watch: {\n ".concat(onUpdateWithDeps
|
|
165
|
+
.map(function (hook, index) {
|
|
166
|
+
return "".concat((0, helpers_1.getOnUpdateHookName)(index), "() {\n ").concat((0, helpers_1.processBinding)({ code: hook.code, options: options, json: component }), "\n }\n ");
|
|
167
|
+
})
|
|
168
|
+
.join(','), "\n },")
|
|
169
|
+
: '', "\n ").concat(component.hooks.onUnMount
|
|
170
|
+
? "unmounted() {\n ".concat((0, helpers_1.processBinding)({
|
|
171
|
+
code: component.hooks.onUnMount.code,
|
|
172
|
+
options: options,
|
|
173
|
+
json: component,
|
|
174
|
+
}), "\n },")
|
|
175
|
+
: '', "\n\n ").concat(getterString.length < 4
|
|
176
|
+
? ''
|
|
177
|
+
: " \n computed: ".concat(getterString, ",\n "), "\n ").concat(functionsString.length < 4
|
|
178
|
+
? ''
|
|
179
|
+
: "\n methods: ".concat(functionsString, ",\n "), "\n ").concat(Object.entries(component.meta.vueConfig || {})
|
|
180
|
+
.map(function (_a) {
|
|
181
|
+
var k = _a[0], v = _a[1];
|
|
182
|
+
return "".concat(k, ": ").concat(v);
|
|
183
|
+
})
|
|
184
|
+
.join(','), "\n }");
|
|
185
|
+
}
|
|
186
|
+
exports.generateOptionsApiScript = generateOptionsApiScript;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
2
|
+
export declare type VueVersion = 2 | 3;
|
|
3
|
+
export declare type Api = 'options' | 'composition';
|
|
4
|
+
export interface VueVersionOpt {
|
|
5
|
+
vueVersion: VueVersion;
|
|
6
|
+
}
|
|
7
|
+
export interface ToVueOptions extends BaseTranspilerOptions, VueVersionOpt {
|
|
8
|
+
cssNamespace?: () => string;
|
|
9
|
+
namePrefix?: (path: string) => string;
|
|
10
|
+
asyncComponentImports?: boolean;
|
|
11
|
+
api?: Api;
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OmitObj } from '../../helpers/typescript';
|
|
2
|
+
import { ToVueOptions, VueVersionOpt } from './types';
|
|
3
|
+
declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
|
|
4
|
+
export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => import("../../types/transpiler").Transpiler<string>;
|
|
5
|
+
export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => import("../../types/transpiler").Transpiler<string>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.componentToVue3 = exports.componentToVue2 = void 0;
|
|
42
|
+
var dedent_1 = __importDefault(require("dedent"));
|
|
43
|
+
var standalone_1 = require("prettier/standalone");
|
|
44
|
+
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
45
|
+
var fast_clone_1 = require("../../helpers/fast-clone");
|
|
46
|
+
var map_refs_1 = require("../../helpers/map-refs");
|
|
47
|
+
var render_imports_1 = require("../../helpers/render-imports");
|
|
48
|
+
var get_props_1 = require("../../helpers/get-props");
|
|
49
|
+
var plugins_1 = require("../../modules/plugins");
|
|
50
|
+
var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
51
|
+
var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
52
|
+
var traverse_1 = __importDefault(require("traverse"));
|
|
53
|
+
var lodash_1 = require("lodash");
|
|
54
|
+
var process_http_requests_1 = require("../../helpers/process-http-requests");
|
|
55
|
+
var function_1 = require("fp-ts/lib/function");
|
|
56
|
+
var slots_1 = require("../../helpers/slots");
|
|
57
|
+
var functions_1 = require("../helpers/functions");
|
|
58
|
+
var helpers_1 = require("./helpers");
|
|
59
|
+
var optionsApi_1 = require("./optionsApi");
|
|
60
|
+
var compositionApi_1 = require("./compositionApi");
|
|
61
|
+
var blocks_1 = require("./blocks");
|
|
62
|
+
// Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
|
|
63
|
+
function processDynamicComponents(json, _options) {
|
|
64
|
+
(0, traverse_1.default)(json).forEach(function (node) {
|
|
65
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
66
|
+
if (node.name.includes('.')) {
|
|
67
|
+
node.bindings.is = { code: node.name };
|
|
68
|
+
node.name = 'component';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function processForKeys(json, _options) {
|
|
74
|
+
(0, traverse_1.default)(json).forEach(function (node) {
|
|
75
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
76
|
+
if (node.name === 'For') {
|
|
77
|
+
var firstChild = node.children[0];
|
|
78
|
+
if (firstChild && firstChild.bindings.key) {
|
|
79
|
+
node.bindings.key = firstChild.bindings.key;
|
|
80
|
+
delete firstChild.bindings.key;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This plugin handle `onUpdate` code that watches dependencies.
|
|
88
|
+
* We need to apply this workaround to be able to watch specific dependencies in Vue 2: https://stackoverflow.com/a/45853349
|
|
89
|
+
*
|
|
90
|
+
* We add a `computed` property for the dependencies, and a matching `watch` function for the `onUpdate` code
|
|
91
|
+
*/
|
|
92
|
+
var onUpdatePlugin = function (options) { return ({
|
|
93
|
+
json: {
|
|
94
|
+
post: function (component) {
|
|
95
|
+
if (component.hooks.onUpdate) {
|
|
96
|
+
component.hooks.onUpdate
|
|
97
|
+
.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })
|
|
98
|
+
.forEach(function (hook, index) {
|
|
99
|
+
var _a;
|
|
100
|
+
var code = "get ".concat((0, helpers_1.getOnUpdateHookName)(index), " () {\n return {\n ").concat((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.slice(1, -1).split(',').map(function (dep, k) {
|
|
101
|
+
var val = dep.trim();
|
|
102
|
+
return "".concat(k, ": ").concat(val);
|
|
103
|
+
}).join(','), "\n }\n }");
|
|
104
|
+
component.state[(0, helpers_1.getOnUpdateHookName)(index)] = {
|
|
105
|
+
code: code,
|
|
106
|
+
type: 'getter',
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}); };
|
|
113
|
+
var BASE_OPTIONS = {
|
|
114
|
+
plugins: [],
|
|
115
|
+
vueVersion: 2,
|
|
116
|
+
api: 'options',
|
|
117
|
+
};
|
|
118
|
+
var mergeOptions = function (_a, _b) {
|
|
119
|
+
var _c = _a.plugins, pluginsA = _c === void 0 ? [] : _c, a = __rest(_a, ["plugins"]);
|
|
120
|
+
var _d = _b.plugins, pluginsB = _d === void 0 ? [] : _d, b = __rest(_b, ["plugins"]);
|
|
121
|
+
return (__assign(__assign(__assign({}, a), b), { plugins: __spreadArray(__spreadArray([], pluginsA, true), pluginsB, true) }));
|
|
122
|
+
};
|
|
123
|
+
var componentToVue = function (userOptions) {
|
|
124
|
+
if (userOptions === void 0) { userOptions = BASE_OPTIONS; }
|
|
125
|
+
return function (_a) {
|
|
126
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
127
|
+
var component = _a.component, path = _a.path;
|
|
128
|
+
var options = mergeOptions(BASE_OPTIONS, userOptions);
|
|
129
|
+
if (options.api === 'options') {
|
|
130
|
+
(_b = options.plugins) === null || _b === void 0 ? void 0 : _b.unshift(onUpdatePlugin);
|
|
131
|
+
}
|
|
132
|
+
else if (options.api === 'composition') {
|
|
133
|
+
(_c = options.plugins) === null || _c === void 0 ? void 0 : _c.unshift(functions_1.FUNCTION_HACK_PLUGIN);
|
|
134
|
+
options.asyncComponentImports = false;
|
|
135
|
+
}
|
|
136
|
+
// Make a copy we can safely mutate, similar to babel's toolchain can be used
|
|
137
|
+
component = (0, fast_clone_1.fastClone)(component);
|
|
138
|
+
(0, process_http_requests_1.processHttpRequests)(component);
|
|
139
|
+
processDynamicComponents(component, options);
|
|
140
|
+
processForKeys(component, options);
|
|
141
|
+
if (options.plugins) {
|
|
142
|
+
component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
|
|
143
|
+
}
|
|
144
|
+
if (options.api === 'options') {
|
|
145
|
+
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
|
|
146
|
+
}
|
|
147
|
+
if (options.plugins) {
|
|
148
|
+
component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
|
|
149
|
+
}
|
|
150
|
+
var css = (0, collect_css_1.collectCss)(component, {
|
|
151
|
+
prefix: (_e = (_d = options.cssNamespace) === null || _d === void 0 ? void 0 : _d.call(options)) !== null && _e !== void 0 ? _e : undefined,
|
|
152
|
+
});
|
|
153
|
+
(0, strip_meta_properties_1.stripMetaProperties)(component);
|
|
154
|
+
var template = (0, function_1.pipe)(component.children.map(function (item) { return (0, blocks_1.blockToVue)(item, options, { isRootNode: true }); }).join('\n'), helpers_1.renameMitosisComponentsToKebabCase);
|
|
155
|
+
var onUpdateWithDeps = ((_f = component.hooks.onUpdate) === null || _f === void 0 ? void 0 : _f.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })) || [];
|
|
156
|
+
var onUpdateWithoutDeps = ((_g = component.hooks.onUpdate) === null || _g === void 0 ? void 0 : _g.filter(function (hook) { var _a; return !((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length); })) || [];
|
|
157
|
+
var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
|
|
158
|
+
var elementProps = Array.from((0, get_props_1.getProps)(component)).filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
|
|
159
|
+
// import from vue
|
|
160
|
+
var vueImports = [];
|
|
161
|
+
if (options.vueVersion >= 3 && options.asyncComponentImports) {
|
|
162
|
+
vueImports.push('defineAsyncComponent');
|
|
163
|
+
}
|
|
164
|
+
if (options.api === 'composition') {
|
|
165
|
+
onUpdateWithDeps.length && vueImports.push('watch');
|
|
166
|
+
((_h = component.hooks.onMount) === null || _h === void 0 ? void 0 : _h.code) && vueImports.push('onMounted');
|
|
167
|
+
((_j = component.hooks.onUnMount) === null || _j === void 0 ? void 0 : _j.code) && vueImports.push('onUnMounted');
|
|
168
|
+
onUpdateWithoutDeps.length && vueImports.push('onUpdated');
|
|
169
|
+
(0, lodash_1.size)(getterKeys) && vueImports.push('computed');
|
|
170
|
+
(0, lodash_1.size)(component.context.set) && vueImports.push('provide');
|
|
171
|
+
(0, lodash_1.size)(component.context.get) && vueImports.push('inject');
|
|
172
|
+
(0, lodash_1.size)(Object.keys(component.state).filter(function (key) { var _a; return ((_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; })) && vueImports.push('ref');
|
|
173
|
+
}
|
|
174
|
+
var tsLangAttribute = options.typescript ? "lang='ts'" : '';
|
|
175
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "], ["\n <template>\n ", "\n </template>\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "])), template, options.api === 'composition' ? 'setup' : '', tsLangAttribute, vueImports.length ? "import { ".concat((0, lodash_1.uniq)(vueImports).sort().join(', '), " } from \"vue\"") : '', (options.typescript && ((_k = component.types) === null || _k === void 0 ? void 0 : _k.join('\n'))) || '', (0, render_imports_1.renderPreComponent)({
|
|
176
|
+
component: component,
|
|
177
|
+
target: 'vue',
|
|
178
|
+
asyncComponentImports: options.asyncComponentImports,
|
|
179
|
+
}), options.api === 'composition'
|
|
180
|
+
? (0, compositionApi_1.generateCompositionApiScript)(component, options, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps)
|
|
181
|
+
: (0, optionsApi_1.generateOptionsApiScript)(component, options, path, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps), !css.trim().length
|
|
182
|
+
? ''
|
|
183
|
+
: "<style scoped>\n ".concat(css, "\n </style>"));
|
|
184
|
+
if (options.plugins) {
|
|
185
|
+
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
186
|
+
}
|
|
187
|
+
if (true || options.prettier !== false) {
|
|
188
|
+
try {
|
|
189
|
+
str = (0, standalone_1.format)(str, {
|
|
190
|
+
parser: 'vue',
|
|
191
|
+
plugins: [
|
|
192
|
+
// To support running in browsers
|
|
193
|
+
require('prettier/parser-typescript'),
|
|
194
|
+
require('prettier/parser-html'),
|
|
195
|
+
require('prettier/parser-postcss'),
|
|
196
|
+
require('prettier/parser-babel'),
|
|
197
|
+
],
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (options.plugins) {
|
|
205
|
+
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
206
|
+
}
|
|
207
|
+
for (var _i = 0, removePatterns_1 = removePatterns; _i < removePatterns_1.length; _i++) {
|
|
208
|
+
var pattern = removePatterns_1[_i];
|
|
209
|
+
str = str.replace(pattern, '');
|
|
210
|
+
}
|
|
211
|
+
return str;
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
var componentToVue2 = function (vueOptions) {
|
|
215
|
+
return componentToVue(__assign(__assign({}, vueOptions), { vueVersion: 2 }));
|
|
216
|
+
};
|
|
217
|
+
exports.componentToVue2 = componentToVue2;
|
|
218
|
+
var componentToVue3 = function (vueOptions) {
|
|
219
|
+
return componentToVue(__assign(__assign({}, vueOptions), { vueVersion: 3 }));
|
|
220
|
+
};
|
|
221
|
+
exports.componentToVue3 = componentToVue3;
|
|
222
|
+
// Remove unused artifacts like empty script or style tags
|
|
223
|
+
var removePatterns = [
|
|
224
|
+
"<script>\nexport default {};\n</script>",
|
|
225
|
+
"<style>\n</style>",
|
|
226
|
+
];
|
|
227
|
+
var templateObject_1;
|
|
@@ -1,21 +1,24 @@
|
|
|
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 renderImport: ({ theImport, target, asyncComponentImports, }: {
|
|
4
|
+
export declare const renderImport: ({ theImport, target, asyncComponentImports, preserveFileExtensions, }: {
|
|
5
5
|
theImport: MitosisImport;
|
|
6
6
|
target: Target;
|
|
7
7
|
asyncComponentImports: boolean;
|
|
8
|
+
preserveFileExtensions?: boolean | undefined;
|
|
8
9
|
}) => string;
|
|
9
|
-
export declare const renderImports: ({ imports, target, asyncComponentImports, excludeMitosisComponents, }: {
|
|
10
|
+
export declare const renderImports: ({ imports, target, asyncComponentImports, excludeMitosisComponents, preserveFileExtensions, }: {
|
|
10
11
|
imports: MitosisImport[];
|
|
11
12
|
target: Target;
|
|
12
13
|
asyncComponentImports: boolean;
|
|
13
14
|
excludeMitosisComponents?: boolean | undefined;
|
|
15
|
+
preserveFileExtensions?: boolean | undefined;
|
|
14
16
|
}) => string;
|
|
15
|
-
export declare const renderPreComponent: ({ component, target, excludeMitosisComponents, asyncComponentImports, }: {
|
|
17
|
+
export declare const renderPreComponent: ({ component, target, excludeMitosisComponents, asyncComponentImports, preserveFileExtensions, }: {
|
|
16
18
|
component: MitosisComponent;
|
|
17
19
|
target: Target;
|
|
18
20
|
asyncComponentImports?: boolean | undefined;
|
|
19
21
|
excludeMitosisComponents?: boolean | undefined;
|
|
22
|
+
preserveFileExtensions?: boolean | undefined;
|
|
20
23
|
}) => string;
|
|
21
24
|
export declare const renderExportAndLocal: (component: MitosisComponent) => string;
|
|
@@ -40,7 +40,8 @@ var getFileExtensionForTarget = function (target) {
|
|
|
40
40
|
case 'angular':
|
|
41
41
|
return '';
|
|
42
42
|
// these `.lite` extensions are handled in the `transpile` step of the CLI.
|
|
43
|
-
// TO-DO: consolidate file-extension renaming to this file, and remove `.lite` replaces from the CLI `transpile`.
|
|
43
|
+
// TO-DO: consolidate file-extension renaming to this file, and remove `.lite` replaces from the CLI `transpile`. (outdated) ?
|
|
44
|
+
// Bit team wanted to make sure React and Angular behaved the same in regards to imports - ALU 10/05/22
|
|
44
45
|
default:
|
|
45
46
|
return '.lite';
|
|
46
47
|
}
|
|
@@ -49,12 +50,12 @@ var checkIsComponentImport = function (theImport) {
|
|
|
49
50
|
return theImport.path.endsWith('.lite') && !theImport.path.endsWith('.context.lite');
|
|
50
51
|
};
|
|
51
52
|
exports.checkIsComponentImport = checkIsComponentImport;
|
|
52
|
-
var transformImportPath = function (theImport, target) {
|
|
53
|
+
var transformImportPath = function (theImport, target, preserveFileExtensions) {
|
|
53
54
|
// We need to drop the `.lite` from context files, because the context generator does so as well.
|
|
54
55
|
if (theImport.path.endsWith('.context.lite')) {
|
|
55
56
|
return theImport.path.replace('.lite', '.js');
|
|
56
57
|
}
|
|
57
|
-
if ((0, exports.checkIsComponentImport)(theImport)) {
|
|
58
|
+
if ((0, exports.checkIsComponentImport)(theImport) && !preserveFileExtensions) {
|
|
58
59
|
return theImport.path.replace('.lite', getFileExtensionForTarget(target));
|
|
59
60
|
}
|
|
60
61
|
return theImport.path;
|
|
@@ -94,9 +95,9 @@ var getImportValue = function (_a) {
|
|
|
94
95
|
}
|
|
95
96
|
};
|
|
96
97
|
var renderImport = function (_a) {
|
|
97
|
-
var theImport = _a.theImport, target = _a.target, asyncComponentImports = _a.asyncComponentImports;
|
|
98
|
+
var theImport = _a.theImport, target = _a.target, asyncComponentImports = _a.asyncComponentImports, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b;
|
|
98
99
|
var importedValues = getImportedValues({ theImport: theImport });
|
|
99
|
-
var path = transformImportPath(theImport, target);
|
|
100
|
+
var path = transformImportPath(theImport, target, preserveFileExtensions);
|
|
100
101
|
var importValue = getImportValue(importedValues);
|
|
101
102
|
var isComponentImport = (0, exports.checkIsComponentImport)(theImport);
|
|
102
103
|
var shouldBeAsyncImport = asyncComponentImports && isComponentImport;
|
|
@@ -118,7 +119,7 @@ var renderImport = function (_a) {
|
|
|
118
119
|
};
|
|
119
120
|
exports.renderImport = renderImport;
|
|
120
121
|
var renderImports = function (_a) {
|
|
121
|
-
var imports = _a.imports, target = _a.target, asyncComponentImports = _a.asyncComponentImports, excludeMitosisComponents = _a.excludeMitosisComponents;
|
|
122
|
+
var imports = _a.imports, target = _a.target, asyncComponentImports = _a.asyncComponentImports, excludeMitosisComponents = _a.excludeMitosisComponents, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b;
|
|
122
123
|
return imports
|
|
123
124
|
.filter(function (theImport) {
|
|
124
125
|
if (
|
|
@@ -135,18 +136,21 @@ var renderImports = function (_a) {
|
|
|
135
136
|
return true;
|
|
136
137
|
}
|
|
137
138
|
})
|
|
138
|
-
.map(function (theImport) {
|
|
139
|
+
.map(function (theImport) {
|
|
140
|
+
return (0, exports.renderImport)({ theImport: theImport, target: target, asyncComponentImports: asyncComponentImports, preserveFileExtensions: preserveFileExtensions });
|
|
141
|
+
})
|
|
139
142
|
.join('\n');
|
|
140
143
|
};
|
|
141
144
|
exports.renderImports = renderImports;
|
|
142
145
|
var renderPreComponent = function (_a) {
|
|
143
146
|
var _b;
|
|
144
|
-
var component = _a.component, target = _a.target, excludeMitosisComponents = _a.excludeMitosisComponents, _c = _a.asyncComponentImports, asyncComponentImports = _c === void 0 ? false : _c;
|
|
147
|
+
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;
|
|
145
148
|
return "\n ".concat((0, exports.renderImports)({
|
|
146
149
|
imports: component.imports,
|
|
147
150
|
target: target,
|
|
148
151
|
asyncComponentImports: asyncComponentImports,
|
|
149
152
|
excludeMitosisComponents: excludeMitosisComponents,
|
|
153
|
+
preserveFileExtensions: preserveFileExtensions,
|
|
150
154
|
}), "\n ").concat((0, exports.renderExportAndLocal)(component), "\n ").concat(((_b = component.hooks.preComponent) === null || _b === void 0 ? void 0 : _b.code) || '', "\n ");
|
|
151
155
|
};
|
|
152
156
|
exports.renderPreComponent = renderPreComponent;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export * from './generators/context/solid';
|
|
|
43
43
|
export * from './generators/context/vue';
|
|
44
44
|
export * from './generators/context/svelte';
|
|
45
45
|
export * from './generators/react';
|
|
46
|
+
export * from './generators/rsc';
|
|
46
47
|
export * from './generators/solid';
|
|
47
48
|
export * from './generators/liquid';
|
|
48
49
|
export * from './generators/builder';
|
package/dist/src/index.js
CHANGED
|
@@ -81,6 +81,7 @@ __exportStar(require("./generators/context/solid"), exports);
|
|
|
81
81
|
__exportStar(require("./generators/context/vue"), exports);
|
|
82
82
|
__exportStar(require("./generators/context/svelte"), exports);
|
|
83
83
|
__exportStar(require("./generators/react"), exports);
|
|
84
|
+
__exportStar(require("./generators/rsc"), exports);
|
|
84
85
|
__exportStar(require("./generators/solid"), exports);
|
|
85
86
|
__exportStar(require("./generators/liquid"), exports);
|
|
86
87
|
__exportStar(require("./generators/builder"), exports);
|
package/dist/src/targets.d.ts
CHANGED
|
@@ -20,4 +20,5 @@ export declare const targets: {
|
|
|
20
20
|
readonly marko: import(".").TranspilerGenerator<import("./generators/marko").ToMarkoOptions, string>;
|
|
21
21
|
readonly preact: import(".").TranspilerGenerator<import("./generators/react").ToReactOptions, string>;
|
|
22
22
|
readonly lit: import(".").TranspilerGenerator<import("./generators/lit").ToLitOptions, string>;
|
|
23
|
+
readonly rsc: import(".").TranspilerGenerator<import("./generators/rsc").ToRscOptions, string>;
|
|
23
24
|
};
|
package/dist/src/targets.js
CHANGED
|
@@ -18,6 +18,7 @@ var stencil_1 = require("./generators/stencil");
|
|
|
18
18
|
var qwik_1 = require("./generators/qwik");
|
|
19
19
|
var marko_1 = require("./generators/marko");
|
|
20
20
|
var lit_1 = require("./generators/lit");
|
|
21
|
+
var rsc_1 = require("./generators/rsc");
|
|
21
22
|
exports.builder = builder_1.componentToBuilder;
|
|
22
23
|
exports.targets = {
|
|
23
24
|
angular: angular_1.componentToAngular,
|
|
@@ -40,4 +41,5 @@ exports.targets = {
|
|
|
40
41
|
marko: marko_1.componentToMarko,
|
|
41
42
|
preact: react_2.componentToPreact,
|
|
42
43
|
lit: lit_1.componentToLit,
|
|
44
|
+
rsc: rsc_1.componentToRsc,
|
|
43
45
|
};
|