Compare commits

..

29 Commits

Author SHA1 Message Date
74229cb226 2.0.42 2025-04-18 19:22:57 +00:00
2e64489e9b fix(directives): Add explicit type annotations to subscribeWithTemplate directive export 2025-04-18 19:22:57 +00:00
af2b4048d0 2.0.41 2025-04-18 17:04:34 +00:00
a4992c26be fix(directives): Refactor export statements in directives index for consistency 2025-04-18 17:04:34 +00:00
02f32f5e4f 2.0.40 2025-04-18 17:00:04 +00:00
a9d5fce1b2 fix(dees-element): Refactor project structure and update dependency versions. Internal modules (e.g. dees-element classes and directives) have been reorganized and deprecated paths removed, and package.json now includes an updated packageManager field. 2025-04-18 17:00:04 +00:00
1dd6756213 2.0.39 2024-10-04 15:29:23 +02:00
07dcfb41be fix(core): Update dependency version for @design.estate/dees-domtools 2024-10-04 15:29:22 +02:00
fb2dc2e315 2.0.38 2024-10-02 17:50:38 +02:00
3d67a757ca fix(dependencies): Bump to 2.0.60 2024-10-02 17:50:37 +02:00
1b2206a8f9 2.0.37 2024-10-02 15:47:14 +02:00
5631c9cbb0 fix(dependencies): Update dependencies to latest versions. 2024-10-02 15:47:14 +02:00
e50bc60bfb 2.0.36 2024-07-01 14:26:00 +02:00
ffd95a2e2f fix(core): Ensure documentation completeness and code quality improvements 2024-07-01 14:25:59 +02:00
7263110837 2.0.35 2024-07-01 14:23:15 +02:00
f41f0211a4 fix(dependencies): Update dependency versions and development dependencies 2024-07-01 14:23:14 +02:00
20547a00d5 update documentation 2024-04-20 23:19:23 +02:00
009674d78c 2.0.34 2024-02-05 12:35:33 +01:00
dcca685021 fix(core): update 2024-02-05 12:35:32 +01:00
8eff93febc 2.0.33 2023-10-31 13:47:29 +01:00
11f731aa61 fix(core): update 2023-10-31 13:47:28 +01:00
a8e7d2f335 2.0.32 2023-10-26 12:43:04 +02:00
219390e895 fix(core): update 2023-10-26 12:43:04 +02:00
e321286259 2.0.31 2023-10-23 17:22:10 +02:00
5f141feb50 fix(core): update 2023-10-23 17:22:09 +02:00
7b99c70275 2.0.30 2023-10-23 17:20:09 +02:00
9f3b396633 fix(core): update 2023-10-23 17:20:08 +02:00
8dd48fdc05 2.0.29 2023-09-17 14:39:59 +02:00
2538f59769 fix(core): update 2023-09-17 14:39:59 +02:00
16 changed files with 8916 additions and 4108 deletions

362
changelog.md Normal file
View File

@ -0,0 +1,362 @@
# Changelog
## 2025-04-18 - 2.0.42 - fix(directives)
Add explicit type annotations to subscribeWithTemplate directive export
- Imported DirectiveResult type for better typing
- Defined SubscribeWithTemplateFn signature to ensure proper type inference
- Used type assertion with 'as SubscribeWithTemplateFn' to improve type safety
## 2025-04-18 - 2.0.41 - fix(directives)
Refactor export statements in directives index for consistency
- Changed individual export of 'resolve' and 'subscribe' to wildcard exports in ts/directives/index.ts
- Simplified module export structure without altering functionality
## 2025-04-18 - 2.0.40 - fix(dees-element)
Refactor project structure and update dependency versions. Internal modules (e.g. dees-element classes and directives) have been reorganized and deprecated paths removed, and package.json now includes an updated packageManager field.
- Updated versions for @git.zone/tsbuild, tsbundle, tstest, tapbundle, and lit.
- Changed dependency @design.estate/dees-domtools from ^2.0.61 to ^2.3.2.
- Reorganized internal file structure: moved code from dees-element.classes.* to classes.* and re-exported via index.
- Added packageManager field in package.json for pnpm configuration.
## 2024-10-04 - 2.0.39 - fix(core)
Update dependency version for @design.estate/dees-domtools
- Bumped @design.estate/dees-domtools dependency to version ^2.0.61 to include latest patches and improvements.
## 2024-10-02 - 2.0.38 - fix(dependencies)
Bump `@design.estate/dees-domtools` to 2.0.60
- Updated @design.estate/dees-domtools from 2.0.59 to 2.0.60
## 2024-10-02 - 2.0.37 - fix(dependencies)
Update dependencies to latest versions.
- Updated @git.zone/tsbuild from ^2.1.82 to ^2.1.84
- Updated @types/node from ^20.14.9 to ^22.7.4
- Updated @push.rocks/tapbundle from ^5.0.23 to ^5.3.0
- Updated @design.estate/dees-domtools from ^2.0.57 to ^2.0.59
- Updated lit from ^3.1.4 to ^3.2.0
## 2024-07-01 - 2.0.36 - fix(core)
Ensure documentation completeness and code quality improvements
- Improved the README.md file to provide more detailed usage instructions and examples.
- Refactored code for better readability and performance.
- Updated npmextra.json to ensure accurate project metadata and configurations.
## 2024-07-01 - 2.0.35 - fix(dependencies)
Update dependency versions and development dependencies
- Update @git.zone/tsbuild to version ^2.1.82
- Update @git.zone/tstest to version ^1.0.90
- Update @push.rocks/tapbundle to version ^5.0.23
- Update @types/node to version ^20.14.9
- Update lit to version ^3.1.4
## 2024-04-20 - 2.0.34 - Documentation
Updated project documentation.
- Refreshed the documentation to include recent changes and improvements.
## 2023-10-31 - 2.0.33 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-10-26 - 2.0.32 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-10-23 - 2.0.31 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-10-23 - 2.0.30 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-09-17 - 2.0.29 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-09-17 - 2.0.28 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-09-04 - 2.0.27 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-09-04 - 2.0.26 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-08-07 - 2.0.25 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-08-07 - 2.0.24 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-08-07 - 2.0.23 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-03-29 - 2.0.22 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-03-29 - 2.0.21 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-03-26 - 2.0.20 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2023-03-15 - 2.0.19 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-12-31 - 2.0.18 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-12-31 - 2.0.17 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-05-21 - 2.0.16 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-05-12 - 2.0.15 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-05-02 - 2.0.14 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-05-01 - 2.0.13 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-04-22 - 2.0.12 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-04-21 - 2.0.11 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-04-19 - 2.0.10 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-04-19 - 2.0.9 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-04-18 - 2.0.8 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-04-15 - 2.0.7 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-29 - 2.0.6 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-25 - 2.0.5 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-24 - 2.0.4 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-23 - 2.0.3 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-16 - 2.0.2 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-16 - 2.0.1 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-16 - 2.0.0 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-03-16 - 1.0.36 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-01-07 - 1.0.35 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-01-06 - 1.0.34 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-01-06 - 1.0.33 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2022-01-06 - 1.0.32 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-12-14 - 1.0.31 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-12-13 - 1.0.30 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-12-10 - 1.0.29 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-12-10 - 1.0.28 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-11-27 - 1.0.27 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-27 - 1.0.26 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-16 - 1.0.25 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-16 - 1.0.24 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-13 - 1.0.23 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-08 - 1.0.22 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-08 - 1.0.21 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-09-08 - 1.0.20 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-29 - 1.0.19 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-29 - 1.0.18 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-29 - 1.0.17 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-28 - 1.0.16 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-28 - 1.0.15 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-28 - 1.0.14 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-27 - 1.0.13 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-27 - 1.0.12 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.
## 2021-03-27 - 1.0.11 - Core
Minor core fixes and optimizations.
- Updated core functionalities to improve performance.

View File

@ -2,17 +2,32 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"githost": "code.foss.global",
"gitscope": "designestate",
"gitrepo": "dees-element",
"description": "a custom element class extending lit element class",
"description": "A library for creating custom elements extending the lit element class with additional functionalities.",
"npmPackagename": "@designestate/dees-element",
"license": "MIT",
"projectDomain": "design.estate"
"projectDomain": "design.estate",
"keywords": [
"custom elements",
"lit",
"TypeScript",
"CSS manager",
"themes",
"decorators",
"async directive",
"web components",
"reactive programming",
"DOM manipulation"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -1,8 +1,8 @@
{
"name": "@design.estate/dees-element",
"version": "2.0.28",
"version": "2.0.42",
"private": false,
"description": "a custom element class extending lit element class",
"description": "A library for creating custom elements extending the lit element class with additional functionalities.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -14,17 +14,17 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.70",
"@git.zone/tsbundle": "^2.0.8",
"@git.zone/tstest": "^1.0.81",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.6.2"
"@git.zone/tsbuild": "^2.3.2",
"@git.zone/tsbundle": "^2.2.5",
"@git.zone/tstest": "^1.0.96",
"@push.rocks/tapbundle": "^5.6.3",
"@types/node": "^22.14.1"
},
"dependencies": {
"@design.estate/dees-domtools": "^2.0.41",
"@design.estate/dees-domtools": "^2.3.2",
"@push.rocks/isounique": "^1.0.5",
"@push.rocks/smartrx": "^3.0.6",
"lit": "^2.8.0"
"@push.rocks/smartrx": "^3.0.7",
"lit": "^3.3.0"
},
"browserslist": [
"last 1 chrome versions"
@ -40,5 +40,18 @@
"cli.js",
"npmextra.json",
"readme.md"
]
],
"keywords": [
"custom elements",
"lit",
"TypeScript",
"CSS manager",
"themes",
"decorators",
"async directive",
"web components",
"reactive programming",
"DOM manipulation"
],
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
}

12289
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

182
readme.md
View File

@ -1,37 +1,167 @@
# @designestate/dees-element
# @design.estate/dees-element
a custom element class extending lit element class
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@designestate/dees-element)
* [gitlab.com (source)](https://gitlab.com/designestate/dees-element)
* [github.com (source mirror)](https://github.com/designestate/dees-element)
* [docs (typedoc)](https://designestate.gitlab.io/dees-element/)
## Install
## Status for master
To install `@design.estate/dees-element`, you need to run the following command using npm:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/designestate/dees-element/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/designestate/dees-element/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@designestate/dees-element)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/designestate/dees-element)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@designestate/dees-element)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@designestate/dees-element)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@designestate/dees-element)](https://lossless.cloud)
```bash
npm install @design.estate/dees-element
```
Ensure you have TypeScript and the necessary compilers configured in your development environment since this package uses ESM syntax and TypeScript.
## Usage
Use TypeScript for best in class intellisense
This section provides a comprehensive exploration into the usage of `@design.estate/dees-element`, offering examples to illustrate its capabilities in creating custom elements by extending the lit element class. All examples assume the use of ESM syntax and TypeScript, aligning with modern best practices in web development.
## Contribution
`@design.estate/dees-element` serves as a robust foundation for building custom web components, leveraging the power of the Lit library for reactive updates and efficient rendering management. This guide takes you through the process of creating, styling, and interacting with your custom elements.
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
### Getting Started
For further information read the linked docs at the top of this readme.
Firstly, ensure you have installed the package as described in the installation section. Once installed, you can start creating custom elements. Let's begin with a simple example:
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
#### Define a Custom Element
Create a file named `MyElement.ts`:
```typescript
import { DeesElement, customElement, html, css, cssManager } from '@design.estate/dees-element';
@customElement('my-element')
class MyElement extends DeesElement {
render() {
return html`<div>My Custom Element</div>`;
}
}
```
This code snippet defines a custom element `<my-element>` that renders a simple div. `DeesElement` extends the LitElement class, bringing in all of its reactive rendering capabilities along with additional features that `@design.estate/dees-element` offers.
#### Styling the Element
To style the element, utilize the static `styles` property:
```typescript
@customElement('my-styled-element')
class MyStyledElement extends DeesElement {
static styles = [
css`
div {
color: blue;
padding: 16px;
border: 1px solid blue;
}
`,
];
render() {
return html`<div>A Styled Custom Element</div>`;
}
}
```
The `css` template tag allows you to define CSS styles scoped to your custom element.
#### Leveraging the `cssManager` for Theme Management
`@design.estate/dees-element` introduces a powerful `CssManager` class that facilitates dynamic theming and responsive designs:
```typescript
import { cssManager, DeesElement, customElement, html, css } from '@design.estate/dees-element';
@customElement('themed-element')
class ThemedElement extends DeesElement {
static styles = [
cssManager.defaultStyles,
css`
:host {
display: block;
background-color: var(--theme-background-color, #fff);
}
`,
];
constructor() {
super();
cssManager.bdTheme('#fff', '#000'); // Define themes
}
render() {
return html`<div>A Themed Custom Element</div>`;
}
}
```
The `CssManager` allows easy management of themes, breakpoints, and more, ensuring your custom elements remain consistent and responsive across different devices and themes.
### Reactive Properties and State Management
To make your elements interactive and data-driven, `@design.estate/dees-element` offers a seamless approach to managing properties and internal state:
```typescript
@customElement('interactive-element')
class InteractiveElement extends DeesElement {
@property({ type: String }) labelText = 'Click me';
@state() private count = 0;
render() {
return html`
<button @click="${this.incrementCount}">${this.labelText}: ${this.count}</button>
`;
}
incrementCount() {
this.count++;
}
}
```
Here, `@property` and `@state` decorators are used to reactively update your custom element whenever the internal state or properties change.
### Advanced Scenarios: Directives and Async Data
`@design.estate/dees-element` supports Lit's directives for handling asynchronous data, complex rendering conditions, and more. Here's an example using the `resolve` directive to render content asynchronously:
```typescript
import { resolve } from '@design.estate/dees-element';
@customElement('async-element')
class AsyncElement extends DeesElement {
private fetchData() {
return new Promise((resolve) => {
setTimeout(() => resolve('Data Loaded'), 2000);
});
}
render() {
return html`${resolve(this.fetchData())}`;
}
}
```
This example demonstrates how to render async data efficiently, ensuring your custom elements can handle dynamic content and states gracefully.
### Conclusion
`@design.estate/dees-element` enriches the development experience for building custom elements by extending the capabilities of LitElement. Through thoughtful design choices, such as enhanced theming with `CssManager` and the incorporation of useful plugins and decorators, it facilitates a seamless and powerful approach to developing custom web components.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@design.estate/dees-element',
version: '2.0.28',
description: 'a custom element class extending lit element class'
version: '2.0.42',
description: 'A library for creating custom elements extending the lit element class with additional functionalities.'
}

View File

@ -1,5 +1,5 @@
import { CSSResult, unsafeCSS } from 'lit';
import * as plugins from './dees-element.plugins.js';
import * as plugins from './plugins.js';
import * as domtools from '@design.estate/dees-domtools';
export interface IBdVarTriplet {

View File

@ -1,4 +1,4 @@
import * as plugins from './dees-element.plugins.js';
import * as plugins from './plugins.js';
export class DeesElement extends plugins.lit.LitElement {
// INSTANCE
@ -32,6 +32,9 @@ export class DeesElement extends plugins.lit.LitElement {
this.goBright = goBrightArg;
});
this.rxSubscriptions.push(this.themeSubscription);
for (const startupFunction of this.startupFunctions) {
await startupFunction();
}
this.dispatchEvent(new CustomEvent('deesElementConnected'));
}
@ -40,12 +43,25 @@ export class DeesElement extends plugins.lit.LitElement {
this.elementDomReadyDeferred.resolve();
}
private startupFunctions: (() => void | Promise<any>)[] = [];
public registerStartupFunction(startupFunctionArg: () => void) {
this.startupFunctions.push(startupFunctionArg);
}
private garbageFunctions: (() => void | Promise<any>)[] = [];
public registerGarbageFunction(garbageFunctionArg: () => void) {
this.garbageFunctions.push(garbageFunctionArg);
}
public async disconnectedCallback() {
await this.domtoolsPromise;
super.disconnectedCallback();
for (const subscription of this.rxSubscriptions) {
subscription.unsubscribe();
}
for (const garbageFunction of this.garbageFunctions) {
await garbageFunction();
}
this.dispatchEvent(new CustomEvent('deesElementDisconnected'));
}
}

View File

@ -1,6 +1,9 @@
import { type TemplateResult, noChange } from 'lit';
import { AsyncDirective, directive } from 'lit/async-directive.js';
/**
* Resolves a promise and sets the value of the directive
*/
class ResolveDirective extends AsyncDirective {
promise: Promise<unknown> | undefined;
hasPromiseSettled: boolean = false;

View File

@ -2,6 +2,9 @@ import { noChange } from 'lit';
import { AsyncDirective, directive } from 'lit/async-directive.js';
import { rxjs } from '@push.rocks/smartrx';
/**
* Subscribes to an observable
*/
class SubscribeDirective extends AsyncDirective {
observable: rxjs.Observable<unknown> | undefined;
sub: rxjs.Subscription | null = null;

View File

@ -0,0 +1,61 @@
import { type TemplateResult, noChange } from 'lit';
import type { DirectiveResult } from 'lit/directive.js';
import { AsyncDirective, directive } from 'lit/async-directive.js';
import { rxjs } from '@push.rocks/smartrx';
/**
* Subscribes to an observable and applies a template function to each emission.
* @param observable - the source Observable
* @param templateFn - function mapping each emitted value to a TemplateResult or other renderable content
*/
class SubscribeWithTemplateDirective extends AsyncDirective {
private observable?: rxjs.Observable<unknown>;
private templateFn?: (value: unknown) => TemplateResult | unknown;
private sub: rxjs.Subscription | null = null;
render(
observable: rxjs.Observable<unknown>,
templateFn: (value: unknown) => TemplateResult | unknown
) {
const changed = this.observable !== observable || this.templateFn !== templateFn;
if (changed) {
this.sub?.unsubscribe();
this.observable = observable;
this.templateFn = templateFn;
if (this.isConnected) {
this.startSubscription();
}
}
return noChange;
}
private startSubscription() {
this.sub = this.observable!.subscribe((v: unknown) => {
const out = this.templateFn!(v);
this.setValue(out);
});
}
disconnected() {
this.sub?.unsubscribe();
}
reconnected() {
this.startSubscription();
}
}
/**
* Directive that renders templates for each emission of an Observable.
* Usage: html`${subscribeWithTemplate(myObservable, v => html`<span>${v}</span>`)}`
*/
/**
* Typed directive function signature: returns a Lit DirectiveResult.
*/
type SubscribeWithTemplateFn = <T>(
observable: rxjs.Observable<T>,
templateFn: (value: T) => TemplateResult | unknown
) => DirectiveResult;
export const subscribeWithTemplate = directive(
SubscribeWithTemplateDirective
) as SubscribeWithTemplateFn;

9
ts/directives/index.ts Normal file
View File

@ -0,0 +1,9 @@
// better scoped exports
export * from './classes.resolvedirective.js';
export * from './classes.subscribedirective.js';
export { subscribeWithTemplate } from './classes.subscribewithtemplate.js';
export { until } from 'lit/directives/until.js';
export { asyncAppend } from 'lit/directives/async-append.js';

View File

@ -1,4 +1,4 @@
import { CssManager } from './dees-element.classes.cssmanager.js';
import { CssManager } from './classes.cssmanager.js';
// lit exports
export { html, type TemplateResult, css, unsafeCSS, render, type CSSResult } from 'lit';
@ -8,28 +8,28 @@ export { customElement } from 'lit/decorators/custom-element.js';
export { property, state, query, queryAll, queryAsync } from 'lit/decorators.js';
export { until } from 'lit/directives/until.js';
export { asyncAppend } from 'lit/directives/async-append.js';
// domtools exports
import * as domtools from '@design.estate/dees-domtools';
export { domtools };
// DeesElements exports
export * from './dees-element.classes.dees-element.js';
export * from './dees-element.classes.subscribedirective.js';
export * from './dees-element.classes.resolvedirective.js';
export * from './classes.dees-element.js';
// directives exports
import * as directives from './directives/index.js';
export { directives };
/**
* a singleton instance of CssManager
*/
export const cssManager = new CssManager();
// better scoped exports
import { resolve } from './dees-element.classes.resolvedirective.js';
import { subscribe } from './dees-element.classes.subscribedirective.js';
export const directives = {
resolve,
subscribe,
// type exports
import type { rxjs } from '@push.rocks/smartrx';
export type {
rxjs,
}

View File

@ -3,8 +3,8 @@
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},