Refactor code structure for improved readability and maintainability.…#71
Refactor code structure for improved readability and maintainability.…#71
Conversation
… Modernize the build system and HA features. Implement aditional custom card features to highlight great features.
…t color, attribute limit, and show timestamps settings.
…; enhance editor with accordion sections for better organization
… enhance comments for better guidance on customization
… resolutions to overrides
There was a problem hiding this comment.
Pull request overview
This pull request modernizes the Boilerplate Card from 2023 tooling to 2026 standards, upgrading all major dependencies and introducing significant new features. The project transitions from Lit 2 to Lit 3, TypeScript 4 to 5, Rollup 2 to 4, and migrates build tooling to official Rollup plugins while removing Babel dependencies.
Changes:
- Major dependency upgrades: Lit 3.3.2, TypeScript 5.9.3, Rollup 4.20.0, ESLint 9.39.1, custom-card-helpers 2.0.0
- Complete action-handler-directive rewrite with improved gesture support (tap, hold, double-tap, keyboard, repeat)
- Visual editor refactored with accordion sections and new config fields (card_style, accent_color, layout, display_mode, attribute_limit, show_timestamps)
- Extensive boilerplate-card enhancements: skeleton loading, badge mode, horizontal layout, responsive design, comprehensive styling
- Build system modernization: ES module support, removed Babel, official Rollup plugins, updated devcontainer
Reviewed changes
Copilot reviewed 32 out of 45 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Dependency version updates, ES module type declaration - has critical version errors |
| tsconfig.json | ES2022 target, bundler module resolution, strict mode enabled |
| src/types.ts | Added new config fields for appearance, layout, display options |
| src/editor.ts | Complete rewrite with accordion UI, new selectors for visual config |
| src/boilerplate-card.ts | Extensive expansion: skeleton, badge mode, layouts, action buttons, styling |
| src/action-handler-directive.ts | Complete rewrite with improved gesture handling and event management |
| src/localize/localize.ts | Type-safe localization with proper fallback handling |
| rollup.config.js | Modernized to official @rollup plugins, removed Babel |
| eslint.config.js | New flat config for ESLint 9 |
| .devcontainer/* | Migrated to thomasloven/hass-custom-devcontainer image |
| README.md | Comprehensive rewrite with modern documentation |
| .github/workflows/* | Updated to actions/checkout@v4, setup-node@v4, npm ci |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…mance and remove unused loadCardHelpers method
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 38 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Blocked by thomasloven/hass-custom-devcontainer#231 which add LOVELACE_REMOTE_FILES functionality to Thomas' devcontainer so you can remotely use a hosted card in the devcontainer, allowing for easier debugging and builds of the card being developed |
|
Utilizes new custom-card-helpers release https://github.com/custom-cards/custom-card-helpers/releases/tag/2.0.0 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 34 out of 39 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I saw here piitaya/lovelace-mushroom#1860 that mwc components may longer be available. Need to investigate this further. |
Boilerplate Card - Modernization Summary
Overview
Modernize from 2023 tooling (honestly might be older than that) to current 2026 standards. The project now uses the latest stable versions of all major dependencies.
Major Version Updates
Core Dependencies
Dev Dependencies - Removed
@babel/core(^7.15.0) - No longer needed; TypeScript handles transpilation@babel/plugin-proposal-class-properties- Decorators now standardized@babel/plugin-proposal-decorators- Decorators now standardizedrollup-plugin-babel- Redundant with TypeScript pluginsrollup-plugin-commonjs- Replaced with @rollup/plugin-commonjsrollup-plugin-node-resolve- Replaced with @rollup/plugin-node-resolverollup-plugin-terser- Replaced with @rollup/plugin-terserrollup-plugin-typescript2- Replaced with @rollup/plugin-typescriptDev Dependencies - Added
@rollup/plugin-commonjs(^26.0.0) - Official Rollup CommonJS support@rollup/plugin-node-resolve(^15.2.0) - Official Rollup Node resolver@rollup/plugin-terser(^0.4.4) - Official Rollup minifier@rollup/plugin-typescript(^11.1.0) - Official Rollup TypeScript supporttslib(^2.6.0) - TypeScript runtime library helper@typescript-eslint/*(^8.0.0) - Latest TypeScript ESLint parserBuild Configuration Changes
tsconfig.json
rollup.config.js
rollup-plugin-typescript2to@rollup/plugin-typescriptcreateRequireforrequire.resolve()package.json
"type": "module"to support ES module importstslibas dependency for TypeScript helpers.eslintrc.json (New)
Created modern ESLint configuration with:
Code Quality Improvements
Type Safety
anytypes with proper typing:any→Record<string, unknown>for dynamic objectsany→WindowWithCustomCardsinterface for window objectIActionHandler- renamed from interface-class collisionRipple- proper typing for mwc-ripple elementWindowWithCustomCards- window augmentationModule Improvements
.jsextensions for ES module compatibility'./rollup-plugins/ignore'→'./rollup-plugins/ignore.js'ESLint Compliance
All linting passes successfully:
@typescript-eslint/no-explicit-anyviolationsBreaking Changes & Migration Notes
Lit 3.x Changes
ESLint Configuration
.eslintrcfiles ignored; new.eslintrc.jsonuses flat configTypeScript 5.x Changes
consttype parameters now availableBuild & Runtime
Build Output
yarn buildyarn rollupyarn startrollup --watch)yarn lintsrc/filesBuild Artifacts
Performance Improvements
Compatibility
Files Modified
Configuration Files
package.json- Updated all dependencies, added type moduletsconfig.json- Modern compiler optionsrollup.config.js- Modernized Rollup configurationrollup.config.dev.js- Development build config.eslintrc.json- New ESLint configuration (created)Source Code
src/boilerplate-card.ts- Proper typing for custom cardssrc/editor.ts- Fixed element importssrc/action-handler-directive.ts- Type-safe directive implementationsrc/localize/localize.ts- Improved type safetyUpdated devcontainer
Migrated to custom-cards/custom-card-devcontainer
Action Handler Directive (Complete Rewrite)
The
src/action-handler-directive.tswas fully rewritten to implement a comprehensive,cross-platform interaction system based on the button-card pattern.
Interaction Support Added
Editor Controls Expansion
New Config Fields (
src/types.ts)card_style'default' | 'compact' | 'detailed' | 'minimal''default'accent_color[number, number, number]attribute_limitnumber3show_timestampsbooleantrueNew Editor Sections (
src/editor.ts)Appearance section (after Actions):
ha-selector select— Card Style dropdown with four labeled optionsha-selector color_rgb— Accent Color using HA's native color pickerDisplay section:
ha-selector number— Attribute Limit (box mode, 0–10)ha-switch— Show Timestamps toggleAdded
_selectorChangedhandler for genericha-selectorfields, separate from theexisting
_actionChangedhandler for action selectors.Card Rendering (
src/boilerplate-card.ts)ha-cardreceivesclass="clickable-card style-${card_style}"for CSS variant targeting--card-accent-colorCSS custom property injected inline whenaccent_coloris set_renderAttributes()now accepts alimitparameter, wired toattribute_limitcard_style === 'minimal'show_timestamps !== falseconditionalCSS Variants Added
.style-compact.style-detailed.style-minimalCSS Variants Added
.style-compact.style-detailed.style-minimalEditor Accordion Sections
The editor was restructured from a long flat list of controls into collapsible accordion
sections to improve usability as the number of config fields grew.
Accordion Sections (
src/editor.ts)Four sections, only one open at a time:
Implementation Details
@state() private _openSection = 'entity'— tracks which section is expanded_renderSection(id, title, content)— reusable helper that wraps any content block inan accordion shell
_toggleSection(ev, id)— dedicated handler that callsev.stopPropagation(),ev.stopImmediatePropagation(), andthis.requestUpdate()explicitly; required becauseHA's editor container re-invokes
setConfigon bubbling click events, racing againstLit's microtask update and freezing the view
<button>elements usetype="button"to prevent accidental formsubmission behaviour in HA's editor host
CSS Animate Technique
Expand/collapse uses the
grid-template-rows: 0fr → 1frCSS grid trick (no JavaScriptheight measurement required):