Commit 7c43690
* feat: Template Browser Phase 3 - Usage Guidance & Context (#96)
Adds contextual guidance fields to help users understand when and how to use each template:
**New Template Fields:**
- when_to_use: Brief description of ideal usage scenarios
- use_cases: Array of 2-4 specific example scenarios
- prerequisites: Knowledge or setup requirements
- related_templates: Template IDs for discovery and cross-linking
- estimated_time: Time to complete the template
**Changes:**
- Updated Template interface in TemplateTypes.ts with new optional guidance fields
- Added comprehensive guidance metadata to all 5 built-in templates in constants.ts
- Enhanced Template Browser UI with collapsible guidance sections
- Added CSS styling for guidance display (labels, lists, related templates, time badges)
- JavaScript toggle function for expanding/collapsing guidance sections
**Implementation Details:**
- Guidance section displays only when at least one guidance field is present
- Collapsible design with smooth toggle animation matching preview sections
- Visual hierarchy with icons for each guidance type (📌 When to Use, 💡 Use Cases, ✅ Prerequisites, 🔗 Related Templates)
- Time estimate badge displayed in toggle button header (⏱️)
- Related templates shown as clickable tags for future navigation
- Custom templates from JSON files can also include these guidance fields
Fixes #96
* fix: Address security and code quality issues in Template Browser
**Critical Security Fix:**
- Fixed XSS vulnerability in onclick handlers by replacing all inline event handlers with event delegation
- Replaced onclick="function('${templateId}')" pattern with data-command and data-* attributes
- Implemented single master event listener using event.target.closest('[data-command]')
- Template IDs and user-controllable data no longer executed as JavaScript code
**Code Quality Improvements:**
- Added validation warning for missing built-in template metadata
- Optimized CSS transition from 'all' to specific properties (background, color, border-color) for better performance
- Removed redundant justify-content CSS property (margin-left: auto already handles spacing)
- Refactored toggleGuidance() to use DOM traversal with nextElementSibling
- Refactored togglePreview() to accept button element and use classList.toggle with boolean
- Simplified logic using classList.toggle(class, boolean) instead of manual add/remove
**Event Delegation Changes:**
- Replaced 18+ onclick handlers with data-command attributes
- Added master click handler on document.body for all buttons
- Added event listener for search input
- Added modal overlay click handler with proper event target checking
- All functions now receive elements/parameters directly instead of reconstructing IDs
**Security Impact:**
Previously, a malicious template file named `');alert(1);('.json` could have executed arbitrary JavaScript. Now all user data is safely stored in data attributes and never executed.
Addresses code review feedback.
---------
Co-authored-by: Claude <[email protected]>
1 parent 4ac6728 commit 7c43690
File tree
3 files changed
+397
-55
lines changed- src
- templates
3 files changed
+397
-55
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
92 | 162 | | |
93 | 163 | | |
94 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| |||
0 commit comments