Skip to content
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

feat: Edit code style #667

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 72 additions & 63 deletions packages/common/component/MetaCodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@
<div class="source-code">
<div v-if="editorTipsTitle" class="header-tips-container">
<span class="header-tips-title" :title="editorTipsTitle">{{ editorTipsTitle }}</span>
<div
v-if="editorTipsDemo"
class="header-tips-showdemo"
@click="editorState.showEditorDemo = !editorState.showEditorDemo"
>
<span>{{ editorState.showEditorDemo ? $t('common.collapseExample') : $t('common.expandExample') }}</span>
<icon-chevron-up v-if="editorState.showEditorDemo" class="collapse-icon"></icon-chevron-up>
<icon-chevron-down v-else class="collapse-icon"></icon-chevron-down>
</div>
</div>
<div v-if="editorState.showEditorDemo" class="header-tips-demo">
<div class="header-tips-demo-content lowcode-scrollbar-thin">
<pre><code>{{ editorTipsDemo }}</code></pre>
</div>
<div class="source-code-split-panel-wrapper">
<tiny-split v-model="editorState.splitWidth">
<template #left>
<monaco-editor
ref="editor"
class="source-code-content"
:value="value"
:options="options"
@editorDidMount="editorDidMount"
></monaco-editor>
</template>
<template #right>
<div v-if="editorTipsDemo" class="source-code-split-panel-wrapper-right">
<div class="header-tips-demo-content lowcode-scrollbar-thin">
<span>{{ $t('common.exampleCode') }}</span>
<pre><code>{{ editorTipsDemo }}</code></pre>
</div>
</div>
</template>
</tiny-split>
</div>
<monaco-editor
ref="editor"
class="source-code-content"
:value="value"
:options="options"
@editorDidMount="editorDidMount"
></monaco-editor>
<div v-if="showErrorMsg" class="error-msg">{{ editorState.errorMsg }}</div>
</div>
<template #footer>
Expand All @@ -67,19 +67,17 @@

<script>
import { computed, nextTick, reactive, ref, watchEffect } from 'vue'
import { Button, DialogBox } from '@opentiny/vue'
import { iconChevronDown, iconChevronUp } from '@opentiny/vue-icon'
import { Button, DialogBox, Split } from '@opentiny/vue'
import VueMonaco from './VueMonaco.vue'
import { formatString } from '../js/ast'
import i18n from '../js/i18n'

export default {
components: {
TinySplit: Split,
MonacoEditor: VueMonaco,
TinyButton: Button,
TinyDialogBox: DialogBox,
IconChevronDown: iconChevronDown(),
IconChevronUp: iconChevronUp()
TinyDialogBox: DialogBox
},
props: {
buttonText: {
Expand All @@ -96,7 +94,7 @@ export default {
},
title: {
type: [String, Object],
default: ''
default: '编辑代码'
},
language: {
type: String,
Expand Down Expand Up @@ -131,9 +129,9 @@ export default {
show: false,
created: false,
errorMsg: '',
showEditorDemo: false
showEditorDemo: false,
splitWidth: props.tips?.demo ? 0.7 : 1
})

const value = ref('')
const editor = ref(null)

Expand Down Expand Up @@ -254,22 +252,27 @@ export default {
<style lang="less" scoped>
.editor-wrap {
width: 100%;

.edit-btn {
color: var(--ti-lowcode-meta-codeEditor-color);
border-color: var(--ti-lowcode-meta-codeEditor-border-color);

&:hover {
color: var(--ti-lowcode-meta-codeEditor-hover-color);
border-color: var(--ti-lowcode-meta-codeEditor-border-hover-color);
}
}
}

.btn-box {
display: flex;
justify-content: flex-end;

&:has(.format-btn) {
justify-content: space-between;
}
}

.full-width {
display: flex;
justify-content: space-between;
Expand All @@ -279,76 +282,82 @@ export default {
padding: 4px 8px;
border: 1px solid var(--ti-lowcode-meta-codeEditor-border-color);
border-radius: 6px;

&:hover {
border-color: var(--ti-lowcode-meta-codeEditor-border-hover-color);
}

.text-content {
--ellipsis-line: 1;
}

&.empty-color {
color: var(--ti-lowcode-common-text-desc-color);
}

.edit-icon {
margin-left: 4px;
flex-shrink: 0;
cursor: pointer;
color: var(--ti-lowcode-common-text-main-color);
}
}
:deep(.tiny-dialog-box__header) {
padding-bottom: 15px;
}

:deep(.tiny-dialog-box__title) {
font-size: 14px;
}

:deep(.view-line) {
font-size: 12px;
}

.source-code {
height: 50vh;
display: flex;
flex-direction: column;

.header-tips-container {
display: flex;
height: 17px;
margin-bottom: 10px;
color: var(--ti-lowcode-meta-code-editor-header-tips-container-color);

.header-tips-title {
color: var(--ti-lowcode-base-text-color-3);
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.header-tips-showdemo {
display: flex;
align-items: center;
margin-left: 10px;
white-space: nowrap;
cursor: pointer;
&:hover {
.collapse-icon {
color: var(--ti-lowcode-meta-code-editor-header-collapse-icon-hover-color);
}
}
.collapse-icon {
margin-left: 4px;
color: var(--ti-lowcode-meta-code-editor-header-collapse-icon-color);
}
}
}
.header-tips-demo {
overflow: hidden;
margin-bottom: 12px;
padding: 8px 12px;
border-radius: 8px;
color: var(--ti-lowcode-meta-code-editor-header-tips-demo-color);
background-color: var(--ti-lowcode-meta-code-editor-header-tips-demo-bg-color);
.header-tips-demo-content {
max-height: 98px;
overflow-y: auto;
}
pre {
margin: 0px;
}
code {
font-family: Consolas, Menlo, Monaco, Courier New, monospace, serif;
}
}

.source-code-content {
overflow-y: auto;
height: 100%;
flex: 1;
border: 1px solid var(--ti-lowcode-meta-code-editor-source-code-content-border-color);
}

.source-code-split-panel-wrapper {
height: 100%;

:deep(.tiny-split-trigger) {
width: 2px;
}

&-right {
padding: 16px 0 0 16px;

pre {
margin: 8px;
}

code {
font-family: Microsoft YaHei, Microsoft YaHei-Normal;
color: var(--ti-lowcode-base-text-color-3);
}
}
}

.error-msg {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"passwordTip2": " to add an encrypted parameter to configure the value.",
"createEncryption": "Create Encrypted Parameter",
"expandExample": "Show Example",
"collapseExample": "Hide Example"
"collapseExample": "Hide Example",
"exampleCode": "Example Code"
}
}
3 changes: 2 additions & 1 deletion packages/common/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"passwordTip2": "通过加密参数来配置密码数据。",
"createEncryption": "创建加密参数",
"expandExample": "展开示例",
"collapseExample": "收起示例"
"collapseExample": "收起示例",
"exampleCode": "示例代码"
}
}
1 change: 1 addition & 0 deletions packages/theme/common/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@
// tiny-vue dialogBox 弹框样式
.tiny-dialog-box__wrapper {
.tiny-dialog-box {
border-radius: 6px;
background-color: var(--ti-lowcode-dialog-box-bg-color);
.tiny-dialog-box__header {
color: var(--ti-lowcode-dialog-header-color);
Expand Down