-
Notifications
You must be signed in to change notification settings - Fork 2.8k
perf: optimization codemirror component #2451
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,8 @@ | |
| :prop="'input_field_list.' + index + '.value'" | ||
| :rules="{ | ||
| required: item.is_required, | ||
| message: item.source === 'reference' | ||
| message: | ||
| item.source === 'reference' | ||
| ? $t('views.functionLib.functionForm.form.param.selectPlaceholder') | ||
| : $t('views.functionLib.functionForm.form.param.inputPlaceholder'), | ||
| trigger: 'blur' | ||
|
|
@@ -76,17 +77,13 @@ | |
| <h5 class="lighter mb-8"> | ||
| {{ $t('views.functionLib.functionForm.form.param.code') }} | ||
| </h5> | ||
| <div class="function-CodemirrorEditor mb-8" v-if="showEditor"> | ||
| <div class="mb-8" v-if="showEditor"> | ||
| <CodemirrorEditor | ||
| v-model="chat_data.code" | ||
| @wheel="wheel" | ||
| style="height: 130px !important" | ||
| @submitDialog="submitCodemirrorEditor" | ||
| /> | ||
| <div class="function-CodemirrorEditor__footer"> | ||
| <el-button text type="info" @click="openCodemirrorDialog" class="magnify"> | ||
| <AppIcon iconName="app-magnify" style="font-size: 16px"></AppIcon> | ||
| </el-button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <el-form-item | ||
|
|
@@ -113,27 +110,6 @@ | |
| </el-form-item> | ||
| </el-form> | ||
| <FieldFormDialog ref="FieldFormDialogRef" @refresh="refreshFieldList" /> | ||
| <!-- Codemirror 弹出层 --> | ||
| <el-dialog | ||
| v-model="dialogVisible" | ||
| :title="$t('views.functionLib.functionForm.form.param.code')" | ||
| append-to-body | ||
| fullscreen | ||
| > | ||
| <CodemirrorEditor | ||
| v-model="cloneContent" | ||
| style=" | ||
| height: calc(100vh - 160px) !important; | ||
| border: 1px solid #bbbfc4; | ||
| border-radius: 4px; | ||
| " | ||
| /> | ||
| <template #footer> | ||
| <div class="dialog-footer mt-24"> | ||
| <el-button type="primary" @click="submitDialog"> {{ $t('common.confirm') }}</el-button> | ||
| </div> | ||
| </template> | ||
| </el-dialog> | ||
| </NodeContainer> | ||
| </template> | ||
| <script setup lang="ts"> | ||
|
|
@@ -190,17 +166,8 @@ const validate = () => { | |
| }) | ||
| } | ||
|
|
||
| const dialogVisible = ref(false) | ||
| const cloneContent = ref('') | ||
|
|
||
| function openCodemirrorDialog() { | ||
| cloneContent.value = chat_data.value.code | ||
| dialogVisible.value = true | ||
| } | ||
|
|
||
| function submitDialog() { | ||
| set(props.nodeModel.properties.node_data, 'code', cloneContent.value) | ||
| dialogVisible.value = false | ||
| function submitCodemirrorEditor(val: string) { | ||
| set(props.nodeModel.properties.node_data, 'code', val) | ||
| } | ||
|
|
||
| function openAddDialog(data?: any, index?: any) { | ||
|
|
@@ -244,13 +211,4 @@ onMounted(() => { | |
| }, 100) | ||
| }) | ||
| </script> | ||
| <style lang="scss"> | ||
| .function-CodemirrorEditor__footer { | ||
| position: absolute; | ||
| bottom: 10px; | ||
| right: 10px; | ||
| } | ||
| .function-CodemirrorEditor { | ||
| position: relative; | ||
| } | ||
| </style> | ||
| <style lang="scss"></style> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code looks generally correct but has a few improvements that can be made:
Here is updated version of the code with these improvements: <style lang="scss">
.mb-8 {
margin-bottom: 1rem;
}
.field-item {
display: grid;
gap: 0.5rem;
& > .form-label-group {
width: 35%;
}
& > .form-input-group {
width: 65%;
}
}
</style>... (rest of the template remains the same)
</template>
<script setup lang="ts">
...
</script> |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 code you've provided appears clean and organized for use with Vue.js along with
vue-codemirror. It introduces several improvements over the original:State Management Using
ComputedandWatch: Thedataproperty is now managed using both Computed properties (computed) and Watchers to efficiently keep the codemirror value synced between props and internal states.Fullscreen Dialog Integration: A new El-dialog component (El-dialog's "full-screen" mode) has been added to display the same Codemirror instance in an overlay when triggered through a button click.
Data Cloning and Update Handling: In the fullscreen view, the current value of the CodeMirror editor is cloned into another variable (
cloneContent). When editing stops, this content is then passed back via events to update the parent component.Enhanced Styling**: Added CSS to ensure that only the main container takes up the full width while maintaining readability within its boundaries.
While these changes make the implementation more flexible and interactive, remember it might be beneficial to thoroughly test all user flows involving the pop-up dialog to verify smooth working and proper error handling in case anything goes wrong during runtime.