2025-06-16 13:10:12 +00:00
|
|
|
# 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
|
2025-06-16 13:18:13 +00:00
|
|
|
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
|
2025-06-16 14:35:28 +00:00
|
|
|
import * as demoTools from '@design.estate/dees-wcctools/demotools';
|
2025-06-16 13:18:13 +00:00
|
|
|
|
|
|
|
// In your demo function:
|
|
|
|
demo: () => html`
|
2025-06-16 14:35:28 +00:00
|
|
|
<dees-demowrapper .runAfterRender=${(children: HTMLCollection) => {
|
|
|
|
// Access all slotted elements
|
|
|
|
const firstElement = children[0] as HTMLElement;
|
|
|
|
firstElement.setAttribute('data-demo', 'true');
|
|
|
|
console.log('All slotted elements:', children);
|
|
|
|
|
|
|
|
// Work with multiple elements
|
|
|
|
Array.from(children).forEach(child => {
|
|
|
|
console.log('Element rendered:', child);
|
|
|
|
});
|
2025-06-16 13:18:13 +00:00
|
|
|
}}>
|
|
|
|
<my-custom-element></my-custom-element>
|
2025-06-16 14:35:28 +00:00
|
|
|
<div>Additional content</div>
|
2025-06-16 13:18:13 +00:00
|
|
|
</dees-demowrapper>
|
|
|
|
`
|
|
|
|
```
|
|
|
|
|
|
|
|
**Features:**
|
|
|
|
- Wraps demo elements without affecting layout (uses `display: contents`)
|
2025-06-16 14:35:28 +00:00
|
|
|
- Provides access to ALL slotted elements via HTMLCollection after mounting
|
2025-06-16 13:18:13 +00:00
|
|
|
- Supports async operations in runAfterRender callback
|
2025-06-16 14:35:28 +00:00
|
|
|
- Automatically handles timing to ensure elements are fully rendered
|
|
|
|
- Can handle multiple slotted elements, not just the first one
|