@htmlplus/element 0.8.4 → 0.8.6
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/client/decorators/event.js +1 -1
- package/compiler/plugins/customElement.js +58 -37
- package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +3 -3
- package/compiler/utils/index.d.ts +0 -2
- package/compiler/utils/index.js +0 -2
- package/package.json +1 -1
- package/compiler/utils/toEventTypeAnnotation.d.ts +0 -2
- package/compiler/utils/toEventTypeAnnotation.js +0 -9
- package/compiler/utils/toPropertySignature.d.ts +0 -7
- package/compiler/utils/toPropertySignature.js +0 -10
|
@@ -12,11 +12,11 @@ export function Event(options = {}) {
|
|
|
12
12
|
let name = options.name || String(propertyKey);
|
|
13
13
|
switch (framework) {
|
|
14
14
|
case 'qwik':
|
|
15
|
+
case 'solid':
|
|
15
16
|
name = pascalCase(name).toLowerCase();
|
|
16
17
|
break;
|
|
17
18
|
case 'preact':
|
|
18
19
|
case 'react':
|
|
19
|
-
case 'solid':
|
|
20
20
|
name = pascalCase(name);
|
|
21
21
|
break;
|
|
22
22
|
default:
|
|
@@ -2,7 +2,7 @@ import template from '@babel/template';
|
|
|
2
2
|
import t from '@babel/types';
|
|
3
3
|
import { camelCase, kebabCase, pascalCase } from 'change-case';
|
|
4
4
|
import * as CONSTANTS from '../../constants/index.js';
|
|
5
|
-
import { addDependency, getType, print,
|
|
5
|
+
import { addDependency, getType, print, visitor } from '../utils/index.js';
|
|
6
6
|
export const CUSTOM_ELEMENT_OPTIONS = {
|
|
7
7
|
prefix: undefined,
|
|
8
8
|
typings: true
|
|
@@ -276,61 +276,82 @@ export const customElement = (options) => {
|
|
|
276
276
|
if (options === null || options === void 0 ? void 0 : options.typings) {
|
|
277
277
|
visitor(ast, {
|
|
278
278
|
Program(path) {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
279
|
+
const attributes = context.classProperties.map((property) => {
|
|
280
|
+
const key = property.key;
|
|
281
|
+
const typeAnnotation = property.typeAnnotation;
|
|
282
|
+
return Object.assign(t.tSPropertySignature(t.stringLiteral(kebabCase(key.name)), typeAnnotation), {
|
|
283
|
+
optional: property.optional,
|
|
284
|
+
leadingComments: t.cloneNode(property, true).leadingComments
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
const events = context.classEvents.map((event) => {
|
|
288
|
+
var _a;
|
|
289
|
+
const key = event.key;
|
|
290
|
+
const typeAnnotation = event.typeAnnotation;
|
|
291
|
+
return Object.assign(t.tSPropertySignature(t.identifier(camelCase('on-' + key.name)), t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
292
|
+
Object.assign({}, t.identifier('event'), {
|
|
293
|
+
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CustomEvent'), (_a = typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation['typeAnnotation']) === null || _a === void 0 ? void 0 : _a.typeParameters))
|
|
294
|
+
})
|
|
295
|
+
], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
|
|
296
|
+
optional: true,
|
|
297
|
+
leadingComments: t.cloneNode(event, true).leadingComments
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
const methods = context.classMethods.map((method) => {
|
|
301
|
+
return Object.assign(t.tsMethodSignature(method.key, undefined, method.params, // TODO
|
|
302
|
+
method.returnType // TODO
|
|
303
|
+
), {
|
|
304
|
+
leadingComments: t.cloneNode(method, true).leadingComments
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
const properties = context.classProperties.map((property) => {
|
|
308
|
+
const key = property.key;
|
|
309
|
+
const typeAnnotation = property.typeAnnotation;
|
|
310
|
+
return Object.assign(t.tSPropertySignature(t.identifier(key.name), typeAnnotation), {
|
|
311
|
+
optional: property.optional,
|
|
312
|
+
leadingComments: t.cloneNode(property, true).leadingComments
|
|
313
|
+
});
|
|
307
314
|
});
|
|
308
315
|
const ast = template.default.ast(`
|
|
309
|
-
export interface ${context.className}
|
|
310
|
-
${
|
|
316
|
+
export interface ${context.className}Attributes {
|
|
317
|
+
${attributes.map(print).join('')}
|
|
311
318
|
}
|
|
312
|
-
|
|
313
|
-
|
|
319
|
+
|
|
320
|
+
export interface ${context.className}Events {
|
|
321
|
+
${events.map(print).join('')}
|
|
314
322
|
}
|
|
323
|
+
|
|
324
|
+
export interface ${context.className}Methods {
|
|
325
|
+
${methods.map(print).join('')}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export interface ${context.className}Properties {
|
|
329
|
+
${properties.map(print).join('')}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export interface ${context.className}JSX extends ${context.className}Events, ${context.className}Properties { }
|
|
333
|
+
|
|
315
334
|
declare global {
|
|
316
|
-
interface ${componentInterfaceName} extends HTMLElement {
|
|
317
|
-
|
|
318
|
-
}
|
|
335
|
+
interface ${componentInterfaceName} extends HTMLElement, ${context.className}Methods, ${context.className}Properties { }
|
|
336
|
+
|
|
319
337
|
var ${componentInterfaceName}: {
|
|
320
338
|
prototype: ${componentInterfaceName};
|
|
321
339
|
new (): ${componentInterfaceName};
|
|
322
340
|
};
|
|
341
|
+
|
|
323
342
|
interface HTMLElementTagNameMap {
|
|
324
343
|
"${tag}": ${componentInterfaceName};
|
|
325
344
|
}
|
|
345
|
+
|
|
326
346
|
namespace JSX {
|
|
327
347
|
interface IntrinsicElements {
|
|
328
|
-
"${tag}": ${context.className}
|
|
348
|
+
"${tag}": ${context.className}Events & ${context.className}Attributes & {
|
|
329
349
|
[key: string]: any;
|
|
330
350
|
};
|
|
331
351
|
}
|
|
332
352
|
}
|
|
333
353
|
}
|
|
354
|
+
|
|
334
355
|
export type ${context.className}Element = globalThis.${componentInterfaceName}
|
|
335
356
|
`, {
|
|
336
357
|
plugins: ['typescript'],
|
|
@@ -163,10 +163,10 @@ const setEvent = (element: Element, name: string, handler: EventHandlerType) =>
|
|
|
163
163
|
|
|
164
164
|
const previous = events[name];
|
|
165
165
|
|
|
166
|
-
previous && element.removeEventListener(
|
|
166
|
+
previous && element.removeEventListener(pascalCase(name), previous);
|
|
167
167
|
|
|
168
168
|
element.addEventListener(
|
|
169
|
-
|
|
169
|
+
pascalCase(name),
|
|
170
170
|
(events[name] = function callback(event: Event) {
|
|
171
171
|
handler && handler.call(this, event);
|
|
172
172
|
})
|
|
@@ -248,7 +248,7 @@ export const proxy = <ElementType, PropType>(
|
|
|
248
248
|
Object.keys(events).forEach((name) => {
|
|
249
249
|
const handler = events[name];
|
|
250
250
|
|
|
251
|
-
(this.element as any).removeEventListener(
|
|
251
|
+
(this.element as any).removeEventListener(pascalCase(name), handler);
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
delete (this.element as any)['$events'];
|
|
@@ -10,6 +10,4 @@ export * from './print.js';
|
|
|
10
10
|
export * from './removeUnusedImport.js';
|
|
11
11
|
export * from './renderTemplate.js';
|
|
12
12
|
export * from './tags.js';
|
|
13
|
-
export * from './toEventTypeAnnotation.js';
|
|
14
|
-
export * from './toPropertySignature.js';
|
|
15
13
|
export * from './visitor.js';
|
package/compiler/utils/index.js
CHANGED
|
@@ -10,6 +10,4 @@ export * from './print.js';
|
|
|
10
10
|
export * from './removeUnusedImport.js';
|
|
11
11
|
export * from './renderTemplate.js';
|
|
12
12
|
export * from './tags.js';
|
|
13
|
-
export * from './toEventTypeAnnotation.js';
|
|
14
|
-
export * from './toPropertySignature.js';
|
|
15
13
|
export * from './visitor.js';
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import t from '@babel/types';
|
|
2
|
-
export const toEventTypeAnnotation = (typeAnnotation) => {
|
|
3
|
-
var _a;
|
|
4
|
-
return t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
5
|
-
Object.assign({}, t.identifier('event'), {
|
|
6
|
-
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CustomEvent'), (_a = typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation['typeAnnotation']) === null || _a === void 0 ? void 0 : _a.typeParameters))
|
|
7
|
-
})
|
|
8
|
-
], t.tsTypeAnnotation(t.tsVoidKeyword())));
|
|
9
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import t from '@babel/types';
|
|
2
|
-
export interface IToPropertySignatureOptions {
|
|
3
|
-
optional?: boolean;
|
|
4
|
-
keyTransformer?: (key: string) => string;
|
|
5
|
-
typeAnnotationTransformer?: (typeAnnotation: t.Noop | t.TSTypeAnnotation | t.TypeAnnotation | null | undefined) => t.TSTypeAnnotation | null | undefined;
|
|
6
|
-
}
|
|
7
|
-
export declare const toPropertySignature: (property: t.ClassProperty, options?: IToPropertySignatureOptions) => t.TSPropertySignature;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import t from '@babel/types';
|
|
2
|
-
export const toPropertySignature = (property, options) => {
|
|
3
|
-
var _a, _b, _c;
|
|
4
|
-
const key = property.key;
|
|
5
|
-
const typeAnnotation = property.typeAnnotation;
|
|
6
|
-
return Object.assign(t.tSPropertySignature(t.stringLiteral(((_a = options === null || options === void 0 ? void 0 : options.keyTransformer) === null || _a === void 0 ? void 0 : _a.call(options, key.name)) || key.name), ((_b = options === null || options === void 0 ? void 0 : options.typeAnnotationTransformer) === null || _b === void 0 ? void 0 : _b.call(options, typeAnnotation)) || typeAnnotation), {
|
|
7
|
-
optional: (_c = options === null || options === void 0 ? void 0 : options.optional) !== null && _c !== void 0 ? _c : property.optional,
|
|
8
|
-
leadingComments: t.cloneNode(property, true).leadingComments
|
|
9
|
-
});
|
|
10
|
-
};
|