-
Notifications
You must be signed in to change notification settings - Fork 3
Add slot-based variable support with VariableItem component #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add slot-based variable support with VariableItem component #4
Conversation
Co-authored-by: iwangbowen <26178681+iwangbowen@users.noreply.github.com>
Co-authored-by: iwangbowen <26178681+iwangbowen@users.noreply.github.com>
Co-authored-by: iwangbowen <26178681+iwangbowen@users.noreply.github.com>
iwangbowen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive slot-based variable support to the Vue Expression Editor, enabling users to fully customize the variables section UI while maintaining complete backward compatibility with the existing props-based approach. The implementation introduces a dual-support system where users can choose between traditional props or modern slot-based variable management.
Key Changes
- Added
VariableItemcomponent for slot-based variable registration with automatic lifecycle management - Implemented
#variablesslot with rich props API for custom variable layouts - Created dual variable system merging slot and prop variables with proper prioritization
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/index.ts |
Added VariableItem export and type declarations for the new component |
src/locales/zh.ts |
Added Chinese translation for search variables placeholder |
src/locales/en.ts |
Added English translation for search variables placeholder |
src/components/VariableItem.vue |
New component implementing slot-based variable registration with provide/inject pattern |
src/components/ExpressionEditor.vue |
Enhanced with slot support, variable merging logic, and provide/inject integration |
src/dev/App.vue |
Updated demo with toggle between props and slots usage modes |
README.md |
Added comprehensive Chinese documentation for slot usage and VariableItem component |
README.en.md |
Added comprehensive English documentation for slot usage and VariableItem component |
| <div class="variables-search"> | ||
| <el-input | ||
| v-model="slotSearchText" | ||
| placeholder="搜索变量" |
Copilot
AI
Sep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search input placeholder is hardcoded in Chinese. It should use the internationalization system like t('editor.searchVariables') to maintain consistency with the rest of the application and support language switching.
| placeholder="搜索变量" | |
| :placeholder="t('editor.searchVariables')" |
| // 初始化变量值 | ||
| props.variables.forEach(v => { | ||
| allVariables.value.forEach(v => { | ||
| variableValues.value[v.code] = 1; | ||
| }); |
Copilot
AI
Sep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This initialization code runs every time the component evaluates, potentially overwriting user-modified variable values when variables change. This should be moved inside a proper lifecycle hook or wrapped in a condition to only initialize values for new variables that don't already exist in variableValues.value.
Overview
This PR adds comprehensive slot-based variable support to the Vue Expression Editor, allowing users to fully customize the variables section while maintaining complete backward compatibility with the existing props-based approach.
Problem
Previously, users could only provide variables through the
variablesprop, which limited customization of the variables section UI. Users requested the ability to use slots to create custom variable layouts, categories, and advanced interfaces while preserving all existing functionality.Solution
🎯 Dual Variable Support System
The component now supports both approaches seamlessly:
Props-based (Original):
Slot-based (New):
🧩 VariableItem Component
Introduced a new
VariableItemcomponent that:🔌 Rich Slot API
The
#variablesslot provides comprehensive props:variables: All available variablesfilteredVariables: Search-filtered variablessearchText: Current search textonVariableClick: Variable selection handleronSearchChange: Search text update handlerKey Features
Advanced Usage Examples
Tabbed Variable Categories:
Custom Search and Layout:
Smart Variable Prioritization
Technical Implementation
Core Changes
allVariablescomputed property that merges slot and prop variables with proper prioritizationprops.variablesreferences updated to useallVariableswhile maintaining API compatibilityQuality Assurance
Demo Updates
Updated the demo application to showcase both approaches with:
Documentation
Added comprehensive documentation covering:
Breaking Changes
None. This is a purely additive change that maintains 100% backward compatibility.
Benefits
This enhancement significantly expands the component's flexibility while preserving its ease of use for existing implementations.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
mirrors.cloud.tencent.comnpm install(dns block)npm ci(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Created from VS Code via the GitHub Pull Request extension.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.