Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c85ad8b43 | |||
| fe2f80ed7f | |||
| 766858d2f1 | |||
| 3f2ecbc7fa | |||
| 7892be0707 | |||
| adbf910993 | |||
| c726cd5af8 | |||
| 8d60911b34 | |||
| 217ea3e9d4 | |||
| 8263a4fe73 | |||
| 340582e042 | |||
| a8e07f9682 | |||
| aa37652b6d | |||
| 7e26cd39d7 | |||
| 05cc971c0b | |||
| 8d39592d23 | |||
| 0d6f9b7f19 | |||
| 8fc1a4ae5d | |||
| 82d672abc2 | |||
| 387b415de9 | |||
| 74229cb226 | |||
| 2e64489e9b |
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@@ -1,128 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- pnpm install -g pnpm
|
|
||||||
- pnpm install -g @shipzone/npmci
|
|
||||||
- npmci npm prepare
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --prod
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --dev
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run buildDocs
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
73
changelog.md
73
changelog.md
@@ -1,5 +1,78 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-01-27 - 2.1.6 - fix(docs, deps, tests)
|
||||||
|
update README with expanded usage docs and examples; bump devDependencies and dees-domtools; fix test import path
|
||||||
|
|
||||||
|
- Bumped devDependencies: @git.zone/tsbuild -> ^4.1.2, @git.zone/tsbundle -> ^2.8.3, @git.zone/tstest -> ^3.1.8, @types/node -> ^25.0.10
|
||||||
|
- Bumped dependency @design.estate/dees-domtools -> ^2.3.8
|
||||||
|
- README rewritten/expanded: more complete usage examples, theme management (cssManager) docs, directives reference, lifecycle helpers, install and issue reporting guidance
|
||||||
|
- Test fix: updated import to use @git.zone/tstest/tapbundle instead of @push.rocks/tapbundle
|
||||||
|
|
||||||
|
## 2026-01-04 - 2.1.5 - fix(build)
|
||||||
|
bump @design.estate/dees-domtools to ^2.3.7 and remove experimentalDecorators and useDefineForClassFields from tsconfig.json
|
||||||
|
|
||||||
|
- Bumped @design.estate/dees-domtools from ^2.3.6 to ^2.3.7.
|
||||||
|
- Removed "experimentalDecorators" and "useDefineForClassFields" compiler options from tsconfig.json.
|
||||||
|
|
||||||
|
## 2026-01-04 - 2.1.4 - fix(build)
|
||||||
|
update dev and runtime dependencies, export additional lit directives, switch test export to default, convert class properties to accessors, and update npmextra configuration
|
||||||
|
|
||||||
|
- Bump devDependencies: @git.zone/tsbuild -> ^4.0.2, @git.zone/tsbundle -> ^2.6.3, @git.zone/tstest -> ^3.1.4, @types/node -> ^25.0.3
|
||||||
|
- Bump runtime deps: @design.estate/dees-domtools -> ^2.3.6, lit -> ^3.3.2
|
||||||
|
- Change test script to run tstest in verbose mode and export default tap.start() in test entry
|
||||||
|
- Convert DeesElement properties to use 'accessor' syntax and make domtools non-optional in type
|
||||||
|
- Add exports for lit directives keyed and repeat in directives index
|
||||||
|
- Update packageManager to pnpm@10.27.0 and adjust npmextra.json: rename keys, add release registries and accessLevel
|
||||||
|
|
||||||
|
## 2025-11-16 - 2.1.3 - fix(CssManager)
|
||||||
|
Make CssManager a singleton and export the shared instance via getSingleton; update tests and dependencies
|
||||||
|
|
||||||
|
- Convert CssManager to a singleton by adding a private static instance and a public static getSingleton() method.
|
||||||
|
- Use CssManager.getSingleton() for the exported cssManager in ts/index.ts to ensure a single shared instance across the app.
|
||||||
|
- Add a Chromium-focused test (test.chromium.ts) and remove the browser-specific test file.
|
||||||
|
- Bump devDependencies (@git.zone/tsbuild, @git.zone/tsbundle, @git.zone/tstest) and update lit to ^3.3.1.
|
||||||
|
- Add readme.hints.md documenting the CssManager singleton pattern and supported access patterns.
|
||||||
|
|
||||||
|
## 2025-07-06 - 2.1.2 - fix(build)
|
||||||
|
Update build script in package.json to include 'tsfolders' in tsbuild command
|
||||||
|
|
||||||
|
- Changed build script from 'tsbuild --web --allowimplicitany && tsbundle npm' to 'tsbuild tsfolders --web --allowimplicitany && tsbundle npm'
|
||||||
|
|
||||||
|
## 2025-07-06 - 2.1.1 - fix(documentation)
|
||||||
|
Refine project documentation and metadata for clarity
|
||||||
|
|
||||||
|
- Update readme examples to better illustrate custom element usage
|
||||||
|
- Clarify CssManager theming and API usage in documentation
|
||||||
|
- Ensure package.json and commitinfo reflect accurate project details
|
||||||
|
|
||||||
|
## 2025-07-06 - 2.1.0 - feat(DeesElement)
|
||||||
|
Add invocation of the themeChanged hook in connectedCallback
|
||||||
|
|
||||||
|
- Now calls themeChanged (if defined) when the theme changes, enabling custom handlers for theme switches
|
||||||
|
- Improves lifecycle management by allowing extensions to react to bright/dark mode changes
|
||||||
|
|
||||||
|
## 2025-06-20 - 2.0.44 - fix(ci)
|
||||||
|
Remove obsolete GitLab CI configuration
|
||||||
|
|
||||||
|
- Deleted the .gitlab-ci.yml file to remove outdated CI configuration from the repository.
|
||||||
|
|
||||||
|
## 2025-06-20 - 2.0.43 - fix(dependencies)
|
||||||
|
Bump build and runtime dependencies to newer versions for improved tooling and compatibility.
|
||||||
|
|
||||||
|
- Bumped @git.zone/tsbuild from ^2.3.2 to ^2.6.4
|
||||||
|
- Bumped @git.zone/tsbundle from ^2.2.5 to ^2.4.0
|
||||||
|
- Bumped @git.zone/tstest from ^1.0.96 to ^2.3.1
|
||||||
|
- Bumped @push.rocks/tapbundle from ^5.6.3 to ^6.0.3
|
||||||
|
- Bumped @design.estate/dees-domtools from ^2.3.2 to ^2.3.3
|
||||||
|
- Bumped @push.rocks/smartrx from ^3.0.7 to ^3.0.10
|
||||||
|
|
||||||
|
## 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)
|
## 2025-04-18 - 2.0.41 - fix(directives)
|
||||||
Refactor export statements in directives index for consistency
|
Refactor export statements in directives index for consistency
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"@git.zone/cli": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
@@ -21,13 +21,19 @@
|
|||||||
"reactive programming",
|
"reactive programming",
|
||||||
"DOM manipulation"
|
"DOM manipulation"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"@git.zone/tsdoc": {
|
||||||
"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"
|
"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"
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
23
package.json
23
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@design.estate/dees-element",
|
"name": "@design.estate/dees-element",
|
||||||
"version": "2.0.41",
|
"version": "2.1.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A library for creating custom elements extending the lit element class with additional functionalities.",
|
"description": "A library for creating custom elements extending the lit element class with additional functionalities.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@@ -9,22 +9,21 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --verbose)",
|
||||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
"build": "(tsbuild tsfolders --web --allowimplicitany && tsbundle npm)",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.3.2",
|
"@git.zone/tsbuild": "^4.1.2",
|
||||||
"@git.zone/tsbundle": "^2.2.5",
|
"@git.zone/tsbundle": "^2.8.3",
|
||||||
"@git.zone/tstest": "^1.0.96",
|
"@git.zone/tstest": "^3.1.8",
|
||||||
"@push.rocks/tapbundle": "^5.6.3",
|
"@types/node": "^25.0.10"
|
||||||
"@types/node": "^22.14.1"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@design.estate/dees-domtools": "^2.3.2",
|
"@design.estate/dees-domtools": "^2.3.8",
|
||||||
"@push.rocks/isounique": "^1.0.5",
|
"@push.rocks/isounique": "^1.0.5",
|
||||||
"@push.rocks/smartrx": "^3.0.7",
|
"@push.rocks/smartrx": "^3.0.10",
|
||||||
"lit": "^3.3.0"
|
"lit": "^3.3.2"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
@@ -53,5 +52,5 @@
|
|||||||
"reactive programming",
|
"reactive programming",
|
||||||
"DOM manipulation"
|
"DOM manipulation"
|
||||||
],
|
],
|
||||||
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
|
"packageManager": "pnpm@10.27.0"
|
||||||
}
|
}
|
||||||
|
|||||||
7748
pnpm-lock.yaml
generated
7748
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1 +1,15 @@
|
|||||||
|
# Project Hints
|
||||||
|
|
||||||
|
## CssManager Singleton Pattern
|
||||||
|
|
||||||
|
**Location:** `ts/classes.cssmanager.ts`
|
||||||
|
|
||||||
|
The `CssManager` class uses a singleton pattern:
|
||||||
|
- **Static method:** `CssManager.getSingleton()` - Returns the singleton instance
|
||||||
|
- **Exported instance:** `cssManager` (from `ts/index.ts`) - Uses `getSingleton()` internally
|
||||||
|
|
||||||
|
Both access patterns are supported for backward compatibility:
|
||||||
|
- `cssManager.method()` - Legacy pattern (still works)
|
||||||
|
- `CssManager.getSingleton().method()` - Preferred pattern
|
||||||
|
|
||||||
|
The singleton ensures only one instance manages CSS variables and theme changes throughout the application.
|
||||||
|
|||||||
270
readme.md
270
readme.md
@@ -1,167 +1,281 @@
|
|||||||
# @design.estate/dees-element
|
# @design.estate/dees-element
|
||||||
a custom element class extending lit element class
|
|
||||||
|
A powerful custom element base class that extends Lit's `LitElement` with integrated theming, responsive CSS utilities, RxJS-powered directives, and DOM tooling — so you can build web components that look great and stay reactive out of the box.
|
||||||
|
|
||||||
|
## Issue Reporting and Security
|
||||||
|
|
||||||
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
To install `@design.estate/dees-element`, you need to run the following command using npm:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install @design.estate/dees-element
|
npm install @design.estate/dees-element
|
||||||
|
# or
|
||||||
|
pnpm 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.
|
This package ships as ESM and is written in TypeScript. Make sure your project targets ES2022+ with a modern module resolution strategy (e.g. `NodeNext`).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
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.
|
Everything you need is exported from the main entry point:
|
||||||
|
|
||||||
`@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.
|
```typescript
|
||||||
|
import {
|
||||||
|
DeesElement,
|
||||||
|
customElement,
|
||||||
|
property,
|
||||||
|
state,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
cssManager,
|
||||||
|
directives,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
```
|
||||||
|
|
||||||
### Getting Started
|
### 🧱 Creating a Custom Element
|
||||||
|
|
||||||
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:
|
Extend `DeesElement` and apply the `@customElement` decorator:
|
||||||
|
|
||||||
#### Define a Custom Element
|
|
||||||
|
|
||||||
Create a file named `MyElement.ts`:
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { DeesElement, customElement, html, css, cssManager } from '@design.estate/dees-element';
|
import { DeesElement, customElement, html, css, cssManager } from '@design.estate/dees-element';
|
||||||
|
|
||||||
@customElement('my-element')
|
@customElement('my-button')
|
||||||
class MyElement extends DeesElement {
|
class MyButton 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 = [
|
static styles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
css`
|
css`
|
||||||
div {
|
.btn {
|
||||||
color: blue;
|
padding: 8px 16px;
|
||||||
padding: 16px;
|
border-radius: 4px;
|
||||||
border: 1px solid blue;
|
background: ${cssManager.bdTheme('#0060df', '#3a8fff')};
|
||||||
|
color: ${cssManager.bdTheme('#fff', '#fff')};
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`<div>A Styled Custom Element</div>`;
|
return html`<button class="btn"><slot></slot></button>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `css` template tag allows you to define CSS styles scoped to your custom element.
|
That single `bdTheme()` call generates a CSS variable that automatically flips between the bright and dark values when the user's theme changes — no manual toggling needed.
|
||||||
|
|
||||||
#### Leveraging the `cssManager` for Theme Management
|
### 🎨 Theme Management with `cssManager`
|
||||||
|
|
||||||
`@design.estate/dees-element` introduces a powerful `CssManager` class that facilitates dynamic theming and responsive designs:
|
The singleton `cssManager` is the central hub for theming and responsive layout:
|
||||||
|
|
||||||
|
| Method | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `cssManager.defaultStyles` | Base styles for consistent element rendering |
|
||||||
|
| `cssManager.bdTheme(bright, dark)` | Returns a `CSSResult` that auto-switches between bright/dark values |
|
||||||
|
| `cssManager.cssForDesktop(css)` | Media-query wrapper for desktop breakpoints |
|
||||||
|
| `cssManager.cssForNotebook(css)` | Media-query wrapper for notebook breakpoints |
|
||||||
|
| `cssManager.cssForTablet(css)` | Media-query wrapper for tablet breakpoints |
|
||||||
|
| `cssManager.cssForPhablet(css)` | Media-query wrapper for phablet breakpoints |
|
||||||
|
| `cssManager.cssForPhone(css)` | Media-query wrapper for phone breakpoints |
|
||||||
|
| `cssManager.cssGridColumns(cols, gap)` | Generates CSS grid column widths |
|
||||||
|
|
||||||
|
Example — responsive + themed styles:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { cssManager, DeesElement, customElement, html, css } from '@design.estate/dees-element';
|
@customElement('my-card')
|
||||||
|
class MyCard extends DeesElement {
|
||||||
@customElement('themed-element')
|
|
||||||
class ThemedElement extends DeesElement {
|
|
||||||
static styles = [
|
static styles = [
|
||||||
cssManager.defaultStyles,
|
cssManager.defaultStyles,
|
||||||
css`
|
css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
background-color: var(--theme-background-color, #fff);
|
padding: 16px;
|
||||||
|
background: ${cssManager.bdTheme('#ffffff', '#1e1e1e')};
|
||||||
|
color: ${cssManager.bdTheme('#111', '#eee')};
|
||||||
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
cssManager.cssForPhone(css`
|
||||||
|
:host { padding: 8px; }
|
||||||
|
`),
|
||||||
];
|
];
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
cssManager.bdTheme('#fff', '#000'); // Define themes
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`<div>A Themed Custom Element</div>`;
|
return html`<slot></slot>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
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 & State
|
||||||
|
|
||||||
### Reactive Properties and State Management
|
Use the standard Lit decorators, re-exported for convenience:
|
||||||
|
|
||||||
To make your elements interactive and data-driven, `@design.estate/dees-element` offers a seamless approach to managing properties and internal state:
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
@customElement('interactive-element')
|
import { DeesElement, customElement, property, state, html } from '@design.estate/dees-element';
|
||||||
class InteractiveElement extends DeesElement {
|
|
||||||
@property({ type: String }) labelText = 'Click me';
|
|
||||||
|
|
||||||
@state() private count = 0;
|
@customElement('my-counter')
|
||||||
|
class MyCounter extends DeesElement {
|
||||||
|
@property({ type: String })
|
||||||
|
accessor label = 'Count';
|
||||||
|
|
||||||
|
@state()
|
||||||
|
accessor count = 0;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`
|
return html`
|
||||||
<button @click="${this.incrementCount}">${this.labelText}: ${this.count}</button>
|
<button @click=${() => this.count++}>
|
||||||
|
${this.label}: ${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.
|
> **Note:** This library uses the TC39 standard decorators with the `accessor` keyword for decorated class properties.
|
||||||
|
|
||||||
### Advanced Scenarios: Directives and Async Data
|
### 🔄 Theme Change Callbacks
|
||||||
|
|
||||||
`@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:
|
`DeesElement` tracks the current theme via the `goBright` property and exposes an optional `themeChanged` callback:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { resolve } from '@design.estate/dees-element';
|
@customElement('theme-aware')
|
||||||
|
class ThemeAware extends DeesElement {
|
||||||
|
protected themeChanged(goBright: boolean) {
|
||||||
|
console.log(goBright ? 'Switched to bright' : 'Switched to dark');
|
||||||
|
}
|
||||||
|
|
||||||
@customElement('async-element')
|
render() {
|
||||||
class AsyncElement extends DeesElement {
|
return html`<p>Current theme: ${this.goBright ? 'bright' : 'dark'}</p>`;
|
||||||
private fetchData() {
|
}
|
||||||
return new Promise((resolve) => {
|
}
|
||||||
setTimeout(() => resolve('Data Loaded'), 2000);
|
```
|
||||||
|
|
||||||
|
### 🚀 Lifecycle Helpers
|
||||||
|
|
||||||
|
`DeesElement` adds lifecycle utilities on top of LitElement:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
@customElement('my-widget')
|
||||||
|
class MyWidget extends DeesElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
// Runs once after the element is connected to the DOM
|
||||||
|
this.registerStartupFunction(async () => {
|
||||||
|
console.log('Widget connected!');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Runs when the element is disconnected — perfect for cleanup
|
||||||
|
this.registerGarbageFunction(() => {
|
||||||
|
console.log('Widget removed');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`${resolve(this.fetchData())}`;
|
return html`<p>Hello World</p>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This example demonstrates how to render async data efficiently, ensuring your custom elements can handle dynamic content and states gracefully.
|
Additionally, `this.elementDomReady` is a promise that resolves after `firstUpdated`, which is handy when you need to wait for the initial render:
|
||||||
|
|
||||||
### Conclusion
|
```typescript
|
||||||
|
await this.elementDomReady;
|
||||||
|
// The element's shadow DOM is now fully rendered
|
||||||
|
```
|
||||||
|
|
||||||
`@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.
|
### 📡 Directives
|
||||||
|
|
||||||
|
The `directives` namespace includes powerful template helpers, accessible via `directives.*`:
|
||||||
|
|
||||||
|
#### `resolve` — Render a Promise
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { html, directives } from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return html`${directives.resolve(this.fetchData())}`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `resolveExec` — Resolve a lazy async function
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
render() {
|
||||||
|
return html`${directives.resolveExec(() => this.loadContent())}`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `subscribe` — Render an RxJS Observable
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { html, directives } from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return html`<span>${directives.subscribe(this.count$)}</span>`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `subscribeWithTemplate` — Observable + template transform
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
render() {
|
||||||
|
return html`
|
||||||
|
${directives.subscribeWithTemplate(
|
||||||
|
this.items$,
|
||||||
|
(items) => html`<ul>${items.map(i => html`<li>${i}</li>`)}</ul>`
|
||||||
|
)}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Re-exported Lit directives
|
||||||
|
|
||||||
|
The directives namespace also re-exports these commonly used Lit directives:
|
||||||
|
|
||||||
|
- `until` — render a placeholder while a promise resolves
|
||||||
|
- `asyncAppend` — append values from an async iterable
|
||||||
|
- `keyed` — force re-creation of a template when a key changes
|
||||||
|
- `repeat` — efficiently render lists with identity tracking
|
||||||
|
|
||||||
|
### 📦 Full Export Reference
|
||||||
|
|
||||||
|
| Export | Description |
|
||||||
|
|---|---|
|
||||||
|
| `DeesElement` | Base class for custom elements |
|
||||||
|
| `CssManager` | CSS/theme management class |
|
||||||
|
| `cssManager` | Singleton `CssManager` instance |
|
||||||
|
| `customElement` | Class decorator to register elements |
|
||||||
|
| `property` | Reactive property decorator |
|
||||||
|
| `state` | Internal state decorator |
|
||||||
|
| `query`, `queryAll`, `queryAsync` | Shadow DOM query decorators |
|
||||||
|
| `html` | Lit html template tag |
|
||||||
|
| `css` | Lit css template tag |
|
||||||
|
| `unsafeCSS` | Create `CSSResult` from a string |
|
||||||
|
| `unsafeHTML` | Render raw HTML in templates |
|
||||||
|
| `render` | Lit render function |
|
||||||
|
| `static` / `unsafeStatic` | Static html template helpers |
|
||||||
|
| `domtools` | DOM tooling utilities |
|
||||||
|
| `directives` | All directives (resolve, subscribe, etc.) |
|
||||||
|
| `rxjs` (type) | RxJS type re-export |
|
||||||
|
|
||||||
## License and Legal Information
|
## 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.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||||
|
|
||||||
**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.
|
**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
|
### 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.
|
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 or third parties, 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 or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
|
|
||||||
### Company Information
|
### Company Information
|
||||||
|
|
||||||
Task Venture Capital GmbH
|
Task Venture Capital GmbH
|
||||||
Registered at District court Bremen HRB 35230 HB, Germany
|
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.
|
For any legal inquiries or 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.
|
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.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as deesElement from '../ts/index.js';
|
import * as deesElement from '../ts/index.js';
|
||||||
|
|
||||||
tap.test('should create a static element', async () => {
|
tap.test('should create a static element', async () => {
|
||||||
@@ -21,4 +21,4 @@ tap.test('should create a static element', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@design.estate/dees-element',
|
name: '@design.estate/dees-element',
|
||||||
version: '2.0.41',
|
version: '2.1.6',
|
||||||
description: 'A library for creating custom elements extending the lit element class with additional functionalities.'
|
description: 'A library for creating custom elements extending the lit element class with additional functionalities.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,21 @@ export interface IBdVarTriplet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CssManager {
|
export class CssManager {
|
||||||
|
// STATIC
|
||||||
|
private static instance: CssManager | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the singleton instance of CssManager
|
||||||
|
*/
|
||||||
|
public static getSingleton(): CssManager {
|
||||||
|
if (!CssManager.instance) {
|
||||||
|
CssManager.instance = new CssManager();
|
||||||
|
}
|
||||||
|
return CssManager.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
public domtoolsPromise = domtools.DomTools.setupDomTools();
|
public domtoolsPromise = domtools.DomTools.setupDomTools();
|
||||||
public goBright: boolean = false;
|
public goBright: boolean = false;
|
||||||
public bdVarTripletStore: IBdVarTriplet[] = [];
|
public bdVarTripletStore: IBdVarTriplet[] = [];
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import * as plugins from './plugins.js';
|
|||||||
export class DeesElement extends plugins.lit.LitElement {
|
export class DeesElement extends plugins.lit.LitElement {
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
@plugins.lit.property({ type: Boolean })
|
@plugins.lit.property({ type: Boolean })
|
||||||
public goBright: boolean = false;
|
public accessor goBright: boolean = false;
|
||||||
|
|
||||||
// domtools
|
// domtools
|
||||||
public domtoolsPromise: Promise<plugins.domtools.DomTools>;
|
public domtoolsPromise: Promise<plugins.domtools.DomTools>;
|
||||||
|
|
||||||
@plugins.lit.property()
|
@plugins.lit.property()
|
||||||
domtools?: plugins.domtools.DomTools;
|
public accessor domtools: plugins.domtools.DomTools;
|
||||||
|
|
||||||
public rxSubscriptions: plugins.smartrx.rxjs.Subscription[] = [];
|
public rxSubscriptions: plugins.smartrx.rxjs.Subscription[] = [];
|
||||||
private themeSubscription: plugins.smartrx.rxjs.Subscription;
|
private themeSubscription: plugins.smartrx.rxjs.Subscription;
|
||||||
@@ -25,11 +25,22 @@ export class DeesElement extends plugins.lit.LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the theme changes between bright and dark.
|
||||||
|
* Override this method to handle theme changes.
|
||||||
|
* @param goBright - true if switching to bright theme, false if switching to dark theme
|
||||||
|
*/
|
||||||
|
protected themeChanged?(goBright: boolean): void;
|
||||||
|
|
||||||
public async connectedCallback() {
|
public async connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
const domtools = await this.domtoolsPromise;
|
const domtools = await this.domtoolsPromise;
|
||||||
this.themeSubscription = domtools.themeManager.themeObservable.subscribe((goBrightArg) => {
|
this.themeSubscription = domtools.themeManager.themeObservable.subscribe((goBrightArg) => {
|
||||||
this.goBright = goBrightArg;
|
this.goBright = goBrightArg;
|
||||||
|
// Call themeChanged if it's defined
|
||||||
|
if (this.themeChanged) {
|
||||||
|
this.themeChanged(goBrightArg);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.rxSubscriptions.push(this.themeSubscription);
|
this.rxSubscriptions.push(this.themeSubscription);
|
||||||
for (const startupFunction of this.startupFunctions) {
|
for (const startupFunction of this.startupFunctions) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { type TemplateResult, noChange } from 'lit';
|
import { type TemplateResult, noChange } from 'lit';
|
||||||
|
import type { DirectiveResult } from 'lit/directive.js';
|
||||||
import { AsyncDirective, directive } from 'lit/async-directive.js';
|
import { AsyncDirective, directive } from 'lit/async-directive.js';
|
||||||
import { rxjs } from '@push.rocks/smartrx';
|
import { rxjs } from '@push.rocks/smartrx';
|
||||||
|
|
||||||
@@ -48,4 +49,13 @@ class SubscribeWithTemplateDirective extends AsyncDirective {
|
|||||||
* Directive that renders templates for each emission of an Observable.
|
* Directive that renders templates for each emission of an Observable.
|
||||||
* Usage: html`${subscribeWithTemplate(myObservable, v => html`<span>${v}</span>`)}`
|
* Usage: html`${subscribeWithTemplate(myObservable, v => html`<span>${v}</span>`)}`
|
||||||
*/
|
*/
|
||||||
export const subscribeWithTemplate = directive(SubscribeWithTemplateDirective);
|
/**
|
||||||
|
* 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;
|
||||||
@@ -7,3 +7,5 @@ export { subscribeWithTemplate } from './classes.subscribewithtemplate.js';
|
|||||||
|
|
||||||
export { until } from 'lit/directives/until.js';
|
export { until } from 'lit/directives/until.js';
|
||||||
export { asyncAppend } from 'lit/directives/async-append.js';
|
export { asyncAppend } from 'lit/directives/async-append.js';
|
||||||
|
export { keyed } from 'lit/directives/keyed.js';
|
||||||
|
export { repeat } from 'lit/directives/repeat.js';
|
||||||
@@ -2,6 +2,9 @@ import { CssManager } from './classes.cssmanager.js';
|
|||||||
|
|
||||||
// lit exports
|
// lit exports
|
||||||
export { html, type TemplateResult, css, unsafeCSS, render, type CSSResult } from 'lit';
|
export { html, type TemplateResult, css, unsafeCSS, render, type CSSResult } from 'lit';
|
||||||
|
|
||||||
|
export { html as static, unsafeStatic } from 'lit/static-html.js';
|
||||||
|
|
||||||
export { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
export { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
||||||
|
|
||||||
export { customElement } from 'lit/decorators/custom-element.js';
|
export { customElement } from 'lit/decorators/custom-element.js';
|
||||||
@@ -23,7 +26,7 @@ export { directives };
|
|||||||
/**
|
/**
|
||||||
* a singleton instance of CssManager
|
* a singleton instance of CssManager
|
||||||
*/
|
*/
|
||||||
export const cssManager = new CssManager();
|
export const cssManager = CssManager.getSingleton();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"experimentalDecorators": true,
|
|
||||||
"useDefineForClassFields": false,
|
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
|
|||||||
Reference in New Issue
Block a user