Skip to content

Commit

Permalink
feat(editor): 代码块功能新增slot
Browse files Browse the repository at this point in the history
  • Loading branch information
parisma authored and jia000 committed Sep 22, 2022
1 parent 2a8cfe5 commit 452c80d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/editor/src/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<template #code-block-panel-header>
<slot name="code-block-panel-header"></slot>
</template>

<template #code-block-panel-tool>
<slot name="code-block-panel-tool"></slot>
</template>
</sidebar>
</slot>
</template>
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/layouts/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<template #code-block-panel-header v-if="item === 'code-block'">
<slot name="code-block-panel-header"></slot>
</template>

<template #code-block-panel-tool v-if="item === 'code-block'">
<slot name="code-block-panel-tool"></slot>
</template>
</tab-pane>
</el-tabs>
</template>
Expand Down
5 changes: 5 additions & 0 deletions packages/editor/src/layouts/sidebar/TabPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<component v-else-if="config.slots?.codeBlockPanelHeader" :is="config.slots.codeBlockPanelHeader" />
</template>

<template #code-block-panel-tool v-if="data === 'code-block' || config.slots?.codeBlockPanelTool">
<slot v-if="data === 'code-block'" name="code-block-panel-tool"></slot>
<component v-else-if="config.slots?.codeBlockPanelTool" :is="config.slots.codeBlockPanelTool" />
</template>

<template
#layer-node-content="{ data: nodeData, node }"
v-if="data === 'layer' || config.slots?.layerNodeContent"
Expand Down
22 changes: 13 additions & 9 deletions packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<template>
<div class="m-editor-code-block-list">
<slot name="code-block-panel-header"></slot>
<div class="create-code-button">
<el-button type="primary" size="small" @click="createCodeBlock">新增代码块</el-button>
</div>
<el-divider class="divider" />
<slot name="code-block-panel-header">
<div class="create-code-button">
<el-button type="primary" size="small" @click="createCodeBlock">新增代码块</el-button>
</div>
<el-divider class="divider" />
</slot>

<!-- 代码块列表 -->
<div class="list-container" v-if="state.codeBlockMap">
<div v-for="(value, key) in state.codeBlockMap" :key="key">
<div class="list-item">
<div class="code-name">{{ value.name }}({{ key }})</div>
<el-tooltip class="box-item" effect="dark" content="编辑代码" placement="top">
<el-icon class="edit-icon" @click="editCode(key)"><EditPen /></el-icon>
</el-tooltip>
<div class="right-tool">
<el-tooltip effect="dark" content="编辑代码" placement="top">
<el-icon class="edit-icon" @click="editCode(key)"><Edit /></el-icon>
</el-tooltip>
<slot name="code-block-panel-tool"></slot>
</div>
</div>
</div>
</div>
Expand All @@ -25,7 +29,7 @@

<script lang="ts" setup>
import { inject, reactive, watchEffect } from 'vue';
import { EditPen } from '@element-plus/icons-vue';
import { Edit } from '@element-plus/icons-vue';
import type { CodeBlockConfig, Services, State } from '../../../type';
Expand Down
9 changes: 7 additions & 2 deletions packages/editor/src/theme/code-block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@
.list-item {
display: flex;
align-items: center;
.edit-icon {
.right-tool {
position: absolute;
right: 15px;
padding-left: 5px;
background-color: #fff;
display: flex;
align-items: center;
.edit-icon {
padding: 0 5px;
}
}
.code-name {
font-size: 14px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding: 10px 15px;
margin-right: 15px;
margin-right: 60px;
}
}
}
Expand Down

0 comments on commit 452c80d

Please sign in to comment.