@htmlplus/element 0.8.5 → 1.0.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.
- package/CHANGELOG.md +7 -0
- package/compiler/plugins/customElement.js +58 -37
- package/compiler/utils/index.d.ts +0 -2
- package/compiler/utils/index.js +0 -2
- package/package.json +9 -2
- 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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# 1.0.0 (2023-12-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **package:** fix mistake import ([40180d6](https://github.com/htmlplus/element/commit/40180d64ff1f7fcc4e9edc10c03431dfc8172fa3))
|
|
7
|
+
* **prettier:** fix extra tabs ([22fbad9](https://github.com/htmlplus/element/commit/22fbad962636fd7a8ad53da64dd22078633e4147))
|
|
@@ -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'],
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
@@ -46,11 +46,18 @@
|
|
|
46
46
|
"typescript": "^4.9.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
50
|
+
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
51
|
+
"@semantic-release/git": "^10.0.1",
|
|
52
|
+
"@semantic-release/github": "^9.2.4",
|
|
53
|
+
"@semantic-release/npm": "^11.0.1",
|
|
54
|
+
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
49
55
|
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
50
56
|
"cpy": "^9.0.1",
|
|
51
57
|
"prettier": "^2.8.0",
|
|
52
58
|
"rimraf": "^3.0.2",
|
|
59
|
+
"semantic-release": "^22.0.8",
|
|
53
60
|
"ts-node": "^10.9.1",
|
|
54
61
|
"vite": "^3.2.4"
|
|
55
62
|
}
|
|
56
|
-
}
|
|
63
|
+
}
|
|
@@ -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
|
-
};
|