@uibit/codegen 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
- import { SourceBuilder, mergePropertiesAndAttributes, generateTypeImports, toCamelCase } from '../core/utils.js';
1
+ import { mergePropertiesAndAttributes, generateTypeImports, toCamelCase, sanitizeEventType, isEventAssociatedWithProp } from '../core/utils.js';
2
+ import { parseModule, parseClassMembers, extractStatementsFromArrow, findClassDeclaration } from '../core/swc.js';
3
+ import swc from '@swc/core';
2
4
  export const angularPlugin = {
3
5
  name: 'angular',
4
6
  generate(component) {
@@ -8,185 +10,214 @@ export const angularPlugin = {
8
10
  };
9
11
  }
10
12
  };
13
+ // ==========================================
14
+ // Standalone Code Templates (Separation of Concerns)
15
+ // ==========================================
16
+ const BASE_COMPONENT_TEMPLATE = `
17
+ // IMPORTS_PLACEHOLDER
18
+
19
+ @Component({
20
+ selector: 'SELECTOR_PLACEHOLDER',
21
+ template: '<ng-content></ng-content>',
22
+ changeDetection: ChangeDetectionStrategy.OnPush,
23
+ standalone: true
24
+ // DECORATOR_METADATA_PLACEHOLDER
25
+ })
26
+ export class CLASS_NAME_PLACEHOLDER {
27
+ constructor(private el: ElementRef<HTMLElementClass>) {}
28
+ }
29
+ `;
30
+ const CVA_METHODS_TEMPLATE = `
31
+ private _onChange: (value: any) => void = () => {};
32
+ private _onTouched: () => void = () => {};
33
+
34
+ writeValue(value: any): void {
35
+ if (value !== undefined) {
36
+ this.value.set(value);
37
+ }
38
+ }
39
+
40
+ registerOnChange(fn: any): void {
41
+ this._onChange = fn;
42
+ }
43
+
44
+ registerOnTouched(fn: any): void {
45
+ this._onTouched = fn;
46
+ }
47
+
48
+ setDisabledState(isDisabled: boolean): void {
49
+ const el = this.el.nativeElement;
50
+ if ('disabled' in el) {
51
+ (el as any).disabled = isDisabled;
52
+ }
53
+ if (isDisabled) {
54
+ el.setAttribute('disabled', '');
55
+ } else {
56
+ el.removeAttribute('disabled');
57
+ }
58
+ }
59
+
60
+ handleInput(event: any) {
61
+ const val = event.target.value;
62
+ this.value.set(val);
63
+ this._onChange(val);
64
+ }
65
+
66
+ handleBlur() {
67
+ this._onTouched();
68
+ }
69
+ `;
11
70
  class AngularComponentGenerator {
12
71
  constructor(component) {
13
72
  this.component = component;
14
73
  this.propMap = mergePropertiesAndAttributes(component.properties, component.attributes);
15
74
  this.isFormAssociated = component.formAssociated || false;
16
75
  }
17
- build() {
18
- return new SourceBuilder()
19
- .append(this.generateImports())
20
- .append(this.generateClass())
21
- .toString();
76
+ isModelProp(name) {
77
+ if (name === 'value')
78
+ return true;
79
+ return this.component.events.some(e => isEventAssociatedWithProp(this.component, e.name, name));
22
80
  }
23
- generateImports() {
24
- const angularImports = [
25
- 'Component',
26
- 'ChangeDetectionStrategy',
27
- 'ElementRef'
28
- ];
29
- if (this.propMap.size > 0) {
30
- angularImports.push('input', 'effect');
81
+ generatePropertySignal(name, type) {
82
+ const originalProp = this.component.properties.find(p => p.name === name);
83
+ const defaultVal = originalProp?.default !== undefined ? originalProp.default : 'undefined';
84
+ if (this.isModelProp(name)) {
85
+ return `readonly ${name} = model<${type}>(${defaultVal});`;
31
86
  }
32
- if (this.component.events.length > 0) {
33
- angularImports.push('output');
87
+ if (type.includes('boolean')) {
88
+ return `readonly ${name} = input<${type}, any>(${defaultVal}, { transform: booleanAttribute });`;
89
+ }
90
+ if (type.includes('number')) {
91
+ return `readonly ${name} = input<${type}, any>(${defaultVal}, { transform: numberAttribute });`;
34
92
  }
93
+ return `readonly ${name} = input<${type}>(${defaultVal});`;
94
+ }
95
+ generateOutputProperty(e) {
96
+ const camel = toCamelCase(e.name);
97
+ const eventType = `CustomEvent<${sanitizeEventType(e.type?.text)}>`;
98
+ return `readonly ${camel} = output<${eventType}>();`;
99
+ }
100
+ build() {
101
+ const name = this.component.name;
102
+ const className = `Ngx${name}`;
103
+ const importPath = this.component.importPath || '../../index.js';
104
+ const typeImports = generateTypeImports(this.component.referencedTypes, importPath);
105
+ const isFormAssociated = this.isFormAssociated;
106
+ // Collect imports dynamically
107
+ const angularImports = ['Component', 'ChangeDetectionStrategy', 'ElementRef'];
108
+ const hasModels = Array.from(this.propMap.keys()).some(k => this.isModelProp(k));
109
+ const hasInputs = Array.from(this.propMap.keys()).some(k => !this.isModelProp(k));
110
+ if (hasModels)
111
+ angularImports.push('model');
112
+ if (hasInputs)
113
+ angularImports.push('input');
114
+ if (this.propMap.size > 0)
115
+ angularImports.push('effect');
116
+ if (this.component.events.length > 0)
117
+ angularImports.push('output');
35
118
  const hasBoolean = Array.from(this.propMap.values()).some(t => t.includes('boolean'));
36
119
  const hasNumber = Array.from(this.propMap.values()).some(t => t.includes('number'));
37
- if (hasBoolean) {
120
+ if (hasBoolean)
38
121
  angularImports.push('booleanAttribute');
39
- }
40
- if (hasNumber) {
122
+ if (hasNumber)
41
123
  angularImports.push('numberAttribute');
42
- }
43
- if (this.isFormAssociated) {
124
+ if (isFormAssociated)
44
125
  angularImports.push('forwardRef');
126
+ // Build decorator metadata additions (providers and host)
127
+ let decoratorAdditions = '';
128
+ if (isFormAssociated) {
129
+ decoratorAdditions += `,
130
+ providers: [
131
+ {
132
+ provide: NG_VALUE_ACCESSOR,
133
+ useExisting: forwardRef(() => ${className}),
134
+ multi: true
135
+ }
136
+ ]`;
45
137
  }
46
- const importPath = this.component.importPath || '../../index.js';
47
- return [
48
- `import { ${angularImports.join(', ')} } from '@angular/core';`,
49
- this.isFormAssociated ? `import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';` : '',
50
- `import '${importPath}';`,
51
- `import type { ${this.component.name} as HTMLElementClass } from '${importPath}';`,
52
- generateTypeImports(this.component.referencedTypes, importPath)
53
- ].filter(Boolean).join('\n');
54
- }
55
- generateClass() {
56
- const name = this.component.name;
57
- const providers = this.generateProviders();
58
- const implementsClause = this.isFormAssociated ? ' implements ControlValueAccessor' : '';
59
- // Build host bindings safely without duplicate keys
138
+ // Build host event bindings
60
139
  const hostBindings = {};
61
140
  for (const e of this.component.events) {
62
141
  const camel = toCamelCase(e.name);
63
- hostBindings[`(${e.name})`] = [`${camel}.emit($event)`];
64
- }
65
- if (this.isFormAssociated) {
66
- hostBindings['(blur)'] = ['handleBlur()'];
67
- if (!hostBindings['(change)'])
68
- hostBindings['(change)'] = [];
69
- hostBindings['(change)'].push('handleInput()');
70
- if (!hostBindings['(input)'])
71
- hostBindings['(input)'] = [];
72
- hostBindings['(input)'].push('handleInput()');
73
- for (const e of this.component.events) {
74
- const key = `(${e.name})`;
75
- const bindings = hostBindings[key] ?? [];
76
- hostBindings[key] = bindings;
77
- bindings.push('handleInput()');
142
+ const actions = [`${camel}.emit($event)`];
143
+ // Find if this event is associated with any class property
144
+ const matchedPropName = Array.from(this.propMap.keys()).find(propName => {
145
+ return isEventAssociatedWithProp(this.component, e.name, propName);
146
+ });
147
+ if (matchedPropName) {
148
+ const isPrimitiveEvent = e.payloadKeys === undefined || e.payloadKeys.length === 0;
149
+ const targetValue = isPrimitiveEvent
150
+ ? `$event.target.${matchedPropName}`
151
+ : `$event.detail?.${matchedPropName} !== undefined ? $event.detail.${matchedPropName} : $event.target.${matchedPropName}`;
152
+ actions.push(`${matchedPropName}.set(${targetValue})`);
153
+ if (isFormAssociated && matchedPropName === 'value') {
154
+ actions.push('handleInput($event)');
155
+ }
78
156
  }
157
+ hostBindings[`(${e.name})`] = actions;
79
158
  }
159
+ // No hardcoded bindings for form association; all bindings are manifest-driven.
80
160
  const hostLines = Object.entries(hostBindings).map(([eventKey, actions]) => {
81
161
  return `'${eventKey}': '${actions.join('; ')}'`;
82
162
  });
83
- const hostAttr = hostLines.length > 0 ? `,\n host: {\n ${hostLines.join(',\n ')}\n }` : '';
84
- const inputsCode = this.generateInputs();
85
- const outputsCode = this.generateOutputs();
86
- const effectCode = this.generateEffect();
87
- const formCode = this.generateFormMethods();
88
- const constructorBody = [effectCode].filter(Boolean).join('\n');
89
- return `@Component({
90
- selector: '${this.component.tagName}',
91
- template: '<ng-content></ng-content>',
92
- changeDetection: ChangeDetectionStrategy.OnPush,
93
- standalone: true${providers}${hostAttr}
94
- })
95
- export class Ngx${name}${implementsClause} {
96
- constructor(private el: ElementRef<HTMLElementClass>) {
97
- ${constructorBody}
98
- }
99
-
100
- ${[inputsCode, outputsCode, formCode].filter(Boolean).join('\n\n')}
101
- }`;
102
- }
103
- generateProviders() {
104
- if (!this.isFormAssociated)
105
- return '';
106
- return `,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => Ngx${this.component.name}),\n multi: true\n }\n ]`;
107
- }
108
- generateInputs() {
109
- return Array.from(this.propMap.entries())
110
- .map(([name, type]) => {
111
- const originalProp = this.component.properties.find(p => p.name === name);
112
- const hasDefault = originalProp && originalProp.default !== undefined;
113
- let defaultVal = 'undefined';
114
- if (hasDefault) {
115
- defaultVal = originalProp.default;
116
- }
117
- else if (type.includes('boolean')) {
118
- defaultVal = 'false';
119
- }
120
- else if (type.includes('number')) {
121
- defaultVal = '0';
122
- }
123
- else if (type.includes('string')) {
124
- defaultVal = '\'\'';
125
- }
126
- const isBoolean = type.includes('boolean');
127
- const isNumber = type.includes('number');
128
- let options = '';
129
- if (isBoolean) {
130
- options = `, { transform: booleanAttribute }`;
131
- }
132
- else if (isNumber) {
133
- options = `, { transform: numberAttribute }`;
134
- }
135
- return ` readonly ${name} = input<${type}, any>(${defaultVal}${options});`;
136
- })
137
- .join('\n');
138
- }
139
- generateOutputs() {
140
- return this.component.events
141
- .map(e => {
142
- const camel = toCamelCase(e.name);
143
- const eventType = e.type?.text ? `CustomEvent<${e.type.text}>` : 'CustomEvent<any>';
144
- return ` readonly ${camel} = output<${eventType}>();`;
145
- })
163
+ if (hostLines.length > 0) {
164
+ decoratorAdditions += `,
165
+ host: {
166
+ ${hostLines.join(',\n')}
167
+ }`;
168
+ }
169
+ // 1. Interpolate and parse the base component wrapper AST
170
+ const implementsClause = isFormAssociated ? ' implements ControlValueAccessor' : '';
171
+ const baseSource = BASE_COMPONENT_TEMPLATE
172
+ .replace('// IMPORTS_PLACEHOLDER', `
173
+ import { ${angularImports.join(', ')} } from '@angular/core';
174
+ ${isFormAssociated ? `import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';` : ''}
175
+ import '${importPath}';
176
+ import type { ${name} as HTMLElementClass } from '${importPath}';
177
+ ${typeImports}
178
+ `)
179
+ .replace('// DECORATOR_METADATA_PLACEHOLDER', decoratorAdditions)
180
+ .replace('SELECTOR_PLACEHOLDER', this.component.tagName)
181
+ .replace('CLASS_NAME_PLACEHOLDER', `${className}${implementsClause}`);
182
+ const moduleAst = parseModule(baseSource);
183
+ const classDecl = findClassDeclaration(moduleAst);
184
+ // 2. Generate and graft reactive properties (inputs/outputs/models)
185
+ const propertiesSource = Array.from(this.propMap.entries())
186
+ .map(([propName, type]) => this.generatePropertySignal(propName, type))
146
187
  .join('\n');
147
- }
148
- generateEffect() {
149
- if (this.propMap.size === 0)
150
- return '';
151
- return Array.from(this.propMap.keys())
152
- .map(name => {
153
- return ` effect(() => {
154
- if (this.el.nativeElement) {
155
- this.el.nativeElement.${name} = this.${name}();
156
- }
157
- });`;
158
- })
188
+ const outputsSource = this.component.events
189
+ .map(e => this.generateOutputProperty(e))
159
190
  .join('\n');
160
- }
161
- generateFormMethods() {
162
- if (!this.isFormAssociated)
163
- return '';
164
- return ` private _onChange: (value: any) => void = () => {};
165
- private _onTouched: () => void = () => {};
166
-
167
- writeValue(value: any): void {
168
- this.el.nativeElement.value = value;
169
- }
170
-
171
- registerOnChange(fn: any): void {
172
- this._onChange = fn;
173
- }
174
-
175
- registerOnTouched(fn: any): void {
176
- this._onTouched = fn;
177
- }
178
-
179
- setDisabledState(isDisabled: boolean): void {
180
- this.el.nativeElement.disabled = isDisabled;
181
- }
182
-
183
- handleInput() {
184
- this._onChange(this.el.nativeElement.value);
185
- }
186
-
187
- handleBlur() {
188
- this._onTouched();
189
- }`;
191
+ classDecl.body.push(...parseClassMembers(propertiesSource));
192
+ classDecl.body.push(...parseClassMembers(outputsSource));
193
+ // 3. Graft ControlValueAccessor methods if form-associated
194
+ if (isFormAssociated) {
195
+ classDecl.body.push(...parseClassMembers(CVA_METHODS_TEMPLATE));
196
+ }
197
+ // 4. Graft effects into Constructor
198
+ const constructorNode = classDecl.body.find((n) => n.type === 'Constructor');
199
+ if (this.propMap.size > 0 && constructorNode) {
200
+ const effectsSource = Array.from(this.propMap.keys())
201
+ .map(propName => {
202
+ return `effect(() => {
203
+ if (this.el.nativeElement) {
204
+ this.el.nativeElement.${propName} = this.${propName}();
205
+ }
206
+ });`;
207
+ })
208
+ .join('\n');
209
+ const statements = extractStatementsFromArrow(effectsSource);
210
+ constructorNode.body.stmts.push(...statements);
211
+ }
212
+ // 5. Print the completed, compiler-validated AST
213
+ try {
214
+ const output = swc.printSync(moduleAst, { minify: false });
215
+ return output.code;
216
+ }
217
+ catch (e) {
218
+ console.error(`Error: Failed to parse and print generated AST for ${name}:`, e);
219
+ throw e;
220
+ }
190
221
  }
191
222
  }
192
223
  //# sourceMappingURL=angular.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"angular.js","sourceRoot":"","sources":["../../src/templates/angular.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEjH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,QAAQ,CAAC,SAA4B;QACnC,MAAM,SAAS,GAAG,IAAI,yBAAyB,CAAC,SAAS,CAAC,CAAC;QAC3D,OAAO;YACL,UAAU,EAAE,SAAS,CAAC,KAAK,EAAE;SAC9B,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,MAAM,yBAAyB;IAI7B,YAAoB,SAA4B;yBAA5B,SAAS;QAC3B,IAAI,CAAC,OAAO,GAAG,4BAA4B,CAAC,SAAS,CAAC,UAAU,EAAE,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I,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,eAAe,EAAE,CAAC;YAC7C,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;iBAClD,GAAG,CAAC,QAAQ,CAAC,EAAE;gBACd,OAAO;;sCAEqB,QAAQ,WAAW,QAAQ;;cAEnD,CAAC;YACP,CAAC,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,MAAM,UAAU,GAAG,0BAA0B,CAAC,aAAa,CAAC,CAAC;YAC7D,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;QACjD,CAAC;QAED,iDAAiD;QACjD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YAC3D,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,sDAAsD,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;YAChF,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { SourceBuilder } from '../core/utils.js';
1
+ import { SourceBuilder, mergePropertiesAndAttributes, generateTypeImports, sanitizeEventType } from '../core/utils.js';
2
2
  export const astroPlugin = {
3
3
  name: 'astro',
4
4
  generate(component) {
@@ -7,17 +7,30 @@ export const astroPlugin = {
7
7
  };
8
8
  }
9
9
  };
10
- function renderAstroImports(name, importPath) {
10
+ function renderAstroImports(name, referencedTypes, importPath) {
11
11
  return [
12
12
  `import type { ${name} as HTMLElementClass } from '${importPath}';`,
13
- `import '${importPath}';`
14
- ].join('\n');
13
+ `import '${importPath}';`,
14
+ generateTypeImports(referencedTypes, importPath)
15
+ ].filter(Boolean).join('\n');
15
16
  }
16
- function renderAstroGlobalDeclaration(tagName) {
17
+ function renderAstroGlobalDeclaration(component) {
18
+ const { tagName, properties, attributes, events = [] } = component;
19
+ const propMap = mergePropertiesAndAttributes(properties, attributes);
20
+ const propTypes = Array.from(propMap.entries()).map(([propName, propType]) => {
21
+ return ` ${propName}?: ${propType};`;
22
+ }).join('\n');
23
+ const eventTypes = events.map(e => {
24
+ const detailType = e.type?.text ? `CustomEvent<${sanitizeEventType(e.type.text)}>` : `Event`;
25
+ return ` "on:${e.name}"?: (event: ${detailType}) => void;`;
26
+ }).join('\n');
17
27
  return `declare global {
18
28
  namespace astroHTML.JSX {
19
29
  interface IntrinsicElements {
20
- '${tagName}': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes;
30
+ '${tagName}': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes & {
31
+ ${propTypes}
32
+ ${eventTypes}
33
+ };
21
34
  }
22
35
  }
23
36
  }`;
@@ -25,8 +38,8 @@ function renderAstroGlobalDeclaration(tagName) {
25
38
  function buildDTS(component) {
26
39
  const importPath = component.importPath || '../../index.js';
27
40
  return new SourceBuilder()
28
- .append(renderAstroImports(component.name, importPath))
29
- .append(renderAstroGlobalDeclaration(component.tagName))
41
+ .append(renderAstroImports(component.name, component.referencedTypes, importPath))
42
+ .append(renderAstroGlobalDeclaration(component))
30
43
  .toString();
31
44
  }
32
45
  //# sourceMappingURL=astro.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro.js","sourceRoot":"","sources":["../../src/templates/astro.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,OAAO;IACb,QAAQ,CAAC,SAA4B;QACnC,OAAO;YACL,YAAY,EAAE,QAAQ,CAAC,SAAS,CAAC;SAClC,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,SAAS,kBAAkB,CAAC,IAAY,EAAE,UAAkB;I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G,SAAS,CAAC;IACnE,MAAM,OAAO,GAAG,4BAA4B,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAErE,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE;QAC3E,OAAO,SAAS,QAAQ,MAAM,QAAQ,GAAG,CAAC;IAC5C,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAChC,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,eAAe,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7F,OAAO,aAAa,CAAC,CAAC,IAAI,eAAe,UAAU,YAAY,CAAC;IAClE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO;;;SAGA,OAAO;EACd,SAAS;EACT,UAAU;;;;EAIV,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,SAA4B;IAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,gBAAgB,CAAC;IAC5D,OAAO,IAAI,aAAa,EAAE;SACvB,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;SACjF,MAAM,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC;SAC/C,QAAQ,EAAE,CAAC;AAChB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { SourceBuilder, mergePropertiesAndAttributes, generateTypeImports } from '../core/utils.js';
1
+ import { SourceBuilder, mergePropertiesAndAttributes, generateTypeImports, toReactEventName, sanitizeEventType } from '../core/utils.js';
2
2
  export const preactPlugin = {
3
3
  name: 'preact',
4
4
  generate(component) {
@@ -8,7 +8,7 @@ export const preactPlugin = {
8
8
  }
9
9
  };
10
10
  function buildDTS(component) {
11
- const { name, tagName, properties, attributes, referencedTypes, importPath = '../../index.js' } = component;
11
+ const { name, tagName, properties, attributes, events = [], referencedTypes, importPath = '../../index.js' } = component;
12
12
  const builder = new SourceBuilder();
13
13
  builder.append(`import type { JSX } from 'preact';
14
14
  import type { ${name} as HTMLElementClass } from '${importPath}';
@@ -18,11 +18,17 @@ ${generateTypeImports(referencedTypes, importPath)}`);
18
18
  const propTypes = Array.from(propMap.entries()).map(([propName, propType]) => {
19
19
  return ` ${propName}?: ${propType};`;
20
20
  }).join('\n');
21
+ const eventTypes = events.map(e => {
22
+ const detailType = e.type?.text ? `CustomEvent<${sanitizeEventType(e.type.text)}>` : `Event`;
23
+ const reactName = toReactEventName(e.name);
24
+ return ` ${reactName}?: (event: ${detailType}) => void;\n "on:${e.name}"?: (event: ${detailType}) => void;`;
25
+ }).join('\n');
21
26
  builder.append(`declare module 'preact' {
22
27
  namespace JSX {
23
28
  interface IntrinsicElements {
24
29
  '${tagName}': JSX.HTMLAttributes<HTMLElementClass> & {
25
30
  ${propTypes}
31
+ ${eventTypes}
26
32
  };
27
33
  }
28
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"preact.js","sourceRoot":"","sources":["../../src/templates/preact.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEpG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,QAAQ;IACd,QAAQ,CAAC,SAA4B;QACnC,OAAO;YACL,YAAY,EAAE,QAAQ,CAAC,SAAS,CAAC;SAClC,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,SAAS,QAAQ,CAAC,SAA4B;IAC5C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EA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AC;IACzH,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IAEpC,OAAO,CAAC,MAAM,CAAC;gBACD,IAAI,gCAAgC,UAAU;UACpD,UAAU;EAClB,mBAAmB,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;IAEpD,MAAM,OAAO,GAAG,4BAA4B,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACrE,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE;QAC3E,OAAO,SAAS,QAAQ,MAAM,QAAQ,GAAG,CAAC;IAC5C,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAChC,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,eAAe,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7F,MAAM,SAAS,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3C,OAAO,SAAS,SAAS,cAAc,UAAU,yBAAyB,CAAC,CAAC,IAAI,eAAe,UAAU,YAAY,CAAC;IACxH,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO,CAAC,MAAM,CAAC;;;SAGR,OAAO;EACd,SAAS;EACT,UAAU;;;;EAIV,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
@@ -2,7 +2,7 @@ import type { ComponentMetadata } from '../core/types.js';
2
2
  export declare const reactPlugin: {
3
3
  name: string;
4
4
  generate(component: ComponentMetadata): {
5
- 'index.d.ts': string;
5
+ 'index.ts': string;
6
6
  };
7
7
  };
8
8
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/templates/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,eAAO,MAAM,WAAW;IACtB,IAAI;IACJ,QAAQ,YAAY,iBAAiB;QAEjC,YAAY;;CAGjB,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/templates/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAI1D,eAAO,MAAM,WAAW;IACtB,IAAI;IACJ,QAAQ,YAAY,iBAAiB;QAEjC,UAAU;;CAGf,CAAC"}