Compare commits

...

8 Commits

Author SHA1 Message Date
bed41da573 1.0.92
Some checks failed
Default (tags) / security (push) Failing after 50s
Default (tags) / test (push) Failing after 35s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2025-06-16 14:24:07 +00:00
48f77e7ba2 docs(readme): update documentation with comprehensive overview, quick start guide, and detailed feature descriptions 2025-06-16 14:24:02 +00:00
f7bc113b6c 1.0.91
Some checks failed
Default (tags) / security (push) Failing after 52s
Default (tags) / test (push) Failing after 27s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2025-06-16 13:18:55 +00:00
05934132a7 feat(demo): add DeesDemoWrapper component for enhanced demo element handling 2025-06-16 13:18:13 +00:00
6bdb8c78b7 fix(properties): enhance element detection in properties panel with recursive search and retry mechanism 2025-06-16 13:10:12 +00:00
fca47b87fb Refactor code structure for improved readability and maintainability 2025-06-16 12:30:12 +00:00
595620af4b 1.0.90 2024-05-07 01:38:47 +02:00
8c3a116943 fix(core): update 2024-05-07 01:38:46 +02:00
14 changed files with 5891 additions and 3100 deletions

View File

@ -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

View File

@ -1,14 +1,16 @@
{ {
"name": "@design.estate/dees-wcctools", "name": "@design.estate/dees-wcctools",
"version": "1.0.89", "version": "1.0.92",
"private": false, "private": false,
"description": "A set of web component tools for creating element catalogues, enabling the structured development and documentation of custom elements and pages.", "description": "A set of web component tools for creating element catalogues, enabling the structured development and documentation of custom elements and pages.",
"main": "dist_ts_web/index.js", "exports": {
"typings": "dist_ts_web/index.d.ts", ".": "./dist_ts_web/index.js",
"./demoTools": "./dist_ts_demotools"
},
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "(npm run build)", "test": "(npm run build)",
"build": "(tsbuild element --web --allowimplicitany && tsbundle element)", "build": "(tsbuild tsfolders --allowimplicitany && tsbundle element)",
"watch": "tswatch element", "watch": "tswatch element",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
@ -54,5 +56,6 @@
"design system", "design system",
"element testing", "element testing",
"page development" "page development"
] ],
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
} }

8235
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +1,51 @@
# Project Hints and Findings
## Properties Panel Element Detection Issue (Fixed)
### Problem
The properties panel had timing issues detecting rendered elements because:
1. Elements are rendered asynchronously via lit's `render()` function in the dashboard component
2. The properties panel tried to find elements immediately without waiting for render completion
3. Element search only looked at direct children of the viewport, missing nested elements or those inside shadow DOM
### Solution Implemented
1. Added a 100ms initial delay to allow render completion
2. Implemented recursive element search that:
- Searches through nested children up to 5 levels deep
- Checks shadow roots of elements
- Handles complex DOM structures
3. Added retry mechanism with up to 5 attempts (200ms between retries)
4. Improved error messages to show retry count
### Code Flow
1. Dashboard renders element demo into viewport using `render(anonItem.demo(), viewport)`
2. Properties panel waits, then searches recursively for the element instance
3. If not found, retries with delays to handle async rendering
4. Once found, extracts and displays element properties
## Demo Tools
### DeesDemoWrapper Component
A utility component for wrapping demo elements with post-render functionality.
**Usage:**
```typescript
import { DeesDemoWrapper } from '@design.estate/dees-wcctools/demoTools';
// In your demo function:
demo: () => html`
<dees-demowrapper .runAfterRender=${(element) => {
// Do something with the rendered element
element.setAttribute('data-demo', 'true');
console.log('Element rendered:', element);
}}>
<my-custom-element></my-custom-element>
</dees-demowrapper>
`
```
**Features:**
- Wraps demo elements without affecting layout (uses `display: contents`)
- Provides access to the rendered element instance after mounting
- Supports async operations in runAfterRender callback
- Automatically handles timing to ensure element is fully rendered

397
readme.md
View File

@ -1,101 +1,360 @@
# @design.estate/dees-wcctools # @design.estate/dees-wcctools
wcc tools for creating element catalogues Web Component Development Tools - A powerful framework for building, testing, and documenting web components
## Install ## Overview
To install `@design.estate/dees-wcctools`, you can use npm: `@design.estate/dees-wcctools` provides a comprehensive development environment for web components, featuring:
- 🎨 Interactive component catalogue with live preview
- 🔧 Real-time property editing
- 🌓 Theme switching (light/dark modes)
- 📱 Responsive viewport testing
- 🧪 Advanced demo tools for component testing
- 🚀 Zero-config setup with TypeScript and Lit support
## Installation
```bash ```bash
npm install @design.estate/dees-wcctools --save # Using npm
npm install @design.estate/dees-wcctools --save-dev
# Using pnpm (recommended)
pnpm add -D @design.estate/dees-wcctools
``` ```
## Usage ## Quick Start
The `@design.estate/dees-wcctools` package provides a set of tools for creating element catalogues using Web Components. It leverages LitElement for creating custom elements and provides a structured way to showcase and test these elements in various environments and themes.
### Setting Up ### 1. Create Your Component
First, ensure that your project is set up to use TypeScript and ESM syntax. This guide assumes you have a basic understanding of TypeScript and modern JavaScript development practices.
Start by importing the necessary tools from `@design.estate/dees-wcctools` in your main TypeScript file.
```typescript ```typescript
import { DeesElement, customElement, html, css, property } from '@design.estate/dees-element';
@customElement('my-button')
export class MyButton extends DeesElement {
// Define a demo for the catalogue
public static demo = () => html`
<my-button .label=${'Click me!'} .variant=${'primary'}></my-button>
`;
@property({ type: String })
public label: string = 'Button';
@property({ type: String })
public variant: 'primary' | 'secondary' = 'primary';
public static styles = [
css`
:host {
display: inline-block;
}
button {
padding: 8px 16px;
border-radius: 4px;
border: none;
font-size: 14px;
cursor: pointer;
transition: all 0.3s;
}
button.primary {
background: #007bff;
color: white;
}
button.secondary {
background: #6c757d;
color: white;
}
button:hover {
opacity: 0.9;
}
`
];
public render() {
return html`
<button class="${this.variant}">
${this.label}
</button>
`;
}
}
```
### 2. Set Up Your Catalogue
```typescript
// catalogue.ts
import { setupWccTools } from '@design.estate/dees-wcctools'; import { setupWccTools } from '@design.estate/dees-wcctools';
import { html } from 'lit';
// Import your components
import './components/my-button.js';
import './components/my-card.js';
// Define elements for the catalogue
const elements = {
'my-button': MyButton,
'my-card': MyCard,
};
// Optionally define pages
const pages = {
'home': () => html`
<div style="padding: 20px;">
<h1>Welcome to My Component Library</h1>
<p>Browse components using the sidebar.</p>
</div>
`,
'getting-started': () => html`
<div style="padding: 20px;">
<h2>Getting Started</h2>
<p>Installation and usage instructions...</p>
</div>
`,
};
// Initialize the catalogue
setupWccTools(elements, pages);
``` ```
### Defining Custom Elements ### 3. Create an HTML Entry Point
Define your custom elements using LitElement. Here's a simple example of an element:
```html
<!DOCTYPE html>
<html>
<head>
<title>Component Catalogue</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="margin: 0; padding: 0;">
<script type="module" src="./catalogue.js"></script>
</body>
</html>
```
## Features
### 🎯 Live Property Editing
The properties panel automatically detects and allows editing of:
- **String** properties with text inputs
- **Number** properties with number inputs
- **Boolean** properties with checkboxes
- **Enum** properties with select dropdowns
- **Object** and **Array** properties (read-only display)
### 📱 Viewport Testing
Test your components across different screen sizes:
- **Phone** (320px width)
- **Phablet** (600px width)
- **Tablet** (768px width)
- **Desktop** (full width)
### 🌓 Theme Support
Components automatically adapt to light/dark themes using the `goBright` property:
```typescript ```typescript
import { LitElement, html, customElement } from 'lit'; public render() {
return html`
<div class="${this.goBright ? 'light-theme' : 'dark-theme'}">
<!-- Your component content -->
</div>
`;
}
```
@customElement('my-element') Or use CSS custom properties:
class MyElement extends LitElement { ```typescript
render() { import { cssManager } from '@design.estate/dees-element';
return html`<p>Hello, world!</p>`;
public static styles = [
css`
:host {
color: ${cssManager.bdTheme('#000', '#fff')};
background: ${cssManager.bdTheme('#fff', '#000')};
}
`
];
```
### 🧪 Advanced Demo Tools
The demo tools provide enhanced testing capabilities:
```typescript
import * as demoTools from '@design.estate/dees-wcctools/demoTools';
@customElement('my-component')
export class MyComponent extends DeesElement {
public static demo = () => html`
<dees-demowrapper .runAfterRender=${async (element: MyComponent) => {
// Access the rendered component instance
console.log('Component mounted:', element);
// Simulate user interactions
element.value = 'Test value';
await element.updateComplete;
// Trigger methods
element.handleClick();
// Assert component state
if (element.isValid) {
console.log('Component validation passed');
}
}}>
<my-component></my-component>
</dees-demowrapper>
`;
}
```
### 🎭 Container Queries Support
Components can respond to their container size:
```typescript
public static styles = [
css`
@container wccToolsViewport (min-width: 768px) {
:host {
flex-direction: row;
}
}
@container wccToolsViewport (max-width: 767px) {
:host {
flex-direction: column;
}
}
`
];
```
## Component Guidelines
### Required for Catalogue Display
1. Components must expose a static `demo` property returning a Lit template
2. Use `@property()` decorators for properties you want to be editable
3. Export component classes for proper detection
### Best Practices
```typescript
@customElement('best-practice-component')
export class BestPracticeComponent extends DeesElement {
// ✅ Static demo property
public static demo = () => html`
<best-practice-component
.complexProp=${{ key: 'value' }}
simpleAttribute="test"
></best-practice-component>
`;
// ✅ Typed properties with defaults
@property({ type: String })
public title: string = 'Default Title';
// ✅ Complex property without attribute
@property({ attribute: false })
public complexProp: { key: string } = { key: 'default' };
// ✅ Enum with proper typing
@property({ type: String })
public variant: 'small' | 'medium' | 'large' = 'medium';
}
```
## URL Routing
The catalogue uses URL routing for deep linking:
```
/wcctools-route/:type/:name/:viewport/:theme
Example:
/wcctools-route/element/my-button/desktop/dark
/wcctools-route/page/home/tablet/bright
```
## Development Workflow
### Build and Watch
```json
{
"scripts": {
"build": "tsbuild tsfolders --allowimplicitany && tsbundle element",
"watch": "tswatch element",
"serve": "http-server ./dist"
} }
} }
``` ```
### Bootstrapping the WCCTools Dashboard ### Project Structure
To showcase your elements, `@design.estate/dees-wcctools` provides a handy way to bootstrap a dashboard where your elements can be registered and displayed. ```
my-components/
Create a bootstrap function in your main file or a separate module: ├── src/
│ ├── components/
```typescript │ │ ├── my-button.ts
async function bootstrapWCCTools() { │ │ └── my-card.ts
// Define your elements here └── catalogue.ts
const elements = { ├── dist/
'my-element': MyElement, // Assuming MyElement is imported ├── index.html
}; └── package.json
// Optionally, define pages as functions returning Lit HTML Templates
const pages = {
home: () => html`<h1>Welcome to My Element Catalogue</h1>`,
};
// Setup the WCCTools dashboard
setupWccTools(elements, pages);
}
``` ```
Call this function to initialize your catalogue: ## Advanced Features
### Custom Property Handlers
For complex property types, implement custom logic in your demo:
```typescript ```typescript
bootstrapWCCTools(); public static demo = () => html`
<dees-demowrapper .runAfterRender=${(el) => {
// Set up complex property handling
el.addEventListener('property-change', (e) => {
console.log('Property changed:', e.detail);
});
}}>
<my-component></my-component>
</dees-demowrapper>
`;
``` ```
### Configurations and Customizations ### Responsive Testing Helpers
The `setupWccTools` function accepts two arguments: `elements` and `pages`.
- `elements`: An object where keys are element tags (e.g., 'my-element') and values are the corresponding class definitions.
- `pages`: An optional object where keys are page identifiers and values are functions returning Lit HTML templates.
### Testing Elements
Once the dashboard is set up, navigate to your project in a web browser. You'll see a sidebar listing all registered elements and pages. Clicking on an element name will display it in the main view, allowing you to interact with it and see it in action.
### Theme and Environment Testing
The dashboard also provides options for testing your elements in different environments (e.g., desktop, tablet) and themes (light or dark). This helps ensure that your elements are versatile and adaptable to varying conditions.
### Expanding Your Catalogue
To add more elements to your catalogue, simply extend the `elements` object and rerun `bootstrapWCCTools()`. This modular approach makes it easy to maintain and expand your element catalogue.
### Leveraging TypeScript
Using TypeScript allows you to enforce typing and build more reliable web components. Define properties with decorators, and use TypeScript's features to enhance your component development process.
```typescript ```typescript
import { LitElement, property, html, customElement } from 'lit'; import * as domtools from '@design.estate/dees-domtools';
@customElement('typed-element') public static styles = [
class TypedElement extends LitElement { // Media query helpers
@property({type: String}) domtools.breakpoints.cssForPhone(css`
name: string = 'World'; :host { font-size: 14px; }
`),
render() { domtools.breakpoints.cssForTablet(css`
return html`<p>Hello, ${this.name}!</p>`; :host { font-size: 16px; }
} `),
}
domtools.breakpoints.cssForDesktop(css`
:host { font-size: 18px; }
`)
];
``` ```
### Conclusion ## API Reference
`@design.estate/dees-wcctools` provides a powerful, flexible platform for developing, showcasing, and testing web components. By leveraging modern development practices like TypeScript and LitElement, you can build a robust catalogue of reusable web components ready for any project.
### setupWccTools(elements, pages?)
Initialize the WCC Tools dashboard.
- `elements`: Object mapping element names to element classes
- `pages`: Optional object mapping page names to template functions
### DeesDemoWrapper
Component for wrapping demos with post-render logic.
- `runAfterRender`: Function called after the wrapped element renders
- Receives the first child element as parameter
- Supports async operations
## Browser Support
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
- Mobile browsers with Web Components support
## License and Legal Information ## License and Legal Information
@ -114,4 +373,4 @@ 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 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. 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.

53
readme.plan.md Normal file
View File

@ -0,0 +1,53 @@
# Fix Properties Panel Element Detection (COMPLETED)
To fix the element detection issue, reread CLAUDE.md first.
## Problem Analysis
The properties panel has timing issues detecting rendered elements because:
1. Elements are rendered asynchronously via lit's `render()` in the dashboard
2. Properties panel tries to find elements immediately without waiting for render completion
3. Element search only looks at direct children, missing nested/shadow DOM elements
## Implementation Plan
### 1. Add proper synchronization ✅
- Add a delay or await render completion before element detection
- Use MutationObserver or lit's updateComplete promises
### 2. Improve element search algorithm ✅
- Search recursively through all descendants, not just direct children
- Handle shadow DOM boundaries properly
- Support elements wrapped in containers
### 3. Add retry mechanism ✅
- If element not found, retry after a delay
- Add maximum retry attempts to prevent infinite loops
- Clear error state when element is eventually found
## Code Changes Required
1. Modify `wcc-properties.ts` createProperties() method ✅
2. Add element search utility function ✅
3. Improve error handling and user feedback ✅
# Demo Wrapper Implementation (COMPLETED)
## Created DeesDemoWrapper Component
- Location: ts_demotools/demotools.ts
- Allows wrapping demo elements with post-render functionality
- Provides runAfterRender callback that receives the rendered element
- Uses display: contents to not affect layout
- Handles timing automatically with 50ms delay after firstUpdated
- Supports both sync and async callbacks
- Exports available at @design.estate/dees-wcctools/demoTools
# Documentation Update (COMPLETED)
## Updated readme.md with:
- Comprehensive overview with feature highlights
- Quick start guide with code examples
- Detailed feature documentation
- Advanced demo tools usage
- Best practices and guidelines
- API reference
- Browser support information
- Complete examples for all major features

41
ts_demotools/demotools.ts Normal file
View File

@ -0,0 +1,41 @@
import { DeesElement, customElement, html, css, property, type TemplateResult } from '@design.estate/dees-element';
@customElement('dees-demowrapper')
export class DeesDemoWrapper extends DeesElement {
@property({ attribute: false })
public runAfterRender: (element: HTMLElement) => void | Promise<void>;
public static styles = [
css`
:host {
display: contents;
}
`
];
public render(): TemplateResult {
return html`
<slot></slot>
`;
}
public async firstUpdated() {
await this.updateComplete;
// Wait a bit for slotted content to render
await new Promise(resolve => setTimeout(resolve, 50));
// Find the first element child (excluding text nodes)
const slottedElements = this.children;
if (slottedElements.length > 0 && this.runAfterRender) {
const firstElement = slottedElements[0] as HTMLElement;
// Call the runAfterRender function with the element
try {
await this.runAfterRender(firstElement);
} catch (error) {
console.error('Error in runAfterRender:', error);
}
}
}
}

1
ts_demotools/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './demotools.js';

5
ts_demotools/plugins.ts Normal file
View File

@ -0,0 +1,5 @@
import * as deesElement from '@design.estate/dees-element';
export {
deesElement
};

View File

@ -0,0 +1,3 @@
{
"order": 2
}

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@design.estate/dees-wcctools', name: '@design.estate/dees-wcctools',
version: '1.0.89', version: '1.0.90',
description: 'A set of web component tools for creating element catalogues, enabling the structured development and documentation of custom elements and pages.' description: 'A set of web component tools for creating element catalogues, enabling the structured development and documentation of custom elements and pages.'
} }

View File

@ -139,9 +139,9 @@ export class WccDashboard extends DeesElement {
const storeElement = this.selectedItem; const storeElement = this.selectedItem;
const wccFrame: WccFrame = this.shadowRoot.querySelector('wcc-frame'); const wccFrame: WccFrame = this.shadowRoot.querySelector('wcc-frame');
if (changedPropertiesArg.has('selectedItemName') { if (changedPropertiesArg.has('selectedItemName')) {
document.title = this.selectedItemName; document.title = this.selectedItemName;
}) };
if (this.selectedType === 'page' && this.selectedItem) { if (this.selectedType === 'page' && this.selectedItem) {
if (typeof this.selectedItem === 'function') { if (typeof this.selectedItem === 'function') {

View File

@ -226,6 +226,31 @@ export class WccProperties extends DeesElement {
`; `;
} }
private async findElementRecursively(container: Element, elementClass: any, maxDepth: number = 5): Promise<HTMLElement | null> {
if (maxDepth <= 0) return null;
// Check direct children
for (const child of Array.from(container.children)) {
if (child instanceof elementClass) {
return child as HTMLElement;
}
}
// Check shadow roots of children
for (const child of Array.from(container.children)) {
if (child.shadowRoot) {
const found = await this.findElementRecursively(child.shadowRoot as any, elementClass, maxDepth - 1);
if (found) return found;
}
// Also check nested children
const found = await this.findElementRecursively(child, elementClass, maxDepth - 1);
if (found) return found;
}
return null;
}
public async createProperties() { public async createProperties() {
console.log('creating properties for:'); console.log('creating properties for:');
console.log(this.selectedItem); console.log(this.selectedItem);
@ -275,15 +300,30 @@ export class WccProperties extends DeesElement {
} }
console.log(anonItem.elementProperties); console.log(anonItem.elementProperties);
const wccFrame = await this.dashboardRef.wccFrame; const wccFrame = await this.dashboardRef.wccFrame;
let firstFoundInstantiatedElement: HTMLElement;
for (const element of Array.from((await wccFrame.getViewportElement()).children)) { // Wait for render to complete
if (element instanceof (this.selectedItem as any)) { await new Promise(resolve => setTimeout(resolve, 100));
firstFoundInstantiatedElement = element as HTMLElement;
break; // Try to find the element with recursive search
} const viewport = await wccFrame.getViewportElement();
let firstFoundInstantiatedElement: HTMLElement = await this.findElementRecursively(
viewport,
this.selectedItem as any
);
// Retry logic if element not found
let retries = 0;
while (!firstFoundInstantiatedElement && retries < 5) {
await new Promise(resolve => setTimeout(resolve, 200));
firstFoundInstantiatedElement = await this.findElementRecursively(
viewport,
this.selectedItem as any
);
retries++;
} }
if (!firstFoundInstantiatedElement) { if (!firstFoundInstantiatedElement) {
this.warning = `no first instantiated element found for >>${anonItem.name}<<`; this.warning = `no first instantiated element found for >>${anonItem.name}<< after ${retries} retries`;
return; return;
} }
const classProperties: Map<string, any> = anonItem.elementProperties; const classProperties: Map<string, any> = anonItem.elementProperties;

3
ts_web/tspublish.json Normal file
View File

@ -0,0 +1,3 @@
{
"order": 1
}