-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from AliMD/feat/element
New package: element
- Loading branch information
Showing
13 changed files
with
168 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @alwatr/element | ||
|
||
Elegant powerful web component (lit-element) helper mixins written in tiny TypeScript module. | ||
|
||
<!-- @TODO: ## Example usage --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@alwatr/element", | ||
"version": "0.0.0", | ||
"description": "Elegant powerful web component (lit-element) helper mixins written in tiny TypeScript module.", | ||
"keywords": [ | ||
"element", | ||
"lit", | ||
"lit-element", | ||
"web-component", | ||
"mixin", | ||
"typescript", | ||
"esm", | ||
"alwatr" | ||
], | ||
"main": "element.js", | ||
"type": "module", | ||
"types": "element.d.ts", | ||
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)", | ||
"license": "MIT", | ||
"files": [ | ||
"**/*.{d.ts.map,d.ts,js.map,js,html,md}" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/AliMD/alwatr", | ||
"directory": "package/element" | ||
}, | ||
"homepage": "https://github.com/AliMD/alwatr/tree/main/package/element#readme", | ||
"bugs": { | ||
"url": "https://github.com/AliMD/alwatr/issues" | ||
}, | ||
"dependencies": { | ||
"@alwatr/logger": "^0.10.0", | ||
"lit": "^2.2.2", | ||
"tslib": "^2.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {alwatrRegisteredList, createLogger} from '@alwatr/logger'; | ||
import {LitElement} from 'lit'; | ||
|
||
import type {Constructor} from './type'; | ||
import type {Logger} from '@alwatr/logger/type'; | ||
import type {PropertyValues} from 'lit'; | ||
|
||
alwatrRegisteredList.push({ | ||
name: '@alwatr/element', | ||
version: '{{ALWATR_VERSION}}', | ||
}); | ||
|
||
declare class LoggerMixinInterface extends LitElement { | ||
protected _logger: Logger; | ||
} | ||
|
||
export function LoggerMixin<ClassType extends Constructor<LitElement>>( | ||
superClass: ClassType, | ||
): Constructor<LoggerMixinInterface> & ClassType { | ||
class LoggerMixinClass extends superClass { | ||
protected _logger = createLogger(`<${this.tagName.toLowerCase()}>`); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
constructor(...args: any[]) { | ||
super(...args); | ||
this._logger.logMethod('constructor'); | ||
} | ||
|
||
override connectedCallback(): void { | ||
this._logger.logMethod('connectedCallback'); | ||
super.connectedCallback(); | ||
} | ||
|
||
override disconnectedCallback(): void { | ||
this._logger.logMethod('disconnectedCallback'); | ||
super.disconnectedCallback(); | ||
} | ||
|
||
protected override update(_changedProperties: PropertyValues): void { | ||
this._logger.logMethod('update'); | ||
super.update(_changedProperties); | ||
} | ||
|
||
protected override firstUpdated(_changedProperties: PropertyValues): void { | ||
this._logger.logMethod('firstUpdated'); | ||
super.firstUpdated(_changedProperties); | ||
} | ||
|
||
override dispatchEvent(event: Event): boolean { | ||
this._logger.logMethodArgs('dispatchEvent', { | ||
type: event.type, | ||
detail: (event as Event & {detail?: unknown}).detail, | ||
}); | ||
return super.dispatchEvent(event); | ||
} | ||
} | ||
|
||
return LoggerMixinClass as unknown as Constructor<LoggerMixinInterface> & ClassType; | ||
} | ||
|
||
export const AlwatrElement = LoggerMixin(LitElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types | ||
export type Constructor<ClassType = {}> = new (...args: any[]) => ClassType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"tsBuildInfoFile": ".tsbuildinfo", | ||
"rootDir": "src", | ||
"outDir": ".", | ||
}, | ||
// files, include and exclude from the inheriting config are always overwritten. | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [], | ||
"references": [ | ||
{ "path": "../logger" }, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters