@builder.io/mitosis 0.3.3 → 0.3.5
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 +1 -1
- package/dist/src/generators/angular/helpers.js +8 -7
- package/dist/src/generators/angular/index.d.ts +7 -1
- package/dist/src/generators/angular/index.js +248 -57
- package/dist/src/generators/angular/types.d.ts +1 -0
- package/dist/src/generators/angular/types.js +1 -0
- package/dist/src/plugins/compile-away-builder-components.js +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAppropriateTemplateFunctionKeys = exports.HELPER_FUNCTIONS = void 0;
|
|
4
|
-
|
|
5
|
-
useObjectWrapper: "useObjectWrapper(...args: any[]) {\n
|
|
6
|
-
useObjectDotValues: "useObjectDotValues(obj: any): any[] {\n
|
|
7
|
-
useTypeOf: "useTypeOf(obj: any): string {\n
|
|
8
|
-
useJsonStringify: "useJsonStringify(
|
|
9
|
-
};
|
|
4
|
+
var HELPER_FUNCTIONS = function (isTs) { return ({
|
|
5
|
+
useObjectWrapper: "useObjectWrapper(...args".concat(isTs ? ': any[]' : '', ") {\n let obj = {}\n args.forEach((arg) => {\n obj = { ...obj, ...arg };\n });\n return obj;\n }"),
|
|
6
|
+
useObjectDotValues: "useObjectDotValues(obj".concat(isTs ? ': any' : '', ")").concat(isTs ? ': any[]' : '', ") {\n return Object.values(obj);\n }"),
|
|
7
|
+
useTypeOf: "useTypeOf(obj".concat(isTs ? ': any' : '', ")").concat(isTs ? ': string' : '', ") {\n return typeof obj;\n }"),
|
|
8
|
+
useJsonStringify: "useJsonStringify(...args".concat(isTs ? ': any' : '', ")").concat(isTs ? ': string' : '', ") {\n return JSON.stringify(...args);\n }"),
|
|
9
|
+
}); };
|
|
10
|
+
exports.HELPER_FUNCTIONS = HELPER_FUNCTIONS;
|
|
10
11
|
var getAppropriateTemplateFunctionKeys = function (code) {
|
|
11
|
-
return Object.keys(exports.HELPER_FUNCTIONS).filter(function (key) { return code.includes(key); });
|
|
12
|
+
return Object.keys((0, exports.HELPER_FUNCTIONS)()).filter(function (key) { return code.includes(key); });
|
|
12
13
|
};
|
|
13
14
|
exports.getAppropriateTemplateFunctionKeys = getAppropriateTemplateFunctionKeys;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { MitosisComponent } from '../../types/mitosis-component';
|
|
1
2
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
3
|
import { TranspilerGenerator } from '../../types/transpiler';
|
|
3
4
|
import { AngularBlockOptions, ToAngularOptions } from './types';
|
|
4
|
-
export declare const blockToAngular: (
|
|
5
|
+
export declare const blockToAngular: ({ root, json, options, blockOptions, }: {
|
|
6
|
+
root: MitosisComponent;
|
|
7
|
+
json: MitosisNode;
|
|
8
|
+
options?: ToAngularOptions | undefined;
|
|
9
|
+
blockOptions?: AngularBlockOptions | undefined;
|
|
10
|
+
}) => string;
|
|
5
11
|
export declare const componentToAngular: TranspilerGenerator<ToAngularOptions>;
|
|
@@ -52,7 +52,9 @@ var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
|
52
52
|
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
53
53
|
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
54
54
|
var helpers_1 = require("../../helpers/styles/helpers");
|
|
55
|
+
var traverse_nodes_1 = require("../../helpers/traverse-nodes");
|
|
55
56
|
var plugins_1 = require("../../modules/plugins");
|
|
57
|
+
var symbol_processor_1 = require("../../symbols/symbol-processor");
|
|
56
58
|
var mitosis_node_1 = require("../../types/mitosis-node");
|
|
57
59
|
var function_1 = require("fp-ts/lib/function");
|
|
58
60
|
var lodash_1 = require("lodash");
|
|
@@ -63,13 +65,13 @@ var on_mount_1 = require("../helpers/on-mount");
|
|
|
63
65
|
var helpers_2 = require("./helpers");
|
|
64
66
|
var types_1 = require("./types");
|
|
65
67
|
var mappers = {
|
|
66
|
-
Fragment: function (json, options) {
|
|
68
|
+
Fragment: function (root, json, options) {
|
|
67
69
|
return "<ng-container>".concat(json.children
|
|
68
|
-
.map(function (item) { return (0, exports.blockToAngular)(item, options); })
|
|
70
|
+
.map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options }); })
|
|
69
71
|
.join('\n'), "</ng-container>");
|
|
70
72
|
},
|
|
71
|
-
Slot: function (json, options) {
|
|
72
|
-
var renderChildren = function () { var _a; return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (0, exports.blockToAngular)(item, options); }).join('\n'); };
|
|
73
|
+
Slot: function (root, json, options) {
|
|
74
|
+
var renderChildren = function () { var _a; return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options }); }).join('\n'); };
|
|
73
75
|
return "<ng-content ".concat(Object.entries(__assign(__assign({}, json.bindings), json.properties))
|
|
74
76
|
.map(function (_a) {
|
|
75
77
|
var binding = _a[0], value = _a[1];
|
|
@@ -152,7 +154,7 @@ var processCodeBlockInTemplate = function (code) {
|
|
|
152
154
|
return "useObjectDotValues".concat(stripped);
|
|
153
155
|
}
|
|
154
156
|
else if (code.includes('JSON.stringify')) {
|
|
155
|
-
var obj = code.match(/JSON.stringify\(
|
|
157
|
+
var obj = code.match(/JSON.stringify\((.*)\)/);
|
|
156
158
|
return "useJsonStringify(".concat(obj, ")");
|
|
157
159
|
}
|
|
158
160
|
else if (code.includes(' as ')) {
|
|
@@ -183,13 +185,10 @@ var processEventBinding = function (key, code, nodeName, customArg) {
|
|
|
183
185
|
var stringifyBinding = function (node, options, blockOptions) {
|
|
184
186
|
return function (_a) {
|
|
185
187
|
var key = _a[0], binding = _a[1];
|
|
186
|
-
if ((binding === null || binding === void 0 ? void 0 : binding.type) === 'spread') {
|
|
188
|
+
if (options.state === 'inline-with-wrappers' && (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread') {
|
|
187
189
|
return;
|
|
188
190
|
}
|
|
189
|
-
if (key.startsWith('$')) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (key === 'key') {
|
|
191
|
+
if (key.startsWith('$') || key.startsWith('"') || key === 'key') {
|
|
193
192
|
return;
|
|
194
193
|
}
|
|
195
194
|
var keyToUse = BINDINGS_MAPPER[key] || key;
|
|
@@ -212,11 +211,13 @@ var stringifyBinding = function (node, options, blockOptions) {
|
|
|
212
211
|
return " [attr.".concat(keyToUse, "]=\"").concat(code, "\" ");
|
|
213
212
|
}
|
|
214
213
|
else {
|
|
215
|
-
|
|
214
|
+
var codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
|
|
215
|
+
return "[".concat(keyToUse, "]=\"").concat(codeToUse, "\"");
|
|
216
216
|
}
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
|
-
var handleNgOutletBindings = function (node) {
|
|
219
|
+
var handleNgOutletBindings = function (node, options) {
|
|
220
|
+
var _a;
|
|
220
221
|
var allProps = '';
|
|
221
222
|
for (var key in node.properties) {
|
|
222
223
|
if (key.startsWith('$')) {
|
|
@@ -235,21 +236,22 @@ var handleNgOutletBindings = function (node) {
|
|
|
235
236
|
if (key.startsWith('$')) {
|
|
236
237
|
continue;
|
|
237
238
|
}
|
|
238
|
-
var
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
239
|
+
var _b = node.bindings[key], code = _b.code, _c = _b.arguments, cusArgs = _c === void 0 ? ['event'] : _c;
|
|
240
|
+
if (options.state === 'class-properties') {
|
|
241
|
+
code = "this.".concat(code);
|
|
242
|
+
if (((_a = node.bindings[key]) === null || _a === void 0 ? void 0 : _a.type) === 'spread') {
|
|
243
|
+
allProps += "...".concat(code, ", ");
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
245
246
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
var keyToUse = key.includes('-') ? "'".concat(key, "'") : key;
|
|
248
|
+
keyToUse = keyToUse.replace('state.', '').replace('props.', '');
|
|
249
|
+
if (key.startsWith('on')) {
|
|
250
|
+
var _d = processEventBinding(key, code, node.name, cusArgs[0]), event_2 = _d.event, value = _d.value;
|
|
251
|
+
allProps += "on".concat(event_2.charAt(0).toUpperCase() + event_2.slice(1), ": ").concat(value.replace(/\(.*?\)/g, ''), ".bind(this), ");
|
|
249
252
|
}
|
|
250
253
|
else {
|
|
251
|
-
var codeToUse = processCodeBlockInTemplate(code);
|
|
252
|
-
var keyToUse = key.includes('-') ? "'".concat(key, "'") : key;
|
|
254
|
+
var codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
|
|
253
255
|
allProps += "".concat(keyToUse, ": ").concat(codeToUse, ", ");
|
|
254
256
|
}
|
|
255
257
|
}
|
|
@@ -261,15 +263,14 @@ var handleNgOutletBindings = function (node) {
|
|
|
261
263
|
}
|
|
262
264
|
return allProps;
|
|
263
265
|
};
|
|
264
|
-
var blockToAngular = function (
|
|
265
|
-
var
|
|
266
|
-
|
|
267
|
-
if (blockOptions === void 0) { blockOptions = {
|
|
266
|
+
var blockToAngular = function (_a) {
|
|
267
|
+
var _b, _c, _d, _e;
|
|
268
|
+
var root = _a.root, json = _a.json, _f = _a.options, options = _f === void 0 ? {} : _f, _g = _a.blockOptions, blockOptions = _g === void 0 ? {
|
|
268
269
|
nativeAttributes: [],
|
|
269
|
-
};
|
|
270
|
+
} : _g;
|
|
270
271
|
var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
271
272
|
if (mappers[json.name]) {
|
|
272
|
-
return mappers[json.name](json, options);
|
|
273
|
+
return mappers[json.name](root, json, options);
|
|
273
274
|
}
|
|
274
275
|
if ((0, is_children_1.default)({ node: json })) {
|
|
275
276
|
return "<ng-content></ng-content>";
|
|
@@ -277,38 +278,41 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
277
278
|
if (json.properties._text) {
|
|
278
279
|
return json.properties._text;
|
|
279
280
|
}
|
|
280
|
-
var textCode = (
|
|
281
|
+
var textCode = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code;
|
|
281
282
|
if (textCode) {
|
|
282
283
|
if ((0, slots_1.isSlotProperty)(textCode)) {
|
|
283
284
|
return "<ng-content select=\"[".concat((0, slots_1.toKebabSlot)(textCode), "]\"></ng-content>");
|
|
284
285
|
}
|
|
285
286
|
if (textCode.includes('JSON.stringify')) {
|
|
286
|
-
var obj = textCode.replace(
|
|
287
|
-
|
|
288
|
-
return "{{useJsonStringify".concat(obj, "}}");
|
|
287
|
+
var obj = textCode.replace(/JSON.stringify\(\s*(\w+)\s*,?.*\)/, '$1');
|
|
288
|
+
return "{{".concat(obj, " | json}}");
|
|
289
289
|
}
|
|
290
290
|
return "{{".concat(textCode, "}}");
|
|
291
291
|
}
|
|
292
292
|
var str = '';
|
|
293
293
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
294
294
|
var indexName = json.scope.indexName;
|
|
295
|
-
str += "<ng-container *ngFor=\"let ".concat(json.scope.forName, " of ").concat((
|
|
296
|
-
str += json.children
|
|
295
|
+
str += "<ng-container *ngFor=\"let ".concat(json.scope.forName, " of ").concat((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
|
|
296
|
+
str += json.children
|
|
297
|
+
.map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
|
|
298
|
+
.join('\n');
|
|
297
299
|
str += "</ng-container>";
|
|
298
300
|
}
|
|
299
301
|
else if (json.name === 'Show') {
|
|
300
|
-
var condition = (
|
|
301
|
-
if (condition === null || condition === void 0 ? void 0 : condition.includes('typeof')) {
|
|
302
|
+
var condition = (_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code;
|
|
303
|
+
if (options.state === 'inline-with-wrappers' && (condition === null || condition === void 0 ? void 0 : condition.includes('typeof'))) {
|
|
302
304
|
var wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
|
|
303
305
|
condition = condition.replace("typeof ".concat(wordAfterTypeof), "useTypeOf(".concat(wordAfterTypeof, ")"));
|
|
304
306
|
}
|
|
305
307
|
str += "<ng-container *ngIf=\"".concat(condition, "\">");
|
|
306
|
-
str += json.children
|
|
308
|
+
str += json.children
|
|
309
|
+
.map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
|
|
310
|
+
.join('\n');
|
|
307
311
|
str += "</ng-container>";
|
|
308
312
|
// else condition
|
|
309
|
-
if ((0, is_mitosis_node_1.isMitosisNode)((
|
|
313
|
+
if ((0, is_mitosis_node_1.isMitosisNode)((_e = json.meta) === null || _e === void 0 ? void 0 : _e.else)) {
|
|
310
314
|
str += "<ng-container *ngIf=\"!(".concat(condition, ")\">");
|
|
311
|
-
str += (0, exports.blockToAngular)(json.meta.else, options, blockOptions);
|
|
315
|
+
str += (0, exports.blockToAngular)({ root: root, json: json.meta.else, options: options, blockOptions: blockOptions });
|
|
312
316
|
str += "</ng-container>";
|
|
313
317
|
}
|
|
314
318
|
}
|
|
@@ -316,8 +320,38 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
316
320
|
var elSelector = childComponents.find(function (impName) { return impName === json.name; })
|
|
317
321
|
? (0, lodash_1.kebabCase)(json.name)
|
|
318
322
|
: json.name;
|
|
319
|
-
var allProps = handleNgOutletBindings(json);
|
|
320
|
-
|
|
323
|
+
var allProps = handleNgOutletBindings(json, options);
|
|
324
|
+
if (options.state === 'class-properties') {
|
|
325
|
+
var inputsPropsStateName = "mergedInputs_".concat((0, symbol_processor_1.hashCodeAsString)(allProps));
|
|
326
|
+
root.state[inputsPropsStateName] = {
|
|
327
|
+
code: 'null',
|
|
328
|
+
type: 'property',
|
|
329
|
+
};
|
|
330
|
+
if (!root.hooks.onMount
|
|
331
|
+
.map(function (hook) { return hook.code; })
|
|
332
|
+
.join('')
|
|
333
|
+
.includes(inputsPropsStateName)) {
|
|
334
|
+
root.hooks.onMount.push({
|
|
335
|
+
code: "this.".concat(inputsPropsStateName, " = {").concat(allProps, "}"),
|
|
336
|
+
onSSR: false,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (root.hooks.onUpdate &&
|
|
340
|
+
root.hooks.onUpdate.length > 0 &&
|
|
341
|
+
!root.hooks.onUpdate
|
|
342
|
+
.map(function (hook) { return hook.code; })
|
|
343
|
+
.join('')
|
|
344
|
+
.includes(inputsPropsStateName)) {
|
|
345
|
+
root.hooks.onUpdate.push({
|
|
346
|
+
code: "this.".concat(inputsPropsStateName, " = {").concat(allProps, "}"),
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
allProps = "".concat(inputsPropsStateName);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
allProps = "{ ".concat(allProps, " }");
|
|
353
|
+
}
|
|
354
|
+
str += "<ng-container *ngComponentOutlet=\"\n ".concat(elSelector.replace('state.', '').replace('props.', ''), ";\n inputs: ").concat(allProps, ";\n content: myContent;\n \"> ");
|
|
321
355
|
str += "</ng-container>";
|
|
322
356
|
}
|
|
323
357
|
else {
|
|
@@ -347,7 +381,9 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
347
381
|
}
|
|
348
382
|
str += '>';
|
|
349
383
|
if (json.children) {
|
|
350
|
-
str += json.children
|
|
384
|
+
str += json.children
|
|
385
|
+
.map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
|
|
386
|
+
.join('\n');
|
|
351
387
|
}
|
|
352
388
|
str += "</".concat(elSelector, ">");
|
|
353
389
|
}
|
|
@@ -360,7 +396,7 @@ var traverseToGetAllDynamicComponents = function (json, options, blockOptions) {
|
|
|
360
396
|
(0, traverse_1.default)(json).forEach(function (item) {
|
|
361
397
|
if ((0, is_mitosis_node_1.isMitosisNode)(item) && item.name.includes('.') && item.name.split('.').length === 2) {
|
|
362
398
|
var children = item.children
|
|
363
|
-
.map(function (child) { return (0, exports.blockToAngular)(child, options, blockOptions); })
|
|
399
|
+
.map(function (child) { return (0, exports.blockToAngular)({ root: json, json: child, options: options, blockOptions: blockOptions }); })
|
|
364
400
|
.join('\n');
|
|
365
401
|
dynamicTemplate = "<ng-template #".concat(item.name.split('.')[1].toLowerCase() + 'Template', ">").concat(children, "</ng-template>");
|
|
366
402
|
components.add(item.name);
|
|
@@ -382,6 +418,147 @@ var processAngularCode = function (_a) {
|
|
|
382
418
|
}), function (newCode) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, { replaceWith: replaceWith }); });
|
|
383
419
|
};
|
|
384
420
|
};
|
|
421
|
+
var isASimpleProperty = function (code) {
|
|
422
|
+
var expressions = ['==', '===', '!=', '!==', '<', '>', '<=', '>='];
|
|
423
|
+
var invalidChars = ['{', '}', '(', ')', 'typeof'];
|
|
424
|
+
return !invalidChars.some(function (char) { return code.includes(char); }) && !expressions.includes(code);
|
|
425
|
+
};
|
|
426
|
+
var generateNewBindingName = function (index, name) {
|
|
427
|
+
return "node_".concat(index, "_").concat(name.replaceAll('.', '_').replaceAll('-', '_'));
|
|
428
|
+
};
|
|
429
|
+
var handleBindings = function (json, item, index, forName, indexName) {
|
|
430
|
+
var _a, _b, _c, _d, _e, _f;
|
|
431
|
+
for (var key in item.bindings) {
|
|
432
|
+
if (key.startsWith('"') ||
|
|
433
|
+
key.startsWith('$') ||
|
|
434
|
+
key === 'css' ||
|
|
435
|
+
key === 'ref' ||
|
|
436
|
+
isASimpleProperty(item.bindings[key].code)) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
var newBindingName = generateNewBindingName(index, item.name);
|
|
440
|
+
if (forName) {
|
|
441
|
+
if (item.name === 'For')
|
|
442
|
+
continue;
|
|
443
|
+
if (key.startsWith('on')) {
|
|
444
|
+
var _g = item.bindings[key].arguments, cusArgs = _g === void 0 ? ['event'] : _g;
|
|
445
|
+
var eventBindingName = "".concat(generateNewBindingName(index, item.name), "_event");
|
|
446
|
+
if (((_a = item.bindings[key]) === null || _a === void 0 ? void 0 : _a.code.trim().startsWith('{')) &&
|
|
447
|
+
((_b = item.bindings[key]) === null || _b === void 0 ? void 0 : _b.code.trim().endsWith('}'))) {
|
|
448
|
+
var forAndIndex = "".concat(forName ? ", ".concat(forName) : '').concat(indexName ? ", ".concat(indexName) : '');
|
|
449
|
+
var eventArgs = "".concat(cusArgs.join(', ')).concat(forAndIndex);
|
|
450
|
+
json.state[eventBindingName] = {
|
|
451
|
+
code: "(".concat(eventArgs, ") => ").concat(item.bindings[key].code),
|
|
452
|
+
type: 'function',
|
|
453
|
+
};
|
|
454
|
+
item.bindings[key].code = "state.".concat(eventBindingName, "(").concat(eventArgs, ")");
|
|
455
|
+
json.state[newBindingName] = {
|
|
456
|
+
code: "(".concat(eventArgs, ") => (").concat(item.bindings[key].code, ")"),
|
|
457
|
+
type: 'function',
|
|
458
|
+
};
|
|
459
|
+
item.bindings[key].code = "state.".concat(newBindingName, "($").concat(eventArgs, ")");
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
json.state[newBindingName] = {
|
|
464
|
+
code: "(".concat(forName).concat(indexName ? ", ".concat(indexName) : '', ") => (").concat(item.bindings[key].code, ")"),
|
|
465
|
+
type: 'function',
|
|
466
|
+
};
|
|
467
|
+
item.bindings[key].code = "state.".concat(newBindingName, "(").concat(forName).concat(indexName ? ", ".concat(indexName) : '', ")");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else if ((_c = item.bindings[key]) === null || _c === void 0 ? void 0 : _c.code) {
|
|
471
|
+
if (((_d = item.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) !== 'spread' && !key.startsWith('on')) {
|
|
472
|
+
json.state[newBindingName] = { code: 'null', type: 'property' };
|
|
473
|
+
json.hooks['onMount'].push({
|
|
474
|
+
code: "state.".concat(newBindingName, " = ").concat(item.bindings[key].code),
|
|
475
|
+
onSSR: false,
|
|
476
|
+
});
|
|
477
|
+
json.hooks['onUpdate'] = json.hooks['onUpdate'] || [];
|
|
478
|
+
json.hooks['onUpdate'].push({
|
|
479
|
+
code: "state.".concat(newBindingName, " = ").concat(item.bindings[key].code),
|
|
480
|
+
});
|
|
481
|
+
item.bindings[key].code = "state.".concat(newBindingName);
|
|
482
|
+
}
|
|
483
|
+
else if (key.startsWith('on')) {
|
|
484
|
+
var _h = item.bindings[key].arguments, cusArgs = _h === void 0 ? ['event'] : _h;
|
|
485
|
+
if (((_e = item.bindings[key]) === null || _e === void 0 ? void 0 : _e.code.trim().startsWith('{')) &&
|
|
486
|
+
((_f = item.bindings[key]) === null || _f === void 0 ? void 0 : _f.code.trim().endsWith('}'))) {
|
|
487
|
+
json.state[newBindingName] = {
|
|
488
|
+
code: "(".concat(cusArgs.join(', '), ") => ").concat(item.bindings[key].code),
|
|
489
|
+
type: 'function',
|
|
490
|
+
};
|
|
491
|
+
item.bindings[key].code = "state.".concat(newBindingName, "(").concat(cusArgs.join(', '), ")");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
json.state[newBindingName] = { code: "null", type: 'property' };
|
|
496
|
+
json.hooks['onMount'].push({
|
|
497
|
+
code: "state.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")}"),
|
|
498
|
+
onSSR: false,
|
|
499
|
+
});
|
|
500
|
+
json.hooks['onUpdate'] = json.hooks['onUpdate'] || [];
|
|
501
|
+
json.hooks['onUpdate'].push({
|
|
502
|
+
code: "state.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")}"),
|
|
503
|
+
});
|
|
504
|
+
item.bindings[newBindingName] = item.bindings[key];
|
|
505
|
+
item.bindings[key].code = "state.".concat(newBindingName);
|
|
506
|
+
delete item.bindings[key];
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
index++;
|
|
510
|
+
}
|
|
511
|
+
return index;
|
|
512
|
+
};
|
|
513
|
+
var handleProperties = function (json, item, index) {
|
|
514
|
+
for (var key in item.properties) {
|
|
515
|
+
if (key.startsWith('$') || isASimpleProperty(item.properties[key])) {
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
var newBindingName = generateNewBindingName(index, item.name);
|
|
519
|
+
json.state[newBindingName] = { code: '`' + "".concat(item.properties[key]) + '`', type: 'property' };
|
|
520
|
+
item.bindings[key] = { code: "state.".concat(newBindingName), type: 'single' };
|
|
521
|
+
delete item.properties[key];
|
|
522
|
+
index++;
|
|
523
|
+
}
|
|
524
|
+
return index;
|
|
525
|
+
};
|
|
526
|
+
var handleAngularBindings = function (json, item, index, _a) {
|
|
527
|
+
var _b = _a === void 0 ? {} : _a, forName = _b.forName, indexName = _b.indexName;
|
|
528
|
+
if ((0, is_children_1.default)({ node: item }))
|
|
529
|
+
return index;
|
|
530
|
+
index = handleBindings(json, item, index, forName, indexName);
|
|
531
|
+
index = handleProperties(json, item, index);
|
|
532
|
+
return index;
|
|
533
|
+
};
|
|
534
|
+
var classPropertiesPlugin = function () { return ({
|
|
535
|
+
json: {
|
|
536
|
+
pre: function (json) {
|
|
537
|
+
var lastId = 0;
|
|
538
|
+
(0, traverse_nodes_1.traverseNodes)(json, function (item) {
|
|
539
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
540
|
+
if (item.name === 'For') {
|
|
541
|
+
var forName_1 = item.scope.forName;
|
|
542
|
+
var indexName_1 = item.scope.indexName;
|
|
543
|
+
(0, traverse_nodes_1.traverseNodes)(item, function (child) {
|
|
544
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(child)) {
|
|
545
|
+
child._traversed = true;
|
|
546
|
+
lastId = handleAngularBindings(json, child, lastId, {
|
|
547
|
+
forName: forName_1,
|
|
548
|
+
indexName: indexName_1,
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
else if (!item._traversed) {
|
|
554
|
+
lastId = handleAngularBindings(json, item, lastId);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
return json;
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
}); };
|
|
385
562
|
var componentToAngular = function (userOptions) {
|
|
386
563
|
if (userOptions === void 0) { userOptions = {}; }
|
|
387
564
|
return function (_a) {
|
|
@@ -446,6 +623,9 @@ var componentToAngular = function (userOptions) {
|
|
|
446
623
|
}
|
|
447
624
|
}),
|
|
448
625
|
], false);
|
|
626
|
+
if (options.state === 'class-properties') {
|
|
627
|
+
options.plugins.push(classPropertiesPlugin);
|
|
628
|
+
}
|
|
449
629
|
if (options.plugins) {
|
|
450
630
|
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
451
631
|
}
|
|
@@ -515,13 +695,20 @@ var componentToAngular = function (userOptions) {
|
|
|
515
695
|
var template = json.children
|
|
516
696
|
.map(function (item) {
|
|
517
697
|
var _a, _b;
|
|
518
|
-
var tmpl = (0, exports.blockToAngular)(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
698
|
+
var tmpl = (0, exports.blockToAngular)({
|
|
699
|
+
root: json,
|
|
700
|
+
json: item,
|
|
701
|
+
options: options,
|
|
702
|
+
blockOptions: {
|
|
703
|
+
childComponents: childComponents,
|
|
704
|
+
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 : [],
|
|
705
|
+
},
|
|
524
706
|
});
|
|
707
|
+
if (options.state === 'inline-with-wrappers') {
|
|
708
|
+
(0, helpers_2.getAppropriateTemplateFunctionKeys)(tmpl).forEach(function (key) {
|
|
709
|
+
return helperFunctions.add((0, helpers_2.HELPER_FUNCTIONS)(options.typescript)[key]);
|
|
710
|
+
});
|
|
711
|
+
}
|
|
525
712
|
return tmpl;
|
|
526
713
|
})
|
|
527
714
|
.join('\n');
|
|
@@ -594,23 +781,25 @@ var componentToAngular = function (userOptions) {
|
|
|
594
781
|
.filter(function (item) { return !(0, slots_1.isSlotProperty)(item) && item !== 'children'; })
|
|
595
782
|
.map(function (item) {
|
|
596
783
|
var propType = propsTypeRef ? "".concat(propsTypeRef, "[\"").concat(item, "\"]") : 'any';
|
|
597
|
-
var propDeclaration = "@Input() ".concat(item
|
|
784
|
+
var propDeclaration = "@Input() ".concat(item).concat(options.typescript ? "!: ".concat(propType) : '');
|
|
598
785
|
if (json.defaultProps && json.defaultProps.hasOwnProperty(item)) {
|
|
599
786
|
propDeclaration += " = defaultProps[\"".concat(item, "\"]");
|
|
600
787
|
}
|
|
601
788
|
return propDeclaration;
|
|
602
789
|
})
|
|
603
790
|
.join('\n'), outputs.join('\n'), Array.from(domRefs)
|
|
604
|
-
.map(function (refName) {
|
|
791
|
+
.map(function (refName) {
|
|
792
|
+
return "@ViewChild('".concat(refName, "') ").concat(refName).concat(options.typescript ? '!: ElementRef' : '');
|
|
793
|
+
})
|
|
605
794
|
.join('\n'), Array.from(dynamicComponents)
|
|
606
795
|
.map(function (component) {
|
|
607
796
|
return "@ViewChild('".concat(component
|
|
608
797
|
.split('.')[1]
|
|
609
798
|
.toLowerCase(), "Template', { static: true }) ").concat(component
|
|
610
799
|
.split('.')[1]
|
|
611
|
-
.toLowerCase(), "TemplateRef!: TemplateRef<any>
|
|
800
|
+
.toLowerCase(), "TemplateRef").concat(options.typescript ? '!: TemplateRef<any>' : '');
|
|
612
801
|
})
|
|
613
|
-
.join('\n'), dynamicComponents.size ? '
|
|
802
|
+
.join('\n'), dynamicComponents.size ? "myContent".concat(options.typescript ? '?: any[][];' : '') : '', dataString, helperFunctions.size ? Array.from(helperFunctions).join('\n') : '', jsRefs
|
|
614
803
|
.map(function (ref) {
|
|
615
804
|
var argument = json.refs[ref].argument;
|
|
616
805
|
var typeParameter = json.refs[ref].typeParameter;
|
|
@@ -626,7 +815,9 @@ var componentToAngular = function (userOptions) {
|
|
|
626
815
|
})
|
|
627
816
|
.join('\n'), !hasConstructor && !dynamicComponents.size
|
|
628
817
|
? ''
|
|
629
|
-
: "constructor(\n".concat(injectables.join(',\n')).concat(dynamicComponents.size
|
|
818
|
+
: "constructor(\n".concat(injectables.join(',\n')).concat(dynamicComponents.size
|
|
819
|
+
? "\nprivate vcRef".concat(options.typescript ? ': ViewContainerRef' : '', ",\n")
|
|
820
|
+
: '', ") {\n ").concat(!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
|
|
630
821
|
? ''
|
|
631
822
|
: "\n ".concat((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, "\n "), "\n }\n "), !json.hooks.onMount.length && !dynamicComponents.size
|
|
632
823
|
? ''
|
|
@@ -640,7 +831,7 @@ var componentToAngular = function (userOptions) {
|
|
|
640
831
|
.join(', '), "];\n ")
|
|
641
832
|
: '', "\n }"), !((_k = json.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.length)
|
|
642
833
|
? ''
|
|
643
|
-
: "
|
|
834
|
+
: "ngOnChanges() {\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
|
|
644
835
|
code += hook.code;
|
|
645
836
|
return code + '\n';
|
|
646
837
|
}, ''), "\n }"), !json.hooks.onUnMount
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
2
2
|
export declare const BUILT_IN_COMPONENTS: Set<string>;
|
|
3
3
|
export interface ToAngularOptions extends BaseTranspilerOptions {
|
|
4
|
+
state?: 'class-properties' | 'inline-with-wrappers';
|
|
4
5
|
standalone?: boolean;
|
|
5
6
|
preserveImports?: boolean;
|
|
6
7
|
preserveFileExtensions?: boolean;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DEFAULT_ANGULAR_OPTIONS = exports.BUILT_IN_COMPONENTS = void 0;
|
|
4
4
|
exports.BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment', 'Slot']);
|
|
5
5
|
exports.DEFAULT_ANGULAR_OPTIONS = {
|
|
6
|
+
state: 'inline-with-wrappers',
|
|
6
7
|
preserveImports: false,
|
|
7
8
|
preserveFileExtensions: false,
|
|
8
9
|
visuallyIgnoreHostElement: true,
|
|
@@ -295,7 +295,7 @@ exports.components = {
|
|
|
295
295
|
name: 'div',
|
|
296
296
|
bindings: noUndefined({
|
|
297
297
|
css: (0, bindings_1.createSingleBinding)({
|
|
298
|
-
code: JSON.stringify(__assign(__assign({
|
|
298
|
+
code: JSON.stringify(__assign(__assign({ display: 'flex', flexDirection: 'column' }, css), { position: 'relative' })),
|
|
299
299
|
}),
|
|
300
300
|
}),
|
|
301
301
|
children: __spreadArray([
|