@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.
@@ -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, _r;
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 (json.children[0].bindings && ((_b = json.children[0].bindings.key) === null || _b === void 0 ? void 0 : _b.code)) {
299
- const fnIndex = ((_c = root.meta) === null || _c === void 0 ? void 0 : _c._trackByForIndex) || 0;
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 = (_d = json.children[0].bindings.key) === null || _d === void 0 ? void 0 : _d.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 ${(_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code}${indexName ? `; index as ${indexName}` : ''}; trackBy: ${trackByFnName}">`;
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 ${(_f = json.bindings.each) === null || _f === void 0 ? void 0 : _f.code}${indexName ? `; index as ${indexName}` : ''}">`;
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 = (_g = json.bindings.when) === null || _g === void 0 ? void 0 : _g.code;
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)((_h = json.meta) === null || _h === void 0 ? void 0 : _h.else)) {
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 (!((_j = root.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code.includes(inputsPropsStateName))) {
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 (!((_k = root.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.map((hook) => hook.code).join('').includes(inputsPropsStateName))) {
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
- const elSelector = childComponents.find((impName) => impName === json.name)
366
- ? (0, lodash_1.kebabCase)(json.name)
367
- : json.name;
368
- str += `<${elSelector} `;
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 (((_l = json.bindings[key]) === null || _l === void 0 ? void 0 : _l.type) === 'spread' && html_tags_1.VALID_HTML_TAGS.includes(json.name.trim())) {
378
- if (((_m = json.bindings[key]) === null || _m === void 0 ? void 0 : _m.code) === 'this') {
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 ((_o = json.bindings['spreadRef']) === null || _o === void 0 ? void 0 : _o.code) {
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 ((_p = json.bindings[key]) === null || _p === void 0 ? void 0 : _p.code.startsWith('{')) {
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} = ${(_q = json.bindings[key]) === null || _q === void 0 ? void 0 : _q.code};`);
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 = `${(_r = json.bindings[key]) === null || _r === void 0 ? void 0 : _r.code}`;
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 += `</${elSelector}>`;
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, '&quot;');
665
700
  };
@@ -0,0 +1,5 @@
1
+ export declare function parse(selector: string): {
2
+ element: string | null;
3
+ classNames: string[];
4
+ attributes: Record<string, string>;
5
+ };
@@ -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 { Plugin } from '../../modules/plugins';
2
- export declare const FUNCTION_HACK_PLUGIN: 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
- if (type === 'open') {
34
- tag += ` key={${(_a = node.bindings['key']) === null || _a === void 0 ? void 0 : _a.code}}`;
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("../../..").Plugin[];
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 renameComponentFile = ({ path, target, options, }) => path.replace(exports.INPUT_EXTENSION_REGEX, (0, exports.getComponentFileExtensionForTarget)({
23
- type: 'filename',
24
- target,
25
- isTypescript: (0, output_1.checkShouldOutputTypeScript)({ options, target }),
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, OnEventHook, Plugin } from '..';
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
- }) => Plugin;
14
+ }) => MitosisPlugin;
@@ -1,5 +1,5 @@
1
1
  import { MitosisComponent } from '../../../types/mitosis-component';
2
- import { Plugin } from '../../../types/plugins';
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) => Plugin;
12
+ } | undefined) => MitosisPlugin;
@@ -1,6 +1,6 @@
1
1
  import { Node, types } from '@babel/core';
2
2
  import { Target } from '../../types/config';
3
- import { Plugin } from '../../types/plugins';
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
- }) => Plugin;
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
- }) => Plugin;
22
+ }) => MitosisPlugin;
@@ -1,6 +1,6 @@
1
1
  import { Targets } from '../../targets';
2
- import { Plugin } from '../../types/plugins';
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) => Plugin;
6
+ export declare const processTargetBlocks: (target: Targets) => MitosisPlugin;
@@ -1,25 +1,25 @@
1
1
  import { MitosisComponent } from '../types/mitosis-component';
2
- import { Plugin } from '../types/plugins';
3
- export type { Plugin };
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: Plugin[];
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: Plugin[];
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: Plugin[];
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: Plugin[];
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" | "getter" | "method" | "property";
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 Plugin } from '..';
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) => Plugin;
14
+ export declare const compileAwayBuilderComponents: (pluginOptions?: CompileAwayBuilderComponentsOptions) => MitosisPlugin;
15
15
  export {};
@@ -1,7 +1,7 @@
1
- import type { ParseMitosisOptions } from '../parsers/jsx/types';
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 Plugin = (options?: any) => {
3
- json?: {
4
- pre?: (json: MitosisComponent) => MitosisComponent | void;
5
- post?: (json: MitosisComponent) => MitosisComponent | void;
6
- };
7
- code?: {
8
- pre?: (code: string, json: MitosisComponent) => string;
9
- post?: (code: string, json: MitosisComponent) => string;
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 { Plugin } from './plugins';
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?: Plugin[];
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
  }
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.5.22",
25
+ "version": "0.5.24",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {