@builder.io/mitosis 0.5.27 → 0.5.28

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.
@@ -0,0 +1,10 @@
1
+ import { AngularBlockOptions, ToAngularOptions } from '../../generators/angular/types';
2
+ import { MitosisComponent } from '../../types/mitosis-component';
3
+ import { MitosisNode } from '../../types/mitosis-node';
4
+ export declare const blockToAngular: ({ root, json, options, blockOptions, rootRef, }: {
5
+ root: MitosisComponent;
6
+ json: MitosisNode;
7
+ options?: ToAngularOptions | undefined;
8
+ rootRef?: string | undefined;
9
+ blockOptions?: AngularBlockOptions | undefined;
10
+ }) => string;
@@ -0,0 +1,402 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.blockToAngular = void 0;
7
+ const html_tags_1 = require("../../constants/html_tags");
8
+ const helpers_1 = require("../../generators/angular/helpers");
9
+ const hooks_1 = require("../../generators/angular/helpers/hooks");
10
+ const parse_selector_1 = require("../../generators/angular/parse-selector");
11
+ const bindings_1 = require("../../helpers/bindings");
12
+ const event_handlers_1 = require("../../helpers/event-handlers");
13
+ const is_children_1 = __importDefault(require("../../helpers/is-children"));
14
+ const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
15
+ const remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
16
+ const slots_1 = require("../../helpers/slots");
17
+ const symbol_processor_1 = require("../../symbols/symbol-processor");
18
+ const mitosis_node_1 = require("../../types/mitosis-node");
19
+ const function_1 = require("fp-ts/function");
20
+ const lodash_1 = require("lodash");
21
+ const mappers = {
22
+ Fragment: (root, json, options, blockOptions) => {
23
+ return `<ng-container>${json.children
24
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
25
+ .join('\n')}</ng-container>`;
26
+ },
27
+ Slot: (root, json, options, blockOptions) => {
28
+ const renderChildren = () => {
29
+ var _a;
30
+ return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions })).join('\n');
31
+ };
32
+ return `<ng-content ${Object.entries({ ...json.bindings, ...json.properties })
33
+ .map(([binding, value]) => {
34
+ if (value && binding === 'name') {
35
+ const selector = (0, function_1.pipe)((0, lodash_1.isString)(value) ? value : value.code, slots_1.stripSlotPrefix, lodash_1.kebabCase);
36
+ return `select="[${selector}]"`;
37
+ }
38
+ })
39
+ .join('\n')}>${Object.entries(json.bindings)
40
+ .map(([binding, value]) => {
41
+ if (value && binding !== 'name') {
42
+ return value.code;
43
+ }
44
+ })
45
+ .join('\n')}${renderChildren()}</ng-content>`;
46
+ },
47
+ };
48
+ // TODO: Maybe in the future allow defining `string | function` as values
49
+ const BINDINGS_MAPPER = {
50
+ innerHTML: 'innerHTML',
51
+ style: 'ngStyle',
52
+ };
53
+ const handleNgOutletBindings = (node, options) => {
54
+ var _a;
55
+ let allProps = '';
56
+ for (const key in node.properties) {
57
+ if (key.startsWith('$')) {
58
+ continue;
59
+ }
60
+ if (key === 'key') {
61
+ continue;
62
+ }
63
+ const value = node.properties[key];
64
+ allProps += `${key}: '${value}', `;
65
+ }
66
+ for (const key in node.bindings) {
67
+ if (key.startsWith('"')) {
68
+ continue;
69
+ }
70
+ if (key.startsWith('$')) {
71
+ continue;
72
+ }
73
+ let { code, arguments: cusArgs = ['event'] } = node.bindings[key];
74
+ if (options.state === 'class-properties') {
75
+ code = `this.${code}`;
76
+ if (((_a = node.bindings[key]) === null || _a === void 0 ? void 0 : _a.type) === 'spread') {
77
+ allProps += `...${code}, `;
78
+ continue;
79
+ }
80
+ }
81
+ let keyToUse = key.includes('-') ? `'${key}'` : key;
82
+ keyToUse = keyToUse.replace('state.', '').replace('props.', '');
83
+ if ((0, event_handlers_1.checkIsEvent)(key)) {
84
+ const { event, value } = processEventBinding(key, code, node.name, cusArgs[0]);
85
+ allProps += `on${event.charAt(0).toUpperCase() + event.slice(1)}: ${value.replace(/\(.*?\)/g, '')}.bind(this), `;
86
+ }
87
+ else {
88
+ const codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
89
+ allProps += `${keyToUse}: ${codeToUse}, `;
90
+ }
91
+ }
92
+ if (allProps.endsWith(', ')) {
93
+ allProps = allProps.slice(0, -2);
94
+ }
95
+ if (allProps.startsWith(', ')) {
96
+ allProps = allProps.slice(2);
97
+ }
98
+ return allProps;
99
+ };
100
+ const handleObjectBindings = (code) => {
101
+ let objectCode = code.replace(/^{/, '').replace(/}$/, '');
102
+ objectCode = objectCode.replace(/\/\/.*\n/g, '');
103
+ let temp = objectCode;
104
+ //STEP 1. remove spread operator for expressions like '{ ...objectName }' and replace them with object name, example {...obj} => obj
105
+ temp = temp.replace(/\{\s*\.\.\.(\w+)\s*}/g, '$1');
106
+ //STEP 2. remove all remaining spread operators that could be nested somewhere deeper, example { ...obj, field1: value1 } => { obj, field1: value1 }
107
+ temp = temp.replace(/\.\.\./g, '');
108
+ //STEP 3. deal with consequences of STEP 2 - for all left field assignments we create new objects provided to useObjectWrapper,
109
+ //and we get rid of surrounding brackets of the initial input value, example {...obj1,test:true,...obj2} => obj1, {test: true}, obj2
110
+ temp = temp.replace(/(\s*\w+\s*:\s*((["'].+["'])|(\[.+])|([\w.]+)))(,|[\n\s]*)/g, `{ $1 },`);
111
+ // handle template strings
112
+ if (temp.includes('`')) {
113
+ // template str
114
+ let str = temp.match(/`[^`]*`/g);
115
+ let values = str && str[0].match(/\${[^}]*}/g);
116
+ let forValues = values === null || values === void 0 ? void 0 : values.map((val) => val.slice(2, -1)).join(' + ');
117
+ if (str && forValues) {
118
+ temp = temp.replace(str[0], forValues);
119
+ }
120
+ }
121
+ return temp;
122
+ };
123
+ const processCodeBlockInTemplate = (code) => {
124
+ // contains helper calls as Angular doesn't support JS expressions in templates
125
+ if (code.startsWith('{') && code.includes('...')) {
126
+ // Objects cannot be spread out directly in Angular so we need to use `useObjectWrapper`
127
+ return `useObjectWrapper(${handleObjectBindings(code)})`;
128
+ }
129
+ else if (code.startsWith('Object.values')) {
130
+ let stripped = code.replace('Object.values', '');
131
+ return `useObjectDotValues${stripped}`;
132
+ }
133
+ else if (code.includes('JSON.stringify')) {
134
+ let obj = code.match(/JSON.stringify\((.*)\)/);
135
+ return `useJsonStringify(${obj})`;
136
+ }
137
+ else if (code.includes(' as ')) {
138
+ const asIndex = code.indexOf('as');
139
+ const asCode = code.slice(0, asIndex - 1);
140
+ return `$any${asCode})`;
141
+ }
142
+ else {
143
+ return `${code}`;
144
+ }
145
+ };
146
+ const processEventBinding = (key, code, nodeName, customArg) => {
147
+ let event = key.replace('on', '');
148
+ event = event.charAt(0).toLowerCase() + event.slice(1);
149
+ // TODO: proper babel transform to replace. Util for this
150
+ const eventName = customArg;
151
+ const regexp = new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + eventName + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g');
152
+ const replacer = '$1$event$2';
153
+ const finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(code.replace(regexp, replacer));
154
+ return {
155
+ event,
156
+ value: finalValue,
157
+ };
158
+ };
159
+ const stringifyBinding = (node, options, blockOptions) => ([key, binding]) => {
160
+ var _a, _b;
161
+ if (key.startsWith('$') || key.startsWith('"') || key === 'key') {
162
+ return;
163
+ }
164
+ if ((binding === null || binding === void 0 ? void 0 : binding.type) === 'spread') {
165
+ return;
166
+ }
167
+ const keyToUse = BINDINGS_MAPPER[key] || key;
168
+ const { code, arguments: cusArgs = ['event'] } = binding;
169
+ // TODO: proper babel transform to replace. Util for this
170
+ if ((0, event_handlers_1.checkIsEvent)(keyToUse)) {
171
+ const { event, value } = processEventBinding(keyToUse, code, node.name, cusArgs[0]);
172
+ // native events are all lowerCased
173
+ const lowerCaseEvent = event.toLowerCase();
174
+ const eventKey = (0, event_handlers_1.checkIsBindingNativeEvent)(event) ||
175
+ ((_a = blockOptions.nativeEvents) === null || _a === void 0 ? void 0 : _a.find((nativeEvent) => nativeEvent === keyToUse || nativeEvent === event || nativeEvent === lowerCaseEvent))
176
+ ? lowerCaseEvent
177
+ : event;
178
+ return ` (${eventKey})="${value}"`;
179
+ }
180
+ else if (keyToUse === 'class') {
181
+ return ` [class]="${code}" `;
182
+ }
183
+ else if (keyToUse === 'ref' || keyToUse === 'spreadRef') {
184
+ return ` #${code} `;
185
+ }
186
+ else if ((html_tags_1.VALID_HTML_TAGS.includes(node.name.trim()) || keyToUse.includes('-')) &&
187
+ !((_b = blockOptions.nativeAttributes) === null || _b === void 0 ? void 0 : _b.includes(keyToUse)) &&
188
+ !Object.values(BINDINGS_MAPPER).includes(keyToUse)) {
189
+ // standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
190
+ return ` [attr.${keyToUse}]="${code}" `;
191
+ }
192
+ else {
193
+ const codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
194
+ return `[${keyToUse}]="${codeToUse}"`;
195
+ }
196
+ };
197
+ const blockToAngular = ({ root, json, options = {}, blockOptions = {
198
+ nativeAttributes: [],
199
+ nativeEvents: [],
200
+ }, rootRef, }) => {
201
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
202
+ const childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
203
+ if (mappers[json.name]) {
204
+ return mappers[json.name](root, json, options, blockOptions);
205
+ }
206
+ if ((0, is_children_1.default)({ node: json })) {
207
+ return `<ng-content></ng-content>`;
208
+ }
209
+ if (json.properties._text) {
210
+ return json.properties._text;
211
+ }
212
+ const textCode = (_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
213
+ if (textCode) {
214
+ if ((0, slots_1.isSlotProperty)(textCode)) {
215
+ return `<ng-content select="[${(0, slots_1.toKebabSlot)(textCode)}]"></ng-content>`;
216
+ }
217
+ if (textCode.includes('JSON.stringify')) {
218
+ const obj = textCode.replace(/JSON.stringify\(\s*(\w+)\s*,?.*\)/, '$1');
219
+ return `{{${obj} | json}}`;
220
+ }
221
+ return `{{${textCode}}}`;
222
+ }
223
+ let str = '';
224
+ if ((0, mitosis_node_1.checkIsForNode)(json)) {
225
+ const indexName = json.scope.indexName;
226
+ const forName = json.scope.forName;
227
+ // Check if "key" is present for the first child of the for loop
228
+ if ((0, helpers_1.hasFirstChildKeyAttribute)(json)) {
229
+ const fnIndex = ((_b = root.meta) === null || _b === void 0 ? void 0 : _b._trackByForIndex) || 0;
230
+ const trackByFnName = `trackBy${forName ? forName.charAt(0).toUpperCase() + forName.slice(1) : ''}${fnIndex}`;
231
+ root.meta._trackByForIndex = fnIndex + 1;
232
+ let code = (_c = json.children[0].bindings.key) === null || _c === void 0 ? void 0 : _c.code;
233
+ root.state[trackByFnName] = {
234
+ code: `${trackByFnName}(${indexName !== null && indexName !== void 0 ? indexName : '_'}, ${forName}) { return ${code}; }`,
235
+ type: 'method',
236
+ };
237
+ str += `<ng-container *ngFor="let ${forName !== null && forName !== void 0 ? forName : '_'} of ${(_d = json.bindings.each) === null || _d === void 0 ? void 0 : _d.code}${indexName ? `; index as ${indexName}` : ''}; trackBy: ${trackByFnName}">`;
238
+ }
239
+ else {
240
+ str += `<ng-container *ngFor="let ${forName !== null && forName !== void 0 ? forName : '_'} of ${(_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code}${indexName ? `; index as ${indexName}` : ''}">`;
241
+ }
242
+ str += json.children
243
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
244
+ .join('\n');
245
+ str += `</ng-container>`;
246
+ }
247
+ else if (json.name === 'Show') {
248
+ let condition = (_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code;
249
+ if (options.state === 'inline-with-wrappers' && (condition === null || condition === void 0 ? void 0 : condition.includes('typeof'))) {
250
+ let wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
251
+ condition = condition.replace(`typeof ${wordAfterTypeof}`, `useTypeOf(${wordAfterTypeof})`);
252
+ }
253
+ str += `<ng-container *ngIf="${condition}">`;
254
+ str += json.children
255
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
256
+ .join('\n');
257
+ str += `</ng-container>`;
258
+ // else condition
259
+ if ((0, is_mitosis_node_1.isMitosisNode)((_g = json.meta) === null || _g === void 0 ? void 0 : _g.else)) {
260
+ str += `<ng-container *ngIf="!(${condition})">`;
261
+ str += (0, exports.blockToAngular)({ root, json: json.meta.else, options, blockOptions });
262
+ str += `</ng-container>`;
263
+ }
264
+ }
265
+ else if (json.name.includes('.')) {
266
+ const elSelector = childComponents.find((impName) => impName === json.name)
267
+ ? (0, lodash_1.kebabCase)(json.name)
268
+ : json.name;
269
+ let allProps = handleNgOutletBindings(json, options);
270
+ if (options.state === 'class-properties') {
271
+ const inputsPropsStateName = `mergedInputs_${(0, symbol_processor_1.hashCodeAsString)(allProps)}`;
272
+ root.state[inputsPropsStateName] = {
273
+ code: '{}' + (options.typescript ? ' as any' : ''),
274
+ type: 'property',
275
+ };
276
+ if (!((_h = root.hooks.onInit) === null || _h === void 0 ? void 0 : _h.code.includes(inputsPropsStateName))) {
277
+ (0, hooks_1.addCodeToOnInit)(root, `this.${inputsPropsStateName} = {${allProps}};`);
278
+ }
279
+ if (!((_j = root.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.map((hook) => hook.code).join('').includes(inputsPropsStateName))) {
280
+ (0, hooks_1.addCodeToOnUpdate)(root, `this.${inputsPropsStateName} = {${allProps}};`);
281
+ }
282
+ allProps = `${inputsPropsStateName}`;
283
+ }
284
+ else {
285
+ allProps = `{ ${allProps} }`;
286
+ }
287
+ str += `<ng-container *ngComponentOutlet="
288
+ ${elSelector.replace('state.', '').replace('props.', '')};
289
+ inputs: ${allProps};
290
+ content: myContent;
291
+ "> `;
292
+ str += `</ng-container>`;
293
+ }
294
+ else {
295
+ let element, classNames = [], attributes;
296
+ const isComponent = childComponents.find((impName) => impName === json.name);
297
+ if (isComponent) {
298
+ const selector = json.meta.selector || (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.selector);
299
+ if (selector) {
300
+ try {
301
+ ({ element, classNames, attributes } = (0, parse_selector_1.parse)(`${selector}`));
302
+ }
303
+ catch (_r) {
304
+ element = (0, lodash_1.kebabCase)(json.name);
305
+ }
306
+ }
307
+ else {
308
+ element = (0, lodash_1.kebabCase)(json.name);
309
+ }
310
+ }
311
+ else {
312
+ element = json.name;
313
+ }
314
+ str += `<${element} `;
315
+ // TODO: merge with existing classes/bindings
316
+ if (classNames.length) {
317
+ str += `class="${classNames.join(' ')}" `;
318
+ }
319
+ // TODO: Merge with existing properties
320
+ if (attributes) {
321
+ Object.entries(attributes).forEach(([key, value]) => {
322
+ if (value) {
323
+ str += `${key}=${JSON.stringify(value)} `;
324
+ }
325
+ else {
326
+ str += `${key} `;
327
+ }
328
+ });
329
+ }
330
+ for (const key in json.properties) {
331
+ if (key.startsWith('$')) {
332
+ continue;
333
+ }
334
+ const value = json.properties[key];
335
+ str += ` ${key}="${value}" `;
336
+ }
337
+ for (const key in json.bindings) {
338
+ if (((_k = json.bindings[key]) === null || _k === void 0 ? void 0 : _k.type) === 'spread' && html_tags_1.VALID_HTML_TAGS.includes(json.name.trim())) {
339
+ if (((_l = json.bindings[key]) === null || _l === void 0 ? void 0 : _l.code) === 'this') {
340
+ // if its an arbitrary { ...props } spread then we skip because Angular needs a named prop to be defined
341
+ continue;
342
+ }
343
+ let refName = '';
344
+ if ((_m = json.bindings['spreadRef']) === null || _m === void 0 ? void 0 : _m.code) {
345
+ refName = json.bindings['spreadRef'].code;
346
+ }
347
+ else {
348
+ const spreadRefIndex = root.meta._spreadRefIndex || 0;
349
+ refName = `elRef${spreadRefIndex}`;
350
+ root.meta._spreadRefIndex = spreadRefIndex + 1;
351
+ json.bindings['spreadRef'] = (0, bindings_1.createSingleBinding)({ code: refName });
352
+ root.refs[refName] = { argument: '' };
353
+ }
354
+ json.bindings['spreadRef'] = (0, bindings_1.createSingleBinding)({ code: refName });
355
+ root.refs[refName] = { argument: '' };
356
+ root.meta.onViewInit = (root.meta.onViewInit || { code: '' });
357
+ let spreadCode = '';
358
+ let changesCode = '';
359
+ if ((_o = json.bindings[key]) === null || _o === void 0 ? void 0 : _o.code.startsWith('{')) {
360
+ json.meta._spreadStateRef = json.meta._spreadStateRef || 0;
361
+ const name = `${refName}_state_${json.meta._spreadStateRef}`;
362
+ json.meta._spreadStateRef = json.meta._spreadStateRef + 1;
363
+ (0, hooks_1.makeReactiveState)(root, name, `this.${name} = ${(_p = json.bindings[key]) === null || _p === void 0 ? void 0 : _p.code};`);
364
+ spreadCode = `this.${name}`;
365
+ changesCode = `changes['${spreadCode.replace('this.', '')}']?.currentValue`;
366
+ }
367
+ else {
368
+ spreadCode = `${(_q = json.bindings[key]) === null || _q === void 0 ? void 0 : _q.code}`;
369
+ changesCode = `changes['${spreadCode.replace('this.', '')}']?.currentValue`;
370
+ }
371
+ (0, hooks_1.addCodeNgAfterViewInit)(root, `\nthis.setAttributes(this.${refName}?.nativeElement, ${spreadCode});`);
372
+ (0, hooks_1.addCodeToOnUpdate)(root, `this.setAttributes(this.${refName}?.nativeElement, ${spreadCode}${changesCode ? `, ${changesCode}` : ''});`);
373
+ if (!root.state['setAttributes']) {
374
+ root.state['setAttributes'] = {
375
+ code: (0, helpers_1.HELPER_FUNCTIONS)(options === null || options === void 0 ? void 0 : options.typescript).setAttributes,
376
+ type: 'method',
377
+ };
378
+ }
379
+ }
380
+ }
381
+ const stringifiedBindings = Object.entries(json.bindings)
382
+ .map(stringifyBinding(json, options, blockOptions))
383
+ .join('');
384
+ str += stringifiedBindings;
385
+ if (rootRef && !str.includes(`#${rootRef}`)) {
386
+ // Add ref for passing attributes
387
+ str += `#${rootRef}`;
388
+ }
389
+ if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
390
+ return str + ' />';
391
+ }
392
+ str += '>';
393
+ if (json.children) {
394
+ str += json.children
395
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
396
+ .join('\n');
397
+ }
398
+ str += `</${element}>`;
399
+ }
400
+ return str;
401
+ };
402
+ exports.blockToAngular = blockToAngular;
@@ -1,9 +1,5 @@
1
- import { type MitosisComponent } from '../../types/mitosis-component';
2
- import { MitosisNode } from '../../types/mitosis-node';
3
- export declare const HELPER_FUNCTIONS: (isTs?: boolean) => {
4
- [key: string]: string;
5
- };
6
- export declare const getAppropriateTemplateFunctionKeys: (code: string) => string[];
1
+ import type { MitosisComponent } from '../../../types/mitosis-component';
2
+ export declare const addCodeNgAfterViewInit: (json: MitosisComponent, code: string) => void;
7
3
  /**
8
4
  * Adds code to the `onUpdate` hook of a MitosisComponent.
9
5
  *
@@ -27,15 +23,3 @@ export declare const addCodeToOnInit: (root: MitosisComponent, code: string) =>
27
23
  * @param code The code to be added to the onInit and onUpdate hooks.
28
24
  */
29
25
  export declare const makeReactiveState: (root: MitosisComponent, stateName: string, code: string) => void;
30
- export declare const getDefaultProps: ({ defaultProps }: MitosisComponent) => string;
31
- /**
32
- * if any state "property" is trying to access state.* or props.*
33
- * then we need to move them to onInit where they can be accessed
34
- * @param json The MitosisComponent.
35
- */
36
- export declare const transformState: (json: MitosisComponent) => void;
37
- /**
38
- * Checks if the first child has a "key" attribute - used for "For" elements
39
- * @param node The node which should be "For"
40
- */
41
- export declare const hasFirstChildKeyAttribute: (node: MitosisNode) => boolean;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeReactiveState = exports.addCodeToOnInit = exports.addCodeToOnUpdate = exports.addCodeNgAfterViewInit = void 0;
4
+ const addCodeNgAfterViewInit = (json, code) => {
5
+ if (!json.compileContext) {
6
+ json.compileContext = {
7
+ angular: {
8
+ hooks: {
9
+ ngAfterViewInit: {
10
+ code: '',
11
+ },
12
+ },
13
+ },
14
+ };
15
+ }
16
+ json.compileContext.angular.hooks.ngAfterViewInit.code += code;
17
+ };
18
+ exports.addCodeNgAfterViewInit = addCodeNgAfterViewInit;
19
+ /**
20
+ * Adds code to the `onUpdate` hook of a MitosisComponent.
21
+ *
22
+ * @param {MitosisComponent} root - The root MitosisComponent.
23
+ * @param {string} code - The code to be added to the `onUpdate` hook.
24
+ */
25
+ const addCodeToOnUpdate = (root, code) => {
26
+ root.hooks.onUpdate = root.hooks.onUpdate || [];
27
+ root.hooks.onUpdate.push({
28
+ code,
29
+ });
30
+ };
31
+ exports.addCodeToOnUpdate = addCodeToOnUpdate;
32
+ /**
33
+ * Adds code to the `onInit` hook of a MitosisComponent.
34
+ *
35
+ * @param {MitosisComponent} root - The root MitosisComponent.
36
+ * @param {string} code - The code to be added to the `onInit` hook.
37
+ */
38
+ const addCodeToOnInit = (root, code) => {
39
+ var _a;
40
+ if (!((_a = root.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code)) {
41
+ root.hooks.onInit = { code: '' };
42
+ }
43
+ root.hooks.onInit.code += `\n${code};`;
44
+ };
45
+ exports.addCodeToOnInit = addCodeToOnInit;
46
+ /**
47
+ * Creates a reactive state in Angular.
48
+ * Initializes the state with `null` because we cannot access `state.` or `props.` properties before the component is initialized.
49
+ * Adds the code (init/re-init code) to the `onInit` and `onUpdate` hooks.
50
+ * @param root The root MitosisComponent.
51
+ * @param stateName The name of the reactive state.
52
+ * @param code The code to be added to the onInit and onUpdate hooks.
53
+ */
54
+ const makeReactiveState = (root, stateName, code) => {
55
+ root.state[stateName] = { code: 'null', type: 'property' };
56
+ (0, exports.addCodeToOnInit)(root, code);
57
+ (0, exports.addCodeToOnUpdate)(root, code);
58
+ };
59
+ exports.makeReactiveState = makeReactiveState;
@@ -0,0 +1,18 @@
1
+ import { type MitosisComponent } from '../../../types/mitosis-component';
2
+ import { MitosisNode } from '../../../types/mitosis-node';
3
+ export declare const HELPER_FUNCTIONS: (isTs?: boolean) => {
4
+ [key: string]: string;
5
+ };
6
+ export declare const getAppropriateTemplateFunctionKeys: (code: string) => string[];
7
+ export declare const getDefaultProps: ({ defaultProps }: MitosisComponent) => string;
8
+ /**
9
+ * if any state "property" is trying to access state.* or props.*
10
+ * then we need to move them to onInit where they can be accessed
11
+ * @param json The MitosisComponent.
12
+ */
13
+ export declare const transformState: (json: MitosisComponent) => void;
14
+ /**
15
+ * Checks if the first child has a "key" attribute - used for "For" elements
16
+ * @param node The node which should be "For"
17
+ */
18
+ export declare const hasFirstChildKeyAttribute: (node: MitosisNode) => boolean;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasFirstChildKeyAttribute = exports.transformState = exports.getDefaultProps = exports.makeReactiveState = exports.addCodeToOnInit = exports.addCodeToOnUpdate = exports.getAppropriateTemplateFunctionKeys = exports.HELPER_FUNCTIONS = void 0;
4
- const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
3
+ exports.hasFirstChildKeyAttribute = exports.transformState = exports.getDefaultProps = exports.getAppropriateTemplateFunctionKeys = exports.HELPER_FUNCTIONS = void 0;
4
+ const strip_state_and_props_refs_1 = require("../../../helpers/strip-state-and-props-refs");
5
5
  const HELPER_FUNCTIONS = (isTs) => ({
6
6
  useObjectWrapper: `useObjectWrapper(...args${isTs ? ': any[]' : ''}) {
7
7
  let obj = {}
@@ -43,47 +43,6 @@ const HELPER_FUNCTIONS = (isTs) => ({
43
43
  exports.HELPER_FUNCTIONS = HELPER_FUNCTIONS;
44
44
  const getAppropriateTemplateFunctionKeys = (code) => Object.keys((0, exports.HELPER_FUNCTIONS)()).filter((key) => code.includes(key));
45
45
  exports.getAppropriateTemplateFunctionKeys = getAppropriateTemplateFunctionKeys;
46
- /**
47
- * Adds code to the `onUpdate` hook of a MitosisComponent.
48
- *
49
- * @param {MitosisComponent} root - The root MitosisComponent.
50
- * @param {string} code - The code to be added to the `onUpdate` hook.
51
- */
52
- const addCodeToOnUpdate = (root, code) => {
53
- root.hooks.onUpdate = root.hooks.onUpdate || [];
54
- root.hooks.onUpdate.push({
55
- code,
56
- });
57
- };
58
- exports.addCodeToOnUpdate = addCodeToOnUpdate;
59
- /**
60
- * Adds code to the `onInit` hook of a MitosisComponent.
61
- *
62
- * @param {MitosisComponent} root - The root MitosisComponent.
63
- * @param {string} code - The code to be added to the `onInit` hook.
64
- */
65
- const addCodeToOnInit = (root, code) => {
66
- var _a;
67
- if (!((_a = root.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code)) {
68
- root.hooks.onInit = { code: '' };
69
- }
70
- root.hooks.onInit.code += `\n${code};`;
71
- };
72
- exports.addCodeToOnInit = addCodeToOnInit;
73
- /**
74
- * Creates a reactive state in Angular.
75
- * Initializes the state with `null` because we cannot access `state.` or `props.` properties before the component is initialized.
76
- * Adds the code (init/re-init code) to the `onInit` and `onUpdate` hooks.
77
- * @param root The root MitosisComponent.
78
- * @param stateName The name of the reactive state.
79
- * @param code The code to be added to the onInit and onUpdate hooks.
80
- */
81
- const makeReactiveState = (root, stateName, code) => {
82
- root.state[stateName] = { code: 'null', type: 'property' };
83
- (0, exports.addCodeToOnInit)(root, code);
84
- (0, exports.addCodeToOnUpdate)(root, code);
85
- };
86
- exports.makeReactiveState = makeReactiveState;
87
46
  const getDefaultProps = ({ defaultProps }) => {
88
47
  if (!defaultProps)
89
48
  return '';
@@ -1,11 +1,3 @@
1
- import { MitosisComponent } from '../../types/mitosis-component';
2
- import { MitosisNode } from '../../types/mitosis-node';
3
1
  import { TranspilerGenerator } from '../../types/transpiler';
4
- import { AngularBlockOptions, ToAngularOptions } from './types';
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;
2
+ import { ToAngularOptions } from './types';
11
3
  export declare const componentToAngular: TranspilerGenerator<ToAngularOptions>;