@builder.io/mitosis 0.1.6 → 0.2.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/helpers.d.ts +4 -0
- package/dist/src/generators/angular/helpers.js +13 -0
- package/dist/src/generators/angular/index.d.ts +5 -0
- package/dist/src/generators/{angular.js → angular/index.js} +273 -103
- package/dist/src/generators/angular/types.d.ts +14 -0
- package/dist/src/generators/angular/types.js +8 -0
- package/dist/src/generators/context/angular.d.ts +9 -0
- package/dist/src/generators/context/angular.js +32 -0
- package/dist/src/generators/solid/index.js +5 -1
- package/dist/src/helpers/component-file-extensions.d.ts +9 -0
- package/dist/src/helpers/component-file-extensions.js +42 -4
- package/dist/src/helpers/get-props.js +12 -17
- package/dist/src/helpers/replace-identifiers.js +5 -4
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -1
- package/dist/src/targets.d.ts +1 -1
- package/dist/src/types/metadata.d.ts +3 -0
- package/package.json +1 -1
- package/dist/src/generators/angular.d.ts +0 -15
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAppropriateTemplateFunctionKeys = exports.HELPER_FUNCTIONS = void 0;
|
|
4
|
+
exports.HELPER_FUNCTIONS = {
|
|
5
|
+
useObjectWrapper: "useObjectWrapper(...args: any[]) {\n let obj = {}\n args.forEach((arg) => {\n obj = { ...obj, ...arg };\n });\n return obj;\n }",
|
|
6
|
+
useObjectDotValues: "useObjectDotValues(obj: any): any[] {\n return Object.values(obj);\n }",
|
|
7
|
+
useTypeOf: "useTypeOf(obj: any): string {\n return typeof obj;\n }",
|
|
8
|
+
useJsonStringify: "useJsonStringify(obj: any): string {\n return JSON.stringify(obj);\n }",
|
|
9
|
+
};
|
|
10
|
+
var getAppropriateTemplateFunctionKeys = function (code) {
|
|
11
|
+
return Object.keys(exports.HELPER_FUNCTIONS).filter(function (key) { return code.includes(key); });
|
|
12
|
+
};
|
|
13
|
+
exports.getAppropriateTemplateFunctionKeys = getAppropriateTemplateFunctionKeys;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
|
+
import { TranspilerGenerator } from '../../types/transpiler';
|
|
3
|
+
import { AngularBlockOptions, ToAngularOptions } from './types';
|
|
4
|
+
export declare const blockToAngular: (json: MitosisNode, options?: ToAngularOptions, blockOptions?: AngularBlockOptions) => string;
|
|
5
|
+
export declare const componentToAngular: TranspilerGenerator<ToAngularOptions>;
|
|
@@ -28,39 +28,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.componentToAngular = exports.blockToAngular = void 0;
|
|
31
|
+
var html_tags_1 = require("../../constants/html_tags");
|
|
32
|
+
var dedent_1 = require("../../helpers/dedent");
|
|
33
|
+
var fast_clone_1 = require("../../helpers/fast-clone");
|
|
34
|
+
var get_components_used_1 = require("../../helpers/get-components-used");
|
|
35
|
+
var get_custom_imports_1 = require("../../helpers/get-custom-imports");
|
|
36
|
+
var get_prop_functions_1 = require("../../helpers/get-prop-functions");
|
|
37
|
+
var get_props_1 = require("../../helpers/get-props");
|
|
38
|
+
var get_props_ref_1 = require("../../helpers/get-props-ref");
|
|
39
|
+
var get_refs_1 = require("../../helpers/get-refs");
|
|
40
|
+
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
41
|
+
var indent_1 = require("../../helpers/indent");
|
|
42
|
+
var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
43
|
+
var is_upper_case_1 = require("../../helpers/is-upper-case");
|
|
44
|
+
var map_refs_1 = require("../../helpers/map-refs");
|
|
45
|
+
var merge_options_1 = require("../../helpers/merge-options");
|
|
46
|
+
var process_code_1 = require("../../helpers/plugins/process-code");
|
|
47
|
+
var remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
|
|
48
|
+
var render_imports_1 = require("../../helpers/render-imports");
|
|
49
|
+
var replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
50
|
+
var slots_1 = require("../../helpers/slots");
|
|
51
|
+
var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
52
|
+
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
53
|
+
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
54
|
+
var helpers_1 = require("../../helpers/styles/helpers");
|
|
55
|
+
var plugins_1 = require("../../modules/plugins");
|
|
56
|
+
var mitosis_node_1 = require("../../types/mitosis-node");
|
|
31
57
|
var function_1 = require("fp-ts/lib/function");
|
|
32
58
|
var lodash_1 = require("lodash");
|
|
33
59
|
var standalone_1 = require("prettier/standalone");
|
|
34
|
-
var html_tags_1 = require("../constants/html_tags");
|
|
35
|
-
var dedent_1 = require("../helpers/dedent");
|
|
36
|
-
var fast_clone_1 = require("../helpers/fast-clone");
|
|
37
|
-
var get_components_used_1 = require("../helpers/get-components-used");
|
|
38
|
-
var get_custom_imports_1 = require("../helpers/get-custom-imports");
|
|
39
|
-
var get_prop_functions_1 = require("../helpers/get-prop-functions");
|
|
40
|
-
var get_props_1 = require("../helpers/get-props");
|
|
41
|
-
var get_props_ref_1 = require("../helpers/get-props-ref");
|
|
42
|
-
var get_refs_1 = require("../helpers/get-refs");
|
|
43
|
-
var get_state_object_string_1 = require("../helpers/get-state-object-string");
|
|
44
|
-
var indent_1 = require("../helpers/indent");
|
|
45
|
-
var is_children_1 = __importDefault(require("../helpers/is-children"));
|
|
46
|
-
var is_upper_case_1 = require("../helpers/is-upper-case");
|
|
47
|
-
var map_refs_1 = require("../helpers/map-refs");
|
|
48
|
-
var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
|
|
49
|
-
var render_imports_1 = require("../helpers/render-imports");
|
|
50
|
-
var replace_identifiers_1 = require("../helpers/replace-identifiers");
|
|
51
|
-
var slots_1 = require("../helpers/slots");
|
|
52
|
-
var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
|
|
53
|
-
var strip_state_and_props_refs_1 = require("../helpers/strip-state-and-props-refs");
|
|
54
|
-
var collect_css_1 = require("../helpers/styles/collect-css");
|
|
55
|
-
var plugins_1 = require("../modules/plugins");
|
|
56
|
-
var mitosis_node_1 = require("../types/mitosis-node");
|
|
57
|
-
var helpers_1 = require("../helpers/styles/helpers");
|
|
58
60
|
var traverse_1 = __importDefault(require("traverse"));
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment', 'Slot']);
|
|
61
|
+
var is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
62
|
+
var on_mount_1 = require("../helpers/on-mount");
|
|
63
|
+
var helpers_2 = require("./helpers");
|
|
64
|
+
var types_1 = require("./types");
|
|
64
65
|
var mappers = {
|
|
65
66
|
Fragment: function (json, options) {
|
|
66
67
|
return "<ng-container>".concat(json.children
|
|
@@ -90,7 +91,7 @@ var mappers = {
|
|
|
90
91
|
var preprocessCssAsJson = function (json) {
|
|
91
92
|
(0, traverse_1.default)(json).forEach(function (item) {
|
|
92
93
|
var _a, _b;
|
|
93
|
-
if ((0,
|
|
94
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
94
95
|
if ((0, helpers_1.nodeHasCss)(item)) {
|
|
95
96
|
if ((_b = (_a = item.bindings.css) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.includes('"')) {
|
|
96
97
|
item.bindings.css.code = item.bindings.css.code.replace(/"/g, '"');
|
|
@@ -107,12 +108,160 @@ var BINDINGS_MAPPER = {
|
|
|
107
108
|
innerHTML: 'innerHTML',
|
|
108
109
|
style: 'ngStyle',
|
|
109
110
|
};
|
|
111
|
+
var handleObjectBindings = function (code) {
|
|
112
|
+
var objectCode = code.replace(/^{/, '').replace(/}$/, '');
|
|
113
|
+
objectCode = objectCode.replace(/\/\/.*\n/g, '');
|
|
114
|
+
var spreadOutObjects = objectCode
|
|
115
|
+
.split(',')
|
|
116
|
+
.filter(function (item) { return item.includes('...'); })
|
|
117
|
+
.map(function (item) { return item.replace('...', '').trim(); });
|
|
118
|
+
var objectKeys = objectCode
|
|
119
|
+
.split(',')
|
|
120
|
+
.filter(function (item) { return !item.includes('...'); })
|
|
121
|
+
.map(function (item) { return item.trim(); });
|
|
122
|
+
var otherObjs = objectKeys.map(function (item) {
|
|
123
|
+
return "{ ".concat(item, " }");
|
|
124
|
+
});
|
|
125
|
+
var temp = "".concat(spreadOutObjects.join(', '), ", ").concat(otherObjs.join(', '));
|
|
126
|
+
if (temp.endsWith(', ')) {
|
|
127
|
+
temp = temp.slice(0, -2);
|
|
128
|
+
}
|
|
129
|
+
if (temp.startsWith(', ')) {
|
|
130
|
+
temp = temp.slice(2);
|
|
131
|
+
}
|
|
132
|
+
// handle template strings
|
|
133
|
+
if (temp.includes('`')) {
|
|
134
|
+
// template str
|
|
135
|
+
var str = temp.match(/`[^`]*`/g);
|
|
136
|
+
var values = str && str[0].match(/\${[^}]*}/g);
|
|
137
|
+
var forValues = values === null || values === void 0 ? void 0 : values.map(function (val) { return val.slice(2, -1); }).join(' + ');
|
|
138
|
+
if (str && forValues) {
|
|
139
|
+
temp = temp.replace(str[0], forValues);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return temp;
|
|
143
|
+
};
|
|
144
|
+
var processCodeBlockInTemplate = function (code) {
|
|
145
|
+
// contains helper calls as Angular doesn't support JS expressions in templates
|
|
146
|
+
if (code.startsWith('{')) {
|
|
147
|
+
// Objects cannot be spread out directly in Angular so we need to use `useObjectWrapper`
|
|
148
|
+
return "\"useObjectWrapper(".concat(handleObjectBindings(code), ")\" ");
|
|
149
|
+
}
|
|
150
|
+
else if (code.startsWith('Object.values')) {
|
|
151
|
+
var stripped = code.replace('Object.values', '');
|
|
152
|
+
return "\"useObjectDotValues".concat(stripped, "\" ");
|
|
153
|
+
}
|
|
154
|
+
else if (code.includes('JSON.stringify')) {
|
|
155
|
+
var obj = code.match(/JSON.stringify\([^)]*\)/g);
|
|
156
|
+
return "\"useJsonStringify(".concat(obj, ")\" ");
|
|
157
|
+
}
|
|
158
|
+
else if (code.includes(' as ')) {
|
|
159
|
+
var asIndex = code.indexOf('as');
|
|
160
|
+
var asCode = code.slice(0, asIndex - 1);
|
|
161
|
+
return "\"$any".concat(asCode, ")\"");
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return "\"".concat(code, "\" ");
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var processEventBinding = function (key, code, nodeName, customArg) {
|
|
168
|
+
var event = key.replace('on', '');
|
|
169
|
+
event = event.charAt(0).toLowerCase() + event.slice(1);
|
|
170
|
+
if (event === 'change' && nodeName === 'input' /* todo: other tags */) {
|
|
171
|
+
event = 'input';
|
|
172
|
+
}
|
|
173
|
+
// TODO: proper babel transform to replace. Util for this
|
|
174
|
+
var eventName = customArg;
|
|
175
|
+
var regexp = new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + eventName + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g');
|
|
176
|
+
var replacer = '$1$event$2';
|
|
177
|
+
var finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(code.replace(regexp, replacer));
|
|
178
|
+
return " (".concat(event, ")=\"").concat(finalValue, "\" ");
|
|
179
|
+
};
|
|
180
|
+
var stringifyBinding = function (node, options, blockOptions) {
|
|
181
|
+
return function (_a) {
|
|
182
|
+
var key = _a[0], binding = _a[1];
|
|
183
|
+
if ((binding === null || binding === void 0 ? void 0 : binding.type) === 'spread') {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (key.startsWith('$')) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (key === 'key') {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (key === 'attributes') {
|
|
193
|
+
// TODO: contains ternary operator which needs to be handled
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
var keyToUse = BINDINGS_MAPPER[key] || key;
|
|
197
|
+
var _b = binding, code = _b.code, _c = _b.arguments, cusArgs = _c === void 0 ? ['event'] : _c;
|
|
198
|
+
// TODO: proper babel transform to replace. Util for this
|
|
199
|
+
if (keyToUse.startsWith('on')) {
|
|
200
|
+
return processEventBinding(keyToUse, code, node.name, cusArgs[0]);
|
|
201
|
+
}
|
|
202
|
+
else if (keyToUse === 'class') {
|
|
203
|
+
return " [class]=\"".concat(code, "\" ");
|
|
204
|
+
}
|
|
205
|
+
else if (keyToUse === 'ref') {
|
|
206
|
+
return " #".concat(code, " ");
|
|
207
|
+
}
|
|
208
|
+
else if ((html_tags_1.VALID_HTML_TAGS.includes(node.name.trim()) || keyToUse.includes('-')) &&
|
|
209
|
+
!blockOptions.nativeAttributes.includes(keyToUse) &&
|
|
210
|
+
!Object.values(BINDINGS_MAPPER).includes(keyToUse)) {
|
|
211
|
+
// standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
|
|
212
|
+
return " [attr.".concat(keyToUse, "]=\"").concat(code, "\" ");
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
return "[".concat(keyToUse, "]=").concat(processCodeBlockInTemplate(code));
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
var handleNgOutletBindings = function (node) {
|
|
220
|
+
var allProps = '';
|
|
221
|
+
var events = '';
|
|
222
|
+
for (var key in node.bindings) {
|
|
223
|
+
if (key.startsWith('"')) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (key.startsWith('$')) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
var _a = node.bindings[key], code = _a.code, _b = _a.arguments, cusArgs = _b === void 0 ? ['event'] : _b;
|
|
230
|
+
if (code.includes('?')) {
|
|
231
|
+
// TODO handle ternary
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
else if (key.includes('props.')) {
|
|
235
|
+
allProps += "".concat(key.replace('props.', ''), ": ").concat(code, ", ");
|
|
236
|
+
}
|
|
237
|
+
else if (key.includes('.')) {
|
|
238
|
+
// TODO: handle arbitrary spread props
|
|
239
|
+
allProps += "".concat(key.split('.')[1], ": ").concat(code, ",");
|
|
240
|
+
}
|
|
241
|
+
else if (key.startsWith('on')) {
|
|
242
|
+
events += processEventBinding(key, code, node.name, cusArgs[0]);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
var codeToUse = processCodeBlockInTemplate(code);
|
|
246
|
+
var keyToUse = key.includes('-') ? "'".concat(key, "'") : key;
|
|
247
|
+
allProps += "".concat(keyToUse, ": ").concat(codeToUse, ", ");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (allProps.endsWith(', ')) {
|
|
251
|
+
allProps = allProps.slice(0, -2);
|
|
252
|
+
}
|
|
253
|
+
if (allProps.startsWith(', ')) {
|
|
254
|
+
allProps = allProps.slice(2);
|
|
255
|
+
}
|
|
256
|
+
return [allProps, events];
|
|
257
|
+
};
|
|
110
258
|
var blockToAngular = function (json, options, blockOptions) {
|
|
111
|
-
var _a, _b, _c
|
|
259
|
+
var _a, _b, _c;
|
|
112
260
|
if (options === void 0) { options = {}; }
|
|
113
|
-
if (blockOptions === void 0) { blockOptions = {
|
|
261
|
+
if (blockOptions === void 0) { blockOptions = {
|
|
262
|
+
nativeAttributes: [],
|
|
263
|
+
}; }
|
|
114
264
|
var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
115
|
-
var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name.trim());
|
|
116
265
|
if (mappers[json.name]) {
|
|
117
266
|
return mappers[json.name](json, options);
|
|
118
267
|
}
|
|
@@ -128,10 +277,14 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
128
277
|
var selector = (0, function_1.pipe)(textCode, slots_1.stripSlotPrefix, lodash_1.kebabCase);
|
|
129
278
|
return "<ng-content select=\"[".concat(selector, "]\"></ng-content>");
|
|
130
279
|
}
|
|
280
|
+
if (textCode.includes('JSON.stringify')) {
|
|
281
|
+
var obj = textCode.replace('JSON.stringify', '');
|
|
282
|
+
obj = obj.replace(/\(.*?\)/, '');
|
|
283
|
+
return "{{useJsonStringify".concat(obj, "}}");
|
|
284
|
+
}
|
|
131
285
|
return "{{".concat(textCode, "}}");
|
|
132
286
|
}
|
|
133
287
|
var str = '';
|
|
134
|
-
var needsToRenderSlots = [];
|
|
135
288
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
136
289
|
var indexName = json.scope.indexName;
|
|
137
290
|
str += "<ng-container *ngFor=\"let ".concat(json.scope.forName, " of ").concat((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
|
|
@@ -139,10 +292,23 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
139
292
|
str += "</ng-container>";
|
|
140
293
|
}
|
|
141
294
|
else if (json.name === 'Show') {
|
|
142
|
-
|
|
295
|
+
var condition = (_c = json.bindings.when) === null || _c === void 0 ? void 0 : _c.code;
|
|
296
|
+
if (condition === null || condition === void 0 ? void 0 : condition.includes('typeof')) {
|
|
297
|
+
var wordAfterTypeof = condition.split('typeof')[1].trim();
|
|
298
|
+
condition = condition.replace("typeof ".concat(wordAfterTypeof), "useTypeOf(".concat(wordAfterTypeof, ")"));
|
|
299
|
+
}
|
|
300
|
+
str += "<ng-container *ngIf=\"".concat(condition, "\">");
|
|
143
301
|
str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
|
|
144
302
|
str += "</ng-container>";
|
|
145
303
|
}
|
|
304
|
+
else if (json.name.includes('.')) {
|
|
305
|
+
var elSelector = childComponents.find(function (impName) { return impName === json.name; })
|
|
306
|
+
? (0, lodash_1.kebabCase)(json.name)
|
|
307
|
+
: json.name;
|
|
308
|
+
var _d = handleNgOutletBindings(json), allProps = _d[0], events = _d[1];
|
|
309
|
+
str += "<ng-container ".concat(events, " *ngComponentOutlet=\"\n ").concat(elSelector.replace('state.', '').replace('props.', ''), ";\n inputs: { ").concat(allProps, " };\n content: myContent;\n \"> ");
|
|
310
|
+
str += "</ng-container>";
|
|
311
|
+
}
|
|
146
312
|
else {
|
|
147
313
|
var elSelector = childComponents.find(function (impName) { return impName === json.name; })
|
|
148
314
|
? (0, lodash_1.kebabCase)(json.name)
|
|
@@ -161,56 +327,14 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
161
327
|
var value = json.properties[key];
|
|
162
328
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
163
329
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (key.startsWith('$')) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f;
|
|
172
|
-
// TODO: proper babel transform to replace. Util for this
|
|
173
|
-
if (key.startsWith('on')) {
|
|
174
|
-
var event_1 = key.replace('on', '');
|
|
175
|
-
event_1 = event_1.charAt(0).toLowerCase() + event_1.slice(1);
|
|
176
|
-
if (event_1 === 'change' && json.name === 'input' /* todo: other tags */) {
|
|
177
|
-
event_1 = 'input';
|
|
178
|
-
}
|
|
179
|
-
// TODO: proper babel transform to replace. Util for this
|
|
180
|
-
var eventName = cusArgs[0];
|
|
181
|
-
var regexp = new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + eventName + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g');
|
|
182
|
-
var replacer = '$1$event$2';
|
|
183
|
-
var finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(code.replace(regexp, replacer));
|
|
184
|
-
str += " (".concat(event_1, ")=\"").concat(finalValue, "\" ");
|
|
185
|
-
}
|
|
186
|
-
else if (key === 'class') {
|
|
187
|
-
str += " [class]=\"".concat(code, "\" ");
|
|
188
|
-
}
|
|
189
|
-
else if (key === 'ref') {
|
|
190
|
-
str += " #".concat(code, " ");
|
|
191
|
-
}
|
|
192
|
-
else if ((0, slots_1.isSlotProperty)(key)) {
|
|
193
|
-
var lowercaseKey = (0, function_1.pipe)(key, slots_1.stripSlotPrefix, function (x) { return x.toLowerCase(); });
|
|
194
|
-
needsToRenderSlots.push("".concat(code.replace(/(\/\>)|\>/, " ".concat(lowercaseKey, ">"))));
|
|
195
|
-
}
|
|
196
|
-
else if (BINDINGS_MAPPER[key]) {
|
|
197
|
-
str += " [".concat(BINDINGS_MAPPER[key], "]=\"").concat(code, "\" ");
|
|
198
|
-
}
|
|
199
|
-
else if (isValidHtmlTag || key.includes('-')) {
|
|
200
|
-
// standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
|
|
201
|
-
str += " [attr.".concat(key, "]=\"").concat(code, "\" ");
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
str += "[".concat(key, "]=\"").concat(code, "\" ");
|
|
205
|
-
}
|
|
206
|
-
}
|
|
330
|
+
var stringifiedBindings = Object.entries(json.bindings)
|
|
331
|
+
.map(stringifyBinding(json, options, blockOptions))
|
|
332
|
+
.join('');
|
|
333
|
+
str += stringifiedBindings;
|
|
207
334
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
208
335
|
return str + ' />';
|
|
209
336
|
}
|
|
210
337
|
str += '>';
|
|
211
|
-
if (needsToRenderSlots.length > 0) {
|
|
212
|
-
str += needsToRenderSlots.map(function (el) { return el; }).join('');
|
|
213
|
-
}
|
|
214
338
|
if (json.children) {
|
|
215
339
|
str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
|
|
216
340
|
}
|
|
@@ -219,6 +343,23 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
219
343
|
return str;
|
|
220
344
|
};
|
|
221
345
|
exports.blockToAngular = blockToAngular;
|
|
346
|
+
var traverseToGetAllDynamicComponents = function (json, options, blockOptions) {
|
|
347
|
+
var components = new Set();
|
|
348
|
+
var dynamicTemplate = '';
|
|
349
|
+
(0, traverse_1.default)(json).forEach(function (item) {
|
|
350
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item) && item.name.includes('.') && item.name.split('.').length === 2) {
|
|
351
|
+
var children = item.children
|
|
352
|
+
.map(function (child) { return (0, exports.blockToAngular)(child, options, blockOptions); })
|
|
353
|
+
.join('\n');
|
|
354
|
+
dynamicTemplate = "<ng-template #".concat(item.name.split('.')[1].toLowerCase() + 'Template', ">").concat(children, "</ng-template>");
|
|
355
|
+
components.add(item.name);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return {
|
|
359
|
+
components: components,
|
|
360
|
+
dynamicTemplate: dynamicTemplate,
|
|
361
|
+
};
|
|
362
|
+
};
|
|
222
363
|
var processAngularCode = function (_a) {
|
|
223
364
|
var contextVars = _a.contextVars, outputVars = _a.outputVars, domRefs = _a.domRefs, stateVars = _a.stateVars, replaceWith = _a.replaceWith;
|
|
224
365
|
return function (code) {
|
|
@@ -230,25 +371,23 @@ var processAngularCode = function (_a) {
|
|
|
230
371
|
}), function (newCode) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, { replaceWith: replaceWith }); });
|
|
231
372
|
};
|
|
232
373
|
};
|
|
233
|
-
var DEFAULT_OPTIONS = {
|
|
234
|
-
preserveImports: false,
|
|
235
|
-
preserveFileExtensions: false,
|
|
236
|
-
};
|
|
237
374
|
var componentToAngular = function (userOptions) {
|
|
238
375
|
if (userOptions === void 0) { userOptions = {}; }
|
|
239
376
|
return function (_a) {
|
|
240
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
377
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
241
378
|
var _component = _a.component;
|
|
242
379
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
243
380
|
var json = (0, fast_clone_1.fastClone)(_component);
|
|
244
|
-
var
|
|
245
|
-
var
|
|
381
|
+
var useMetadata = (_b = json.meta) === null || _b === void 0 ? void 0 : _b.useMetadata;
|
|
382
|
+
var contextVars = Object.keys(((_c = json === null || json === void 0 ? void 0 : json.context) === null || _c === void 0 ? void 0 : _c.get) || {});
|
|
383
|
+
// TODO: Why is 'outputs' used here and shouldn't it be typed in packages/core/src/types/metadata.ts
|
|
384
|
+
var metaOutputVars = (useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.outputs) || [];
|
|
246
385
|
var outputVars = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], metaOutputVars, true), (0, get_prop_functions_1.getPropFunctions)(json), true));
|
|
247
386
|
var stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
|
|
248
387
|
var options = (0, merge_options_1.initializeOptions)({
|
|
249
388
|
target: 'angular',
|
|
250
389
|
component: _component,
|
|
251
|
-
defaults:
|
|
390
|
+
defaults: types_1.DEFAULT_ANGULAR_OPTIONS,
|
|
252
391
|
userOptions: userOptions,
|
|
253
392
|
});
|
|
254
393
|
options.plugins = __spreadArray(__spreadArray([], (options.plugins || []), true), [
|
|
@@ -299,7 +438,7 @@ var componentToAngular = function (userOptions) {
|
|
|
299
438
|
if (options.plugins) {
|
|
300
439
|
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
301
440
|
}
|
|
302
|
-
var
|
|
441
|
+
var _l = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _l[0], hasPropRef = _l[1];
|
|
303
442
|
var childComponents = [];
|
|
304
443
|
var propsTypeRef = json.propsTypeRef !== 'any' ? json.propsTypeRef : undefined;
|
|
305
444
|
json.imports.forEach(function (_a) {
|
|
@@ -311,7 +450,7 @@ var componentToAngular = function (userOptions) {
|
|
|
311
450
|
});
|
|
312
451
|
});
|
|
313
452
|
var customImports = (0, get_custom_imports_1.getCustomImports)(json);
|
|
314
|
-
var
|
|
453
|
+
var _m = json.exports, localExports = _m === void 0 ? {} : _m;
|
|
315
454
|
var localExportVars = Object.keys(localExports)
|
|
316
455
|
.filter(function (key) { return localExports[key].usedInLocal; })
|
|
317
456
|
.map(function (key) { return "".concat(key, " = ").concat(key, ";"); });
|
|
@@ -326,7 +465,7 @@ var componentToAngular = function (userOptions) {
|
|
|
326
465
|
}
|
|
327
466
|
return "public ".concat(variableName, " : ").concat(variableType);
|
|
328
467
|
});
|
|
329
|
-
var hasConstructor = Boolean(injectables.length || ((
|
|
468
|
+
var hasConstructor = Boolean(injectables.length || ((_d = json.hooks) === null || _d === void 0 ? void 0 : _d.onInit));
|
|
330
469
|
var props = (0, get_props_1.getProps)(json);
|
|
331
470
|
// prevent jsx props from showing up as @Input
|
|
332
471
|
if (hasPropRef) {
|
|
@@ -347,7 +486,7 @@ var componentToAngular = function (userOptions) {
|
|
|
347
486
|
var domRefs = (0, get_refs_1.getRefs)(json);
|
|
348
487
|
var jsRefs = Object.keys(json.refs).filter(function (ref) { return !domRefs.has(ref); });
|
|
349
488
|
var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter(function (item) {
|
|
350
|
-
return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !BUILT_IN_COMPONENTS.has(item);
|
|
489
|
+
return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !types_1.BUILT_IN_COMPONENTS.has(item);
|
|
351
490
|
});
|
|
352
491
|
(0, map_refs_1.mapRefs)(json, function (refName) {
|
|
353
492
|
var isDomRef = domRefs.has(refName);
|
|
@@ -361,8 +500,19 @@ var componentToAngular = function (userOptions) {
|
|
|
361
500
|
if (options.prettier !== false) {
|
|
362
501
|
css = tryFormat(css, 'css');
|
|
363
502
|
}
|
|
503
|
+
var helperFunctions = new Set();
|
|
364
504
|
var template = json.children
|
|
365
|
-
.map(function (item) {
|
|
505
|
+
.map(function (item) {
|
|
506
|
+
var _a, _b;
|
|
507
|
+
var tmpl = (0, exports.blockToAngular)(item, options, {
|
|
508
|
+
childComponents: childComponents,
|
|
509
|
+
nativeAttributes: (_b = (_a = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _a === void 0 ? void 0 : _a.nativeAttributes) !== null && _b !== void 0 ? _b : [],
|
|
510
|
+
});
|
|
511
|
+
(0, helpers_2.getAppropriateTemplateFunctionKeys)(tmpl).forEach(function (key) {
|
|
512
|
+
return helperFunctions.add(helpers_2.HELPER_FUNCTIONS[key]);
|
|
513
|
+
});
|
|
514
|
+
return tmpl;
|
|
515
|
+
})
|
|
366
516
|
.join('\n');
|
|
367
517
|
if (options.prettier !== false) {
|
|
368
518
|
template = tryFormat(template, 'html');
|
|
@@ -378,8 +528,12 @@ var componentToAngular = function (userOptions) {
|
|
|
378
528
|
stateVars: stateVars,
|
|
379
529
|
}),
|
|
380
530
|
});
|
|
531
|
+
var _o = traverseToGetAllDynamicComponents(json, options, {
|
|
532
|
+
childComponents: childComponents,
|
|
533
|
+
nativeAttributes: (_f = (_e = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _e === void 0 ? void 0 : _e.nativeAttributes) !== null && _f !== void 0 ? _f : [],
|
|
534
|
+
}), dynamicComponents = _o.components, dynamicTemplate = _o.dynamicTemplate;
|
|
381
535
|
// Preparing built in component metadata parameters
|
|
382
|
-
var componentMetadata = __assign(__assign({ selector: "'".concat((0, lodash_1.kebabCase)(json.name || 'my-component'), ", ").concat(json.name, "'"), template: "`\n ".concat((0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), "\n `") }, (css.length
|
|
536
|
+
var componentMetadata = __assign(__assign({ selector: "'".concat((0, lodash_1.kebabCase)(json.name || 'my-component'), ", ").concat(json.name, "'"), template: "`\n ".concat((0, indent_1.indent)(dynamicTemplate, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), "\n ").concat((0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), "\n `") }, (css.length
|
|
383
537
|
? {
|
|
384
538
|
styles: "[`".concat((0, indent_1.indent)(css, 8), "`]"),
|
|
385
539
|
}
|
|
@@ -410,7 +564,7 @@ var componentToAngular = function (userOptions) {
|
|
|
410
564
|
.join(',');
|
|
411
565
|
return "const defaultProps = {".concat(defalutPropsString, "};\n");
|
|
412
566
|
};
|
|
413
|
-
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' : '', ((
|
|
567
|
+
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 default class ", " {\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 ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\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 ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.inject) ? 'Inject, forwardRef,' : '', domRefs.size || dynamicComponents.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', dynamicComponents.size ? ', ViewContainerRef, TemplateRef' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', getPropsDefinition({ json: json }), (0, render_imports_1.renderPreComponent)({
|
|
414
568
|
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
415
569
|
component: json,
|
|
416
570
|
target: 'angular',
|
|
@@ -427,15 +581,23 @@ var componentToAngular = function (userOptions) {
|
|
|
427
581
|
.filter(function (item) { return !(0, slots_1.isSlotProperty)(item) && item !== 'children'; })
|
|
428
582
|
.map(function (item) {
|
|
429
583
|
var propType = propsTypeRef ? "".concat(propsTypeRef, "[\"").concat(item, "\"]") : 'any';
|
|
430
|
-
var propDeclaration = "@Input() ".concat(item, "
|
|
584
|
+
var propDeclaration = "@Input() ".concat(item, "!: ").concat(propType);
|
|
431
585
|
if (json.defaultProps && json.defaultProps.hasOwnProperty(item)) {
|
|
432
586
|
propDeclaration += " = defaultProps[\"".concat(item, "\"]");
|
|
433
587
|
}
|
|
434
588
|
return propDeclaration;
|
|
435
589
|
})
|
|
436
590
|
.join('\n'), outputs.join('\n'), Array.from(domRefs)
|
|
437
|
-
.map(function (refName) { return "@ViewChild('".concat(refName, "') ").concat(refName, "
|
|
438
|
-
.join('\n'),
|
|
591
|
+
.map(function (refName) { return "@ViewChild('".concat(refName, "') ").concat(refName, "!: ElementRef"); })
|
|
592
|
+
.join('\n'), Array.from(dynamicComponents)
|
|
593
|
+
.map(function (component) {
|
|
594
|
+
return "@ViewChild('".concat(component
|
|
595
|
+
.split('.')[1]
|
|
596
|
+
.toLowerCase(), "Template', { static: true }) ").concat(component
|
|
597
|
+
.split('.')[1]
|
|
598
|
+
.toLowerCase(), "TemplateRef!: TemplateRef<any>");
|
|
599
|
+
})
|
|
600
|
+
.join('\n'), dynamicComponents.size ? 'myContent?: any[][];' : '', dataString, helperFunctions.size ? Array.from(helperFunctions).join('\n') : '', jsRefs
|
|
439
601
|
.map(function (ref) {
|
|
440
602
|
var argument = json.refs[ref].argument;
|
|
441
603
|
var typeParameter = json.refs[ref].typeParameter;
|
|
@@ -449,13 +611,21 @@ var componentToAngular = function (userOptions) {
|
|
|
449
611
|
})(argument))
|
|
450
612
|
: '', ";");
|
|
451
613
|
})
|
|
452
|
-
.join('\n'), !hasConstructor
|
|
614
|
+
.join('\n'), !hasConstructor && !dynamicComponents.size
|
|
453
615
|
? ''
|
|
454
|
-
: "constructor(\n".concat(injectables.join(',\n'), ") {\n ").concat(!((
|
|
616
|
+
: "constructor(\n".concat(injectables.join(',\n')).concat(dynamicComponents.size ? '\nprivate vcRef: ViewContainerRef,\n' : '', ") {\n ").concat(!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
|
|
455
617
|
? ''
|
|
456
|
-
: "\n ".concat((
|
|
618
|
+
: "\n ".concat((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, "\n "), "\n }\n "), !json.hooks.onMount.length && !dynamicComponents.size
|
|
457
619
|
? ''
|
|
458
|
-
: "ngOnInit() {\n ".concat((0, on_mount_1.stringifySingleScopeOnMount)(json), "\n
|
|
620
|
+
: "ngOnInit() {\n ".concat((0, on_mount_1.stringifySingleScopeOnMount)(json), "\n ").concat(dynamicComponents.size
|
|
621
|
+
? "\n this.myContent = [".concat(Array.from(dynamicComponents)
|
|
622
|
+
.map(function (component) {
|
|
623
|
+
return "this.vcRef.createEmbeddedView(this.".concat(component
|
|
624
|
+
.split('.')[1]
|
|
625
|
+
.toLowerCase(), "TemplateRef).rootNodes");
|
|
626
|
+
})
|
|
627
|
+
.join(', '), "];\n ")
|
|
628
|
+
: '', "\n }"), !((_k = json.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.length)
|
|
459
629
|
? ''
|
|
460
630
|
: "ngAfterContentChecked() {\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
|
|
461
631
|
code += hook.code;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
2
|
+
export declare const BUILT_IN_COMPONENTS: Set<string>;
|
|
3
|
+
export interface ToAngularOptions extends BaseTranspilerOptions {
|
|
4
|
+
standalone?: boolean;
|
|
5
|
+
preserveImports?: boolean;
|
|
6
|
+
preserveFileExtensions?: boolean;
|
|
7
|
+
importMapper?: Function;
|
|
8
|
+
bootstrapMapper?: Function;
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_ANGULAR_OPTIONS: ToAngularOptions;
|
|
11
|
+
export interface AngularBlockOptions {
|
|
12
|
+
childComponents?: string[];
|
|
13
|
+
nativeAttributes: string[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ANGULAR_OPTIONS = exports.BUILT_IN_COMPONENTS = void 0;
|
|
4
|
+
exports.BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment', 'Slot']);
|
|
5
|
+
exports.DEFAULT_ANGULAR_OPTIONS = {
|
|
6
|
+
preserveImports: false,
|
|
7
|
+
preserveFileExtensions: false,
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MitosisContext } from '../../types/mitosis-context';
|
|
2
|
+
type ContextToAngularOptions = {
|
|
3
|
+
format?: boolean;
|
|
4
|
+
typescript?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const contextToAngular: (options?: ContextToAngularOptions) => ({ context }: {
|
|
7
|
+
context: MitosisContext;
|
|
8
|
+
}) => string;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contextToAngular = void 0;
|
|
4
|
+
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
5
|
+
var standalone_1 = require("prettier/standalone");
|
|
6
|
+
var contextToAngular = function (options) {
|
|
7
|
+
if (options === void 0) { options = { typescript: false }; }
|
|
8
|
+
return function (_a) {
|
|
9
|
+
var context = _a.context;
|
|
10
|
+
var str = "\nimport { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport default class ".concat(context.name, "Context {\n ").concat((0, get_state_object_string_1.stringifyContextValue)(context.value)
|
|
11
|
+
.replace(/^\{/, '')
|
|
12
|
+
.replace(/\}$/, '')
|
|
13
|
+
.replaceAll(',', ';\n')
|
|
14
|
+
.replaceAll(':', ': any = '), "\n constructor() { }\n}\n ");
|
|
15
|
+
if (options.format !== false) {
|
|
16
|
+
try {
|
|
17
|
+
str = (0, standalone_1.format)(str, {
|
|
18
|
+
parser: 'typescript',
|
|
19
|
+
plugins: [
|
|
20
|
+
require('prettier/parser-typescript'), // To support running in browsers
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
console.error('Format error for file:', str);
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return str;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.contextToAngular = contextToAngular;
|
|
@@ -210,10 +210,14 @@ var componentToSolid = function (passedOptions) {
|
|
|
210
210
|
var newLocal = dep.replace(/(\.|\?|\(|\)|\[|\])/g, '_');
|
|
211
211
|
return "".concat(hookName, "_").concat(newLocal);
|
|
212
212
|
};
|
|
213
|
+
var needsMemo = function (dep) { return true; };
|
|
213
214
|
var reactiveDepsWorkaround = depsArray
|
|
215
|
+
.filter(needsMemo)
|
|
214
216
|
.map(function (dep) { return "const ".concat(getReactiveDepName(dep), " = createMemo(() => ").concat(dep, ");"); })
|
|
215
217
|
.join('\n');
|
|
216
|
-
var depsArrayStr = depsArray
|
|
218
|
+
var depsArrayStr = depsArray
|
|
219
|
+
.map(function (x) { return (needsMemo(x) ? "".concat(getReactiveDepName(x), "()") : x); })
|
|
220
|
+
.join(', ');
|
|
217
221
|
return "\n ".concat(reactiveDepsWorkaround, "\n function ").concat(hookName, "() { ").concat(hook.code, " };\n createEffect(on(() => [").concat(depsArrayStr, "], ").concat(hookName, "));\n ");
|
|
218
222
|
})
|
|
219
223
|
.join('\n')
|
|
@@ -12,6 +12,11 @@ export declare const renameComponentFile: ({ path, target, options, }: {
|
|
|
12
12
|
target: Target;
|
|
13
13
|
options: MitosisConfig;
|
|
14
14
|
}) => string;
|
|
15
|
+
export declare const renameComponentImport: ({ importPath, target, explicitImportFileExtension, }: {
|
|
16
|
+
importPath: string;
|
|
17
|
+
target: Target;
|
|
18
|
+
explicitImportFileExtension: boolean;
|
|
19
|
+
}) => string;
|
|
15
20
|
export declare const renameImport: ({ importPath, target, explicitImportFileExtension, }: {
|
|
16
21
|
importPath: string;
|
|
17
22
|
target: Target;
|
|
@@ -38,4 +43,8 @@ type Args = {
|
|
|
38
43
|
* - in `cli` to render filenames for generated components, and import statements within plain `.js`/`.ts` files.
|
|
39
44
|
*/
|
|
40
45
|
export declare const getComponentFileExtensionForTarget: (args: Args) => string;
|
|
46
|
+
export declare const getFileExtensionForTarget: ({ target, explicitImportFileExtension, }: {
|
|
47
|
+
target: Target;
|
|
48
|
+
explicitImportFileExtension: boolean;
|
|
49
|
+
}) => string;
|
|
41
50
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getComponentFileExtensionForTarget = exports.renameImport = exports.renameComponentFile = exports.INPUT_EXTENSION_REGEX = exports.checkIsMitosisComponentFilePath = exports.checkIsLiteComponentFilePath = exports.checkIsSvelteComponentFilePath = exports.COMPONENT_IMPORT_EXTENSIONS = void 0;
|
|
3
|
+
exports.getFileExtensionForTarget = exports.getComponentFileExtensionForTarget = exports.renameImport = exports.renameComponentImport = exports.renameComponentFile = exports.INPUT_EXTENSION_REGEX = exports.checkIsMitosisComponentFilePath = exports.checkIsLiteComponentFilePath = exports.checkIsSvelteComponentFilePath = exports.COMPONENT_IMPORT_EXTENSIONS = void 0;
|
|
4
4
|
var output_1 = require("./output");
|
|
5
5
|
var COMPONENT_EXTENSIONS = {
|
|
6
6
|
jsx: ['.lite.tsx', '.lite.jsx'],
|
|
@@ -38,7 +38,7 @@ exports.renameComponentFile = renameComponentFile;
|
|
|
38
38
|
* just like `INPUT_EXTENSION_REGEX`, but adds trailing quotes to the end of import paths.
|
|
39
39
|
*/
|
|
40
40
|
var INPUT_EXTENSION_IMPORT_REGEX = /\.(svelte|(lite(\.tsx|\.jsx)?))(?<quote>['"])/g;
|
|
41
|
-
var
|
|
41
|
+
var renameComponentImport = function (_a) {
|
|
42
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',
|
|
@@ -46,6 +46,14 @@ var renameImport = function (_a) {
|
|
|
46
46
|
explicitImportFileExtension: explicitImportFileExtension,
|
|
47
47
|
}), "$4"));
|
|
48
48
|
};
|
|
49
|
+
exports.renameComponentImport = renameComponentImport;
|
|
50
|
+
var renameImport = function (_a) {
|
|
51
|
+
var importPath = _a.importPath, target = _a.target, explicitImportFileExtension = _a.explicitImportFileExtension;
|
|
52
|
+
return importPath.replace(/\.js(['"])/g, "".concat((0, exports.getFileExtensionForTarget)({
|
|
53
|
+
target: target,
|
|
54
|
+
explicitImportFileExtension: explicitImportFileExtension,
|
|
55
|
+
}), "$1"));
|
|
56
|
+
};
|
|
49
57
|
exports.renameImport = renameImport;
|
|
50
58
|
/**
|
|
51
59
|
* Provides the correct file extension for a given component. This is used:
|
|
@@ -54,8 +62,14 @@ exports.renameImport = renameImport;
|
|
|
54
62
|
*/
|
|
55
63
|
var getComponentFileExtensionForTarget = function (args) {
|
|
56
64
|
switch (args.target) {
|
|
57
|
-
case 'angular':
|
|
58
|
-
|
|
65
|
+
case 'angular': {
|
|
66
|
+
switch (args.type) {
|
|
67
|
+
case 'import':
|
|
68
|
+
return '.js';
|
|
69
|
+
case 'filename':
|
|
70
|
+
return args.isTypescript ? '.ts' : '.js';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
59
73
|
case 'alpine':
|
|
60
74
|
case 'html':
|
|
61
75
|
return '.html';
|
|
@@ -97,3 +111,27 @@ var getComponentFileExtensionForTarget = function (args) {
|
|
|
97
111
|
}
|
|
98
112
|
};
|
|
99
113
|
exports.getComponentFileExtensionForTarget = getComponentFileExtensionForTarget;
|
|
114
|
+
var getFileExtensionForTarget = function (_a) {
|
|
115
|
+
var target = _a.target, explicitImportFileExtension = _a.explicitImportFileExtension;
|
|
116
|
+
switch (target) {
|
|
117
|
+
case 'angular':
|
|
118
|
+
case 'alpine':
|
|
119
|
+
case 'html':
|
|
120
|
+
case 'svelte':
|
|
121
|
+
case 'swift':
|
|
122
|
+
case 'vue':
|
|
123
|
+
case 'webcomponent':
|
|
124
|
+
case 'lit':
|
|
125
|
+
case 'qwik':
|
|
126
|
+
case 'react':
|
|
127
|
+
case 'reactNative':
|
|
128
|
+
case 'rsc':
|
|
129
|
+
case 'solid':
|
|
130
|
+
case 'stencil':
|
|
131
|
+
case 'marko':
|
|
132
|
+
case 'preact':
|
|
133
|
+
default:
|
|
134
|
+
return explicitImportFileExtension ? '.js' : '';
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
exports.getFileExtensionForTarget = getFileExtensionForTarget;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getProps = void 0;
|
|
7
|
-
var
|
|
4
|
+
var process_code_1 = require("./plugins/process-code");
|
|
8
5
|
var propsRegex = /props\s*\.\s*([a-zA-Z0-9_\$]+)/;
|
|
9
6
|
var allPropsMatchesRegex = new RegExp(propsRegex, 'g');
|
|
10
7
|
// copied from https://github.com/vuejs/core/blob/fa6556a0d56eeff1fec4f948460351ccf8f99f35/packages/compiler-core/src/validateExpression.ts
|
|
@@ -26,22 +23,20 @@ var prohibitedKeywordRE = new RegExp('\\b' +
|
|
|
26
23
|
*/
|
|
27
24
|
var getProps = function (json) {
|
|
28
25
|
var props = new Set();
|
|
29
|
-
(0,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (prop.match(prohibitedKeywordRE)) {
|
|
38
|
-
throw new Error("avoid using JavaScript keyword as property name: \"".concat(prop, "\""));
|
|
39
|
-
}
|
|
40
|
-
props.add(prop);
|
|
26
|
+
(0, process_code_1.createCodeProcessorPlugin)(function () { return function (code) {
|
|
27
|
+
var matches = code.match(allPropsMatchesRegex);
|
|
28
|
+
if (matches) {
|
|
29
|
+
for (var _i = 0, matches_1 = matches; _i < matches_1.length; _i++) {
|
|
30
|
+
var match = matches_1[_i];
|
|
31
|
+
var prop = match.match(propsRegex)[1];
|
|
32
|
+
if (prop.match(prohibitedKeywordRE)) {
|
|
33
|
+
throw new Error("avoid using JavaScript keyword as property name: \"".concat(prop, "\""));
|
|
41
34
|
}
|
|
35
|
+
props.add(prop);
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
|
-
|
|
38
|
+
return code;
|
|
39
|
+
}; })(json);
|
|
45
40
|
return props;
|
|
46
41
|
};
|
|
47
42
|
exports.getProps = getProps;
|
|
@@ -122,10 +122,11 @@ var replaceIdentifiers = function (_a) {
|
|
|
122
122
|
!core_1.types.isMemberExpression(path.parent) &&
|
|
123
123
|
!core_1.types.isOptionalMemberExpression(path.parent) &&
|
|
124
124
|
// function declaration identifiers shouldn't be transformed
|
|
125
|
-
!core_1.types.isFunctionDeclaration(path.parent)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
!core_1.types.isFunctionDeclaration(path.parent) &&
|
|
126
|
+
// variable declaration identifiers shouldn't be transformed
|
|
127
|
+
// !(types.isVariableDeclarator(path.parent) && path.parent.id === path.node)
|
|
128
|
+
// object -> { detail: { state: 'something' } } shouldn't be transformed to { detail: { this: 'something' } }
|
|
129
|
+
!core_1.types.isObjectProperty(path.parent)) {
|
|
129
130
|
_replaceIdentifiers(path, { from: from, to: to });
|
|
130
131
|
}
|
|
131
132
|
},
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './flow';
|
|
|
6
6
|
export * from './generators/alpine';
|
|
7
7
|
export * from './generators/angular';
|
|
8
8
|
export * from './generators/builder';
|
|
9
|
+
export * from './generators/context/angular';
|
|
9
10
|
export * from './generators/context/qwik';
|
|
10
11
|
export * from './generators/context/react';
|
|
11
12
|
export * from './generators/context/rsc';
|
|
@@ -28,7 +29,7 @@ export * from './generators/swift-ui';
|
|
|
28
29
|
export * from './generators/taro';
|
|
29
30
|
export * from './generators/template';
|
|
30
31
|
export * from './generators/vue';
|
|
31
|
-
export { checkIsLiteComponentFilePath, checkIsMitosisComponentFilePath, checkIsSvelteComponentFilePath, getComponentFileExtensionForTarget, renameComponentFile, renameImport, } from './helpers/component-file-extensions';
|
|
32
|
+
export { checkIsLiteComponentFilePath, checkIsMitosisComponentFilePath, checkIsSvelteComponentFilePath, getComponentFileExtensionForTarget, renameComponentFile, renameComponentImport, renameImport, } from './helpers/component-file-extensions';
|
|
32
33
|
export { createMitosisNode } from './helpers/create-mitosis-node';
|
|
33
34
|
export * from './helpers/is-mitosis-node';
|
|
34
35
|
export { checkShouldOutputTypeScript } from './helpers/output';
|
package/dist/src/index.js
CHANGED
|
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.checkShouldOutputTypeScript = exports.createMitosisNode = exports.renameImport = exports.renameComponentFile = exports.getComponentFileExtensionForTarget = exports.checkIsSvelteComponentFilePath = exports.checkIsMitosisComponentFilePath = exports.checkIsLiteComponentFilePath = void 0;
|
|
17
|
+
exports.checkShouldOutputTypeScript = exports.createMitosisNode = exports.renameImport = exports.renameComponentImport = exports.renameComponentFile = exports.getComponentFileExtensionForTarget = exports.checkIsSvelteComponentFilePath = exports.checkIsMitosisComponentFilePath = exports.checkIsLiteComponentFilePath = void 0;
|
|
18
18
|
__exportStar(require("./flow"), exports);
|
|
19
19
|
__exportStar(require("./generators/alpine"), exports);
|
|
20
20
|
__exportStar(require("./generators/angular"), exports);
|
|
21
21
|
__exportStar(require("./generators/builder"), exports);
|
|
22
|
+
__exportStar(require("./generators/context/angular"), exports);
|
|
22
23
|
__exportStar(require("./generators/context/qwik"), exports);
|
|
23
24
|
__exportStar(require("./generators/context/react"), exports);
|
|
24
25
|
__exportStar(require("./generators/context/rsc"), exports);
|
|
@@ -47,6 +48,7 @@ Object.defineProperty(exports, "checkIsMitosisComponentFilePath", { enumerable:
|
|
|
47
48
|
Object.defineProperty(exports, "checkIsSvelteComponentFilePath", { enumerable: true, get: function () { return component_file_extensions_1.checkIsSvelteComponentFilePath; } });
|
|
48
49
|
Object.defineProperty(exports, "getComponentFileExtensionForTarget", { enumerable: true, get: function () { return component_file_extensions_1.getComponentFileExtensionForTarget; } });
|
|
49
50
|
Object.defineProperty(exports, "renameComponentFile", { enumerable: true, get: function () { return component_file_extensions_1.renameComponentFile; } });
|
|
51
|
+
Object.defineProperty(exports, "renameComponentImport", { enumerable: true, get: function () { return component_file_extensions_1.renameComponentImport; } });
|
|
50
52
|
Object.defineProperty(exports, "renameImport", { enumerable: true, get: function () { return component_file_extensions_1.renameImport; } });
|
|
51
53
|
var create_mitosis_node_1 = require("./helpers/create-mitosis-node");
|
|
52
54
|
Object.defineProperty(exports, "createMitosisNode", { enumerable: true, get: function () { return create_mitosis_node_1.createMitosisNode; } });
|
package/dist/src/targets.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const builder: (options?: import("./generators/builder").ToBuilderOptions) => ({ component }: import(".").TranspilerArgs) => import("@builder.io/sdk").BuilderContent;
|
|
2
2
|
export declare const targets: {
|
|
3
3
|
readonly alpine: import(".").TranspilerGenerator<import("./generators/alpine").ToAlpineOptions>;
|
|
4
|
-
readonly angular: import(".").TranspilerGenerator<import("./generators/angular").ToAngularOptions>;
|
|
4
|
+
readonly angular: import(".").TranspilerGenerator<import("./generators/angular/types").ToAngularOptions>;
|
|
5
5
|
readonly customElement: import(".").TranspilerGenerator<import("./generators/html").ToHtmlOptions>;
|
|
6
6
|
readonly html: import(".").TranspilerGenerator<import("./generators/html").ToHtmlOptions>;
|
|
7
7
|
readonly mitosis: import(".").TranspilerGenerator<Partial<import("./generators/mitosis").ToMitosisOptions>>;
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MitosisNode } from '../types/mitosis-node';
|
|
2
|
-
import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
|
|
3
|
-
export interface ToAngularOptions extends BaseTranspilerOptions {
|
|
4
|
-
standalone?: boolean;
|
|
5
|
-
preserveImports?: boolean;
|
|
6
|
-
preserveFileExtensions?: boolean;
|
|
7
|
-
importMapper?: Function;
|
|
8
|
-
bootstrapMapper?: Function;
|
|
9
|
-
}
|
|
10
|
-
interface AngularBlockOptions {
|
|
11
|
-
childComponents?: string[];
|
|
12
|
-
}
|
|
13
|
-
export declare const blockToAngular: (json: MitosisNode, options?: ToAngularOptions, blockOptions?: AngularBlockOptions) => string;
|
|
14
|
-
export declare const componentToAngular: TranspilerGenerator<ToAngularOptions>;
|
|
15
|
-
export {};
|