@builder.io/mitosis 0.5.22 → 0.5.24
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 +6 -0
- package/dist/src/generators/angular/helpers.js +14 -1
- package/dist/src/generators/angular/index.js +57 -22
- package/dist/src/generators/angular/parse-selector.d.ts +5 -0
- package/dist/src/generators/angular/parse-selector.js +19 -0
- package/dist/src/generators/helpers/functions.d.ts +2 -2
- package/dist/src/generators/react/helpers.js +3 -2
- package/dist/src/generators/stencil/plugins/get-code-processor-plugins.d.ts +1 -1
- package/dist/src/helpers/component-file-extensions.js +21 -5
- package/dist/src/helpers/on-event.d.ts +2 -2
- package/dist/src/helpers/plugins/process-code/index.d.ts +2 -2
- package/dist/src/helpers/plugins/process-signals.d.ts +3 -3
- package/dist/src/helpers/plugins/process-target-blocks.d.ts +2 -2
- package/dist/src/modules/plugins.d.ts +6 -6
- package/dist/src/parsers/svelte/helpers/post-process.d.ts +1 -1
- package/dist/src/plugins/compile-away-builder-components.d.ts +2 -2
- package/dist/src/types/config.d.ts +11 -2
- package/dist/src/types/mitosis-component.d.ts +9 -0
- package/dist/src/types/plugins.d.ts +17 -9
- package/dist/src/types/transpiler.d.ts +12 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type MitosisComponent } from '../../types/mitosis-component';
|
|
2
|
+
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
3
|
export declare const HELPER_FUNCTIONS: (isTs?: boolean) => {
|
|
3
4
|
[key: string]: string;
|
|
4
5
|
};
|
|
@@ -33,3 +34,8 @@ export declare const getDefaultProps: ({ defaultProps }: MitosisComponent) => st
|
|
|
33
34
|
* @param json The MitosisComponent.
|
|
34
35
|
*/
|
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformState = exports.getDefaultProps = exports.makeReactiveState = exports.addCodeToOnInit = exports.addCodeToOnUpdate = exports.getAppropriateTemplateFunctionKeys = exports.HELPER_FUNCTIONS = void 0;
|
|
3
|
+
exports.hasFirstChildKeyAttribute = exports.transformState = exports.getDefaultProps = exports.makeReactiveState = exports.addCodeToOnInit = exports.addCodeToOnUpdate = exports.getAppropriateTemplateFunctionKeys = exports.HELPER_FUNCTIONS = void 0;
|
|
4
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[]' : ''}) {
|
|
@@ -120,3 +120,16 @@ const transformState = (json) => {
|
|
|
120
120
|
});
|
|
121
121
|
};
|
|
122
122
|
exports.transformState = transformState;
|
|
123
|
+
/**
|
|
124
|
+
* Checks if the first child has a "key" attribute - used for "For" elements
|
|
125
|
+
* @param node The node which should be "For"
|
|
126
|
+
*/
|
|
127
|
+
const hasFirstChildKeyAttribute = (node) => {
|
|
128
|
+
var _a;
|
|
129
|
+
if (!node.children || node.children.length === 0) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const firstChildBinding = node.children[0].bindings;
|
|
133
|
+
return Boolean(firstChildBinding && ((_a = firstChildBinding.key) === null || _a === void 0 ? void 0 : _a.code));
|
|
134
|
+
};
|
|
135
|
+
exports.hasFirstChildKeyAttribute = hasFirstChildKeyAttribute;
|
|
@@ -67,6 +67,7 @@ const is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
|
67
67
|
const on_mount_1 = require("../helpers/on-mount");
|
|
68
68
|
const helpers_2 = require("./helpers");
|
|
69
69
|
const types_1 = require("./types");
|
|
70
|
+
const parse_selector_1 = require("./parse-selector");
|
|
70
71
|
const { types } = babel;
|
|
71
72
|
const mappers = {
|
|
72
73
|
Fragment: (root, json, options, blockOptions) => {
|
|
@@ -268,7 +269,7 @@ const handleNgOutletBindings = (node, options) => {
|
|
|
268
269
|
const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
269
270
|
nativeAttributes: [],
|
|
270
271
|
}, }) => {
|
|
271
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q
|
|
272
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
272
273
|
const childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
273
274
|
if (mappers[json.name]) {
|
|
274
275
|
return mappers[json.name](root, json, options, blockOptions);
|
|
@@ -295,19 +296,19 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
295
296
|
const indexName = json.scope.indexName;
|
|
296
297
|
const forName = json.scope.forName;
|
|
297
298
|
// Check if "key" is present for the first child of the for loop
|
|
298
|
-
if (
|
|
299
|
-
const fnIndex = ((
|
|
299
|
+
if ((0, helpers_2.hasFirstChildKeyAttribute)(json)) {
|
|
300
|
+
const fnIndex = ((_b = root.meta) === null || _b === void 0 ? void 0 : _b._trackByForIndex) || 0;
|
|
300
301
|
const trackByFnName = `trackBy${forName ? forName.charAt(0).toUpperCase() + forName.slice(1) : ''}${fnIndex}`;
|
|
301
302
|
root.meta._trackByForIndex = fnIndex + 1;
|
|
302
|
-
let code = (
|
|
303
|
+
let code = (_c = json.children[0].bindings.key) === null || _c === void 0 ? void 0 : _c.code;
|
|
303
304
|
root.state[trackByFnName] = {
|
|
304
305
|
code: `${trackByFnName}(${indexName !== null && indexName !== void 0 ? indexName : '_'}, ${forName}) { return ${code}; }`,
|
|
305
306
|
type: 'method',
|
|
306
307
|
};
|
|
307
|
-
str += `<ng-container *ngFor="let ${forName !== null && forName !== void 0 ? forName : '_'} of ${(
|
|
308
|
+
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}">`;
|
|
308
309
|
}
|
|
309
310
|
else {
|
|
310
|
-
str += `<ng-container *ngFor="let ${forName !== null && forName !== void 0 ? forName : '_'} of ${(
|
|
311
|
+
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}` : ''}">`;
|
|
311
312
|
}
|
|
312
313
|
str += json.children
|
|
313
314
|
.map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
|
|
@@ -315,7 +316,7 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
315
316
|
str += `</ng-container>`;
|
|
316
317
|
}
|
|
317
318
|
else if (json.name === 'Show') {
|
|
318
|
-
let condition = (
|
|
319
|
+
let condition = (_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code;
|
|
319
320
|
if (options.state === 'inline-with-wrappers' && (condition === null || condition === void 0 ? void 0 : condition.includes('typeof'))) {
|
|
320
321
|
let wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
|
|
321
322
|
condition = condition.replace(`typeof ${wordAfterTypeof}`, `useTypeOf(${wordAfterTypeof})`);
|
|
@@ -326,7 +327,7 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
326
327
|
.join('\n');
|
|
327
328
|
str += `</ng-container>`;
|
|
328
329
|
// else condition
|
|
329
|
-
if ((0, is_mitosis_node_1.isMitosisNode)((
|
|
330
|
+
if ((0, is_mitosis_node_1.isMitosisNode)((_g = json.meta) === null || _g === void 0 ? void 0 : _g.else)) {
|
|
330
331
|
str += `<ng-container *ngIf="!(${condition})">`;
|
|
331
332
|
str += (0, exports.blockToAngular)({ root, json: json.meta.else, options, blockOptions });
|
|
332
333
|
str += `</ng-container>`;
|
|
@@ -343,10 +344,10 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
343
344
|
code: '{}' + (options.typescript ? ' as any' : ''),
|
|
344
345
|
type: 'property',
|
|
345
346
|
};
|
|
346
|
-
if (!((
|
|
347
|
+
if (!((_h = root.hooks.onInit) === null || _h === void 0 ? void 0 : _h.code.includes(inputsPropsStateName))) {
|
|
347
348
|
(0, helpers_2.addCodeToOnInit)(root, `this.${inputsPropsStateName} = {${allProps}};`);
|
|
348
349
|
}
|
|
349
|
-
if (!((
|
|
350
|
+
if (!((_j = root.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.map((hook) => hook.code).join('').includes(inputsPropsStateName))) {
|
|
350
351
|
(0, helpers_2.addCodeToOnUpdate)(root, `this.${inputsPropsStateName} = {${allProps}};`);
|
|
351
352
|
}
|
|
352
353
|
allProps = `${inputsPropsStateName}`;
|
|
@@ -362,10 +363,41 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
362
363
|
str += `</ng-container>`;
|
|
363
364
|
}
|
|
364
365
|
else {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
366
|
+
let element, classNames = [], attributes;
|
|
367
|
+
const isComponent = childComponents.find((impName) => impName === json.name);
|
|
368
|
+
if (isComponent) {
|
|
369
|
+
const selector = json.meta.selector || (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.selector);
|
|
370
|
+
if (selector) {
|
|
371
|
+
try {
|
|
372
|
+
({ element, classNames, attributes } = (0, parse_selector_1.parse)(`${selector}`));
|
|
373
|
+
}
|
|
374
|
+
catch (_r) {
|
|
375
|
+
element = (0, lodash_1.kebabCase)(json.name);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
element = (0, lodash_1.kebabCase)(json.name);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
element = json.name;
|
|
384
|
+
}
|
|
385
|
+
str += `<${element} `;
|
|
386
|
+
// TODO: merge with existing classes/bindings
|
|
387
|
+
if (classNames.length) {
|
|
388
|
+
str += `class="${classNames.join(' ')}" `;
|
|
389
|
+
}
|
|
390
|
+
// TODO: Merge with existing properties
|
|
391
|
+
if (attributes) {
|
|
392
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
393
|
+
if (value) {
|
|
394
|
+
str += `${key}=${JSON.stringify(value)} `;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
str += `${key} `;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
369
401
|
for (const key in json.properties) {
|
|
370
402
|
if (key.startsWith('$')) {
|
|
371
403
|
continue;
|
|
@@ -374,13 +406,13 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
374
406
|
str += ` ${key}="${value}" `;
|
|
375
407
|
}
|
|
376
408
|
for (const key in json.bindings) {
|
|
377
|
-
if (((
|
|
378
|
-
if (((
|
|
409
|
+
if (((_k = json.bindings[key]) === null || _k === void 0 ? void 0 : _k.type) === 'spread' && html_tags_1.VALID_HTML_TAGS.includes(json.name.trim())) {
|
|
410
|
+
if (((_l = json.bindings[key]) === null || _l === void 0 ? void 0 : _l.code) === 'this') {
|
|
379
411
|
// if its an arbitrary { ...props } spread then we skip because Angular needs a named prop to be defined
|
|
380
412
|
continue;
|
|
381
413
|
}
|
|
382
414
|
let refName = '';
|
|
383
|
-
if ((
|
|
415
|
+
if ((_m = json.bindings['spreadRef']) === null || _m === void 0 ? void 0 : _m.code) {
|
|
384
416
|
refName = json.bindings['spreadRef'].code;
|
|
385
417
|
}
|
|
386
418
|
else {
|
|
@@ -395,16 +427,16 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
395
427
|
root.meta.onViewInit = (root.meta.onViewInit || { code: '' });
|
|
396
428
|
let spreadCode = '';
|
|
397
429
|
let changesCode = '';
|
|
398
|
-
if ((
|
|
430
|
+
if ((_o = json.bindings[key]) === null || _o === void 0 ? void 0 : _o.code.startsWith('{')) {
|
|
399
431
|
json.meta._spreadStateRef = json.meta._spreadStateRef || 0;
|
|
400
432
|
const name = `${refName}_state_${json.meta._spreadStateRef}`;
|
|
401
433
|
json.meta._spreadStateRef = json.meta._spreadStateRef + 1;
|
|
402
|
-
(0, helpers_2.makeReactiveState)(root, name, `this.${name} = ${(
|
|
434
|
+
(0, helpers_2.makeReactiveState)(root, name, `this.${name} = ${(_p = json.bindings[key]) === null || _p === void 0 ? void 0 : _p.code};`);
|
|
403
435
|
spreadCode = `this.${name}`;
|
|
404
436
|
changesCode = `changes['${spreadCode.replace('this.', '')}']?.currentValue`;
|
|
405
437
|
}
|
|
406
438
|
else {
|
|
407
|
-
spreadCode = `${(
|
|
439
|
+
spreadCode = `${(_q = json.bindings[key]) === null || _q === void 0 ? void 0 : _q.code}`;
|
|
408
440
|
changesCode = `changes['${spreadCode.replace('this.', '')}']?.currentValue`;
|
|
409
441
|
}
|
|
410
442
|
if (!root.compileContext) {
|
|
@@ -441,7 +473,7 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
441
473
|
.map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
|
|
442
474
|
.join('\n');
|
|
443
475
|
}
|
|
444
|
-
str += `</${
|
|
476
|
+
str += `</${element}>`;
|
|
445
477
|
}
|
|
446
478
|
return str;
|
|
447
479
|
};
|
|
@@ -655,11 +687,14 @@ const componentToAngular = (userOptions = {}) => ({ component: _component }) =>
|
|
|
655
687
|
// so we need to use `this.` inside the class to access state and props
|
|
656
688
|
const isSpreadAttributeBinding = ((_a = node === null || node === void 0 ? void 0 : node.bindings[key]) === null || _a === void 0 ? void 0 : _a.type) === 'spread' &&
|
|
657
689
|
html_tags_1.VALID_HTML_TAGS.includes(node.name.trim());
|
|
690
|
+
// If we have a For loop with "key" it will be transformed to
|
|
691
|
+
// trackOfXXX, we need to use "this" for state properties
|
|
692
|
+
const isKey = key === 'key';
|
|
658
693
|
const newLocal = processAngularCode({
|
|
659
694
|
contextVars: [],
|
|
660
695
|
outputVars,
|
|
661
696
|
domRefs: [], // the template doesn't need the this keyword.
|
|
662
|
-
replaceWith: isSpreadAttributeBinding ? 'this' : undefined,
|
|
697
|
+
replaceWith: isKey || isSpreadAttributeBinding ? 'this' : undefined,
|
|
663
698
|
})(code);
|
|
664
699
|
return newLocal.replace(/"/g, '"');
|
|
665
700
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
const compiler_1 = require("@angular/compiler");
|
|
5
|
+
function parse(selector) {
|
|
6
|
+
const { element, classNames, attrs } = compiler_1.CssSelector.parse(selector)[0];
|
|
7
|
+
const attributes = attrs.reduce((acc, attr, i) => {
|
|
8
|
+
if (i % 2 === 0) {
|
|
9
|
+
acc[attr] = attrs[i + 1];
|
|
10
|
+
}
|
|
11
|
+
return acc;
|
|
12
|
+
}, {});
|
|
13
|
+
return {
|
|
14
|
+
element,
|
|
15
|
+
classNames,
|
|
16
|
+
attributes,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.parse = parse;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const FUNCTION_HACK_PLUGIN:
|
|
1
|
+
import { MitosisPlugin } from '../../modules/plugins';
|
|
2
|
+
export declare const FUNCTION_HACK_PLUGIN: MitosisPlugin;
|
|
@@ -30,8 +30,9 @@ function getFragment(type, options, node) {
|
|
|
30
30
|
let tag = '';
|
|
31
31
|
if (node && node.bindings && (0, exports.isFragmentWithKey)(node)) {
|
|
32
32
|
tag = options.preact ? 'Fragment' : 'React.Fragment';
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const keyCode = (_a = node.bindings['key']) === null || _a === void 0 ? void 0 : _a.code;
|
|
34
|
+
if (type === 'open' && keyCode) {
|
|
35
|
+
tag += ` key={${(0, exports.processBinding)(keyCode, options)}}`;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
else if (options.preact) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProcessBindingOptions } from '../../../generators/stencil/helpers/index';
|
|
2
2
|
import { ToStencilOptions } from '../../../generators/stencil/types';
|
|
3
|
-
export declare const getCodeProcessorPlugins: (options: ToStencilOptions, processBindingOptions: ProcessBindingOptions) => import("../../..").
|
|
3
|
+
export declare const getCodeProcessorPlugins: (options: ToStencilOptions, processBindingOptions: ProcessBindingOptions) => import("../../..").MitosisPlugin[];
|
|
@@ -19,11 +19,27 @@ exports.checkIsMitosisComponentFilePath = checkIsMitosisComponentFilePath;
|
|
|
19
19
|
* Matches `.svelte`, `.lite.tsx`, `.lite.jsx` files (with optional `.jsx`/`.tsx` extension)
|
|
20
20
|
*/
|
|
21
21
|
exports.INPUT_EXTENSION_REGEX = /\.(svelte|(lite(\.tsx|\.jsx)?))/g;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const getExplicitFileExtension = (path, explicitBuildFileExtensions) => {
|
|
23
|
+
if (explicitBuildFileExtensions) {
|
|
24
|
+
for (const [extension, regex] of Object.entries(explicitBuildFileExtensions)) {
|
|
25
|
+
const match = path.match(regex);
|
|
26
|
+
if (match) {
|
|
27
|
+
return extension;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
const renameComponentFile = ({ path, target, options, }) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const explicitExtension = getExplicitFileExtension(path, (_a = options.options[target]) === null || _a === void 0 ? void 0 : _a.explicitBuildFileExtensions);
|
|
36
|
+
const extension = explicitExtension !== null && explicitExtension !== void 0 ? explicitExtension : (0, exports.getComponentFileExtensionForTarget)({
|
|
37
|
+
type: 'filename',
|
|
38
|
+
target,
|
|
39
|
+
isTypescript: (0, output_1.checkShouldOutputTypeScript)({ options, target }),
|
|
40
|
+
});
|
|
41
|
+
return path.replace(exports.INPUT_EXTENSION_REGEX, extension);
|
|
42
|
+
};
|
|
27
43
|
exports.renameComponentFile = renameComponentFile;
|
|
28
44
|
/**
|
|
29
45
|
* just like `INPUT_EXTENSION_REGEX`, but adds trailing quotes to the end of import paths.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MitosisComponent, MitosisNode,
|
|
1
|
+
import { MitosisComponent, MitosisNode, MitosisPlugin, OnEventHook } from '..';
|
|
2
2
|
export declare const getOnEventHandlerName: (hook: OnEventHook) => string;
|
|
3
3
|
export declare const getOnEventHooksForNode: ({ node, component, }: {
|
|
4
4
|
node: MitosisNode;
|
|
@@ -11,4 +11,4 @@ export declare const getOnEventHooksForNode: ({ node, component, }: {
|
|
|
11
11
|
export declare const processOnEventHooksPlugin: (args?: {
|
|
12
12
|
setBindings?: boolean;
|
|
13
13
|
includeRootEvents?: boolean;
|
|
14
|
-
}) =>
|
|
14
|
+
}) => MitosisPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MitosisComponent } from '../../../types/mitosis-component';
|
|
2
|
-
import {
|
|
2
|
+
import { MitosisPlugin } from '../../../types/plugins';
|
|
3
3
|
import { CodeProcessor } from './types';
|
|
4
4
|
export declare const createCodeProcessorPlugin: (codeProcessor: CodeProcessor, { processProperties }?: {
|
|
5
5
|
processProperties?: boolean | undefined;
|
|
@@ -9,4 +9,4 @@ export declare const createCodeProcessorPlugin: (codeProcessor: CodeProcessor, {
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const CODE_PROCESSOR_PLUGIN: (codeProcessor: (codeType: import("./types").CodeType, json: MitosisComponent, node?: import("../../..").MitosisNode | undefined) => (code: string, hookType: string) => string | (() => void), a_1?: {
|
|
11
11
|
processProperties?: boolean | undefined;
|
|
12
|
-
} | undefined) =>
|
|
12
|
+
} | undefined) => MitosisPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node, types } from '@babel/core';
|
|
2
2
|
import { Target } from '../../types/config';
|
|
3
|
-
import {
|
|
3
|
+
import { MitosisPlugin } from '../../types/plugins';
|
|
4
4
|
export declare const replaceSignalSetters: ({ code, nodeMaps, }: {
|
|
5
5
|
code: string;
|
|
6
6
|
nodeMaps: {
|
|
@@ -13,10 +13,10 @@ export declare const replaceSignalSetters: ({ code, nodeMaps, }: {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const getSignalTypePlugin: ({ target }: {
|
|
15
15
|
target: Target;
|
|
16
|
-
}) =>
|
|
16
|
+
}) => MitosisPlugin;
|
|
17
17
|
/**
|
|
18
18
|
* Processes `mySignal.value` accessors for props, context, and state.
|
|
19
19
|
*/
|
|
20
20
|
export declare const getSignalAccessPlugin: ({ target }: {
|
|
21
21
|
target: Target;
|
|
22
|
-
}) =>
|
|
22
|
+
}) => MitosisPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Targets } from '../../targets';
|
|
2
|
-
import {
|
|
2
|
+
import { MitosisPlugin } from '../../types/plugins';
|
|
3
3
|
/**
|
|
4
4
|
* Processes `useTarget()` blocks for a given target.
|
|
5
5
|
*/
|
|
6
|
-
export declare const processTargetBlocks: (target: Targets) =>
|
|
6
|
+
export declare const processTargetBlocks: (target: Targets) => MitosisPlugin;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { MitosisComponent } from '../types/mitosis-component';
|
|
2
|
-
import {
|
|
3
|
-
export type {
|
|
2
|
+
import { MitosisPlugin } from '../types/plugins';
|
|
3
|
+
export type { MitosisPlugin };
|
|
4
4
|
export declare const runPreJsonPlugins: ({ json, plugins, options, }: {
|
|
5
5
|
json: MitosisComponent;
|
|
6
|
-
plugins:
|
|
6
|
+
plugins: MitosisPlugin[];
|
|
7
7
|
options?: any;
|
|
8
8
|
}) => MitosisComponent;
|
|
9
9
|
export declare const runPostJsonPlugins: ({ json, plugins, options, }: {
|
|
10
10
|
json: MitosisComponent;
|
|
11
|
-
plugins:
|
|
11
|
+
plugins: MitosisPlugin[];
|
|
12
12
|
options?: any;
|
|
13
13
|
}) => MitosisComponent;
|
|
14
14
|
export declare const runPreCodePlugins: ({ code, plugins, options, json, }: {
|
|
15
15
|
json: MitosisComponent;
|
|
16
16
|
code: string;
|
|
17
|
-
plugins:
|
|
17
|
+
plugins: MitosisPlugin[];
|
|
18
18
|
options?: any;
|
|
19
19
|
}) => string;
|
|
20
20
|
export declare const runPostCodePlugins: ({ code, plugins, options, json, }: {
|
|
21
21
|
json: MitosisComponent;
|
|
22
22
|
code: string;
|
|
23
|
-
plugins:
|
|
23
|
+
plugins: MitosisPlugin[];
|
|
24
24
|
options?: any;
|
|
25
25
|
}) => string;
|
|
@@ -7,7 +7,7 @@ type SveltosisStateValue = StateValue & {
|
|
|
7
7
|
export declare function preventNameCollissions(json: SveltosisComponent, item: SveltosisStateValue): {
|
|
8
8
|
code: string;
|
|
9
9
|
typeParameter?: string | undefined;
|
|
10
|
-
type: "function" | "
|
|
10
|
+
type: "function" | "method" | "property" | "getter";
|
|
11
11
|
propertyType?: import("../../../types/mitosis-component").ReactivityType | undefined;
|
|
12
12
|
arguments?: string[] | undefined;
|
|
13
13
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MitosisPlugin } from '..';
|
|
2
2
|
import { TraverseContext } from 'neotraverse/legacy';
|
|
3
3
|
import { MitosisComponent } from '../types/mitosis-component';
|
|
4
4
|
import { MitosisNode } from '../types/mitosis-node';
|
|
@@ -11,5 +11,5 @@ type CompileAwayBuilderComponentsOptions = {
|
|
|
11
11
|
omit?: string[];
|
|
12
12
|
};
|
|
13
13
|
export declare const compileAwayBuilderComponentsFromTree: (tree: MitosisNode | MitosisComponent, components: CompileAwayComponentsMap) => void;
|
|
14
|
-
export declare const compileAwayBuilderComponents: (pluginOptions?: CompileAwayBuilderComponentsOptions) =>
|
|
14
|
+
export declare const compileAwayBuilderComponents: (pluginOptions?: CompileAwayBuilderComponentsOptions) => MitosisPlugin;
|
|
15
15
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ParseMitosisOptions } from '../parsers/jsx
|
|
1
|
+
import type { ParseMitosisOptions } from '../parsers/jsx';
|
|
2
2
|
import { targets } from '../targets';
|
|
3
3
|
import type { MitosisComponent } from './mitosis-component';
|
|
4
|
-
import { BaseTranspilerOptions } from './transpiler';
|
|
4
|
+
import { BaseTranspilerOptions, TranspilerGenerator } from './transpiler';
|
|
5
5
|
export type Format = 'esm' | 'cjs';
|
|
6
6
|
export type Language = 'js' | 'ts';
|
|
7
7
|
interface TranspilerOptions {
|
|
@@ -17,6 +17,15 @@ export type GeneratorOptions = {
|
|
|
17
17
|
export type generatorsOption = {
|
|
18
18
|
[K in Target]: NonNullable<Targets[K]>;
|
|
19
19
|
};
|
|
20
|
+
export interface TargetContext {
|
|
21
|
+
target: Target;
|
|
22
|
+
generator: TranspilerGenerator<NonNullable<MitosisConfig['options'][Target]>>;
|
|
23
|
+
outputPath: string;
|
|
24
|
+
}
|
|
25
|
+
export interface OutputFiles {
|
|
26
|
+
outputDir: string;
|
|
27
|
+
outputFilePath: string;
|
|
28
|
+
}
|
|
20
29
|
export type MitosisConfig = {
|
|
21
30
|
generators?: generatorsOption;
|
|
22
31
|
/**
|
|
@@ -136,6 +136,15 @@ export type MitosisComponent = {
|
|
|
136
136
|
propsTypeRef?: string;
|
|
137
137
|
defaultProps?: MitosisState;
|
|
138
138
|
style?: string;
|
|
139
|
+
/**
|
|
140
|
+
* This data is filled inside cli to provide more data for plugins
|
|
141
|
+
*/
|
|
142
|
+
pluginData?: {
|
|
143
|
+
target?: Target;
|
|
144
|
+
path?: string;
|
|
145
|
+
outputDir?: string;
|
|
146
|
+
outputFilePath?: string;
|
|
147
|
+
};
|
|
139
148
|
/**
|
|
140
149
|
* Used to store context of a component for a specific framework
|
|
141
150
|
* that we need access only during compilation (for internal use only) and gets removed after compilation.
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import { OutputFiles, TargetContext } from '../types/config';
|
|
1
2
|
import { MitosisComponent } from './mitosis-component';
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export type MitosisBuildPlugin = (targetContext: TargetContext, files?: {
|
|
4
|
+
componentFiles: OutputFiles[];
|
|
5
|
+
nonComponentFiles: OutputFiles[];
|
|
6
|
+
}) => void | Promise<void>;
|
|
7
|
+
export type MitosisJsonPlugin = (json: MitosisComponent) => MitosisComponent | void;
|
|
8
|
+
export type MitosisCodePlugin = (code: string, json: MitosisComponent) => string;
|
|
9
|
+
export type MitosisHook<T> = {
|
|
10
|
+
pre?: T;
|
|
11
|
+
post?: T;
|
|
12
|
+
};
|
|
13
|
+
export type MitosisPlugin = (options?: any) => {
|
|
14
|
+
name?: string;
|
|
15
|
+
order?: number;
|
|
16
|
+
build?: MitosisHook<MitosisBuildPlugin>;
|
|
17
|
+
json?: MitosisHook<MitosisJsonPlugin>;
|
|
18
|
+
code?: MitosisHook<MitosisCodePlugin>;
|
|
11
19
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MitosisComponent } from './mitosis-component';
|
|
2
|
-
import {
|
|
2
|
+
import { MitosisPlugin } from './plugins';
|
|
3
3
|
export interface TranspilerArgs {
|
|
4
4
|
path?: string;
|
|
5
5
|
component: MitosisComponent;
|
|
@@ -20,7 +20,7 @@ export interface BaseTranspilerOptions {
|
|
|
20
20
|
/**
|
|
21
21
|
* Mitosis Plugins to run during codegen.
|
|
22
22
|
*/
|
|
23
|
-
plugins?:
|
|
23
|
+
plugins?: MitosisPlugin[];
|
|
24
24
|
/**
|
|
25
25
|
* Enable `typescript` output
|
|
26
26
|
*/
|
|
@@ -29,4 +29,14 @@ export interface BaseTranspilerOptions {
|
|
|
29
29
|
* Preserves explicit filename extensions in import statements.
|
|
30
30
|
*/
|
|
31
31
|
explicitImportFileExtension?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Can be used for cli builds. Preserves explicit filename extensions when regex matches, e.g.:
|
|
34
|
+
* {
|
|
35
|
+
* explicitBuildFileExtension: {
|
|
36
|
+
* ".ts":/*.figma.lite.tsx/g,
|
|
37
|
+
* ".md":/*.docs.lite.tsx/g
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
explicitBuildFileExtensions?: Record<string, RegExp>;
|
|
32
42
|
}
|