- Introduced async demo functionality in the README, allowing for asynchronous data preparation before rendering components. - Updated WccDashboard, WccProperties, and WccSidebar to support Promise-based template factories. - Implemented resolveTemplateFactory to handle both synchronous and asynchronous template results. - Added tests for resolveTemplateFactory to ensure correct behavior for both sync and async templates. - Updated pnpm workspace configuration.
4.4 KiB
4.4 KiB
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:
- Elements are rendered asynchronously via lit's
render()
in the dashboard - Properties panel tries to find elements immediately without waiting for render completion
- 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
- Modify
wcc-properties.ts
createProperties() method ✅ - Add element search utility function ✅
- 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 ALL slotted elements as HTMLCollection
- 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 (lowercase)
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
Enhanced DemoWrapper (COMPLETED)
Modified runAfterRender callback:
- Now receives the wrapper element itself instead of just children
- Provides full DOM API access (querySelector, querySelectorAll, etc.)
- querySelector works on slotted content (light DOM children)
- Access children via wrapper.children property
- Updated documentation with correct import path (lowercase 'demotools')
- Examples show how to use querySelector for powerful element selection
- Added clarifying comment about querySelector working on slotted content
Fixed Properties Panel Compatibility:
- Made element search generic - works with any container elements
- Searches both light DOM and shadow DOM recursively
- Improved error handling to prevent breaking the update cycle
- Errors in one property don't prevent others from rendering
- Detection continues working even after errors occur
- Maintains compatibility with all element structures
Test Elements Created (COMPLETED)
Created comprehensive test elements:
- test-noprops - Element with no @property decorators
- test-complextypes - Element with arrays, objects, dates, and complex nested data
- test-withwrapper - Element that uses dees-demowrapper in its demo
- test-edgecases - Element with edge cases (null, undefined, NaN, Infinity, circular refs)
- test-nested - Element with deeply nested structure to test recursive search
These test various scenarios:
- Properties panel handling of elements without properties
- Complex data type display and editing
- Element detection inside dees-demowrapper
- Error handling for problematic values
- Deep nesting and shadow DOM traversal
Fixed Demo Value Overwriting (COMPLETED)
Issue:
Properties panel was overwriting values set by demo functions
Solution:
- Changed from attribute binding (
value=
) to property binding (.value=
) - This prevents browser from firing input events during initialization
- Added proper number parsing for number inputs
- Increased initial wait to 200ms for demo wrappers to complete
- Simplified select element handling to use property binding
Async Demo Support (IN PROGRESS)
Tasks
- Allow dashboard-selected items to return Promise-based TemplateResults
- Await async demos/pages before rendering them into the viewport
- Add regression test covering async demo usage
- Document async demo pattern in README and verify with pnpm scripts