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: Editor full screen with title, close button, and examples #866

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
59 changes: 34 additions & 25 deletions packages/common/component/MonacoEditor.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<template>
<div :class="['editor-container', { 'editor-container-full': fullscreen }]">
<div class="toolbar">
<div class="toolbar-start">
<slot name="toolbarStart"></slot>
</div>
<div :class="['buttons', { fullscreen: fullscreen }]">
<slot name="buttons"></slot>
<tiny-tooltip v-if="showFormatBtn && options.language === 'json'" content="格式化" placement="top">
<public-icon name="json" @click="formatCode"></public-icon>
</tiny-tooltip>
<span v-if="showFullScreenBtn">
<tiny-tooltip v-if="!fullscreen" content="全屏" placement="top">
<public-icon name="full-screen" @click="switchFullScreen(true)"></public-icon>
</tiny-tooltip>
<tiny-tooltip v-else content="退出全屏" placement="top">
<public-icon name="cancel-full-screen" @click="switchFullScreen(false)"></public-icon>
<slot v-if="fullscreen" name="fullscreenHead"></slot>
<div class="editor-container-content">
<div class="toolbar">
<div class="toolbar-start">
<slot name="toolbarStart"></slot>
</div>
<div :class="['buttons', { fullscreen: fullscreen }]">
<slot name="buttons"></slot>
<tiny-tooltip v-if="showFormatBtn && options.language === 'json'" content="格式化" placement="top">
<public-icon name="json" @click="formatCode"></public-icon>
</tiny-tooltip>
</span>
<span v-if="showFullScreenBtn">
<tiny-tooltip v-if="!fullscreen" content="全屏" placement="top">
<public-icon name="full-screen" @click="switchFullScreen(true)"></public-icon>
</tiny-tooltip>
<tiny-tooltip v-else content="退出全屏" placement="top">
<public-icon name="cancel-full-screen" @click="switchFullScreen(false)"></public-icon>
</tiny-tooltip>
</span>
</div>
</div>
<monaco-editor
ref="editor"
class="editor"
:value="value"
:options="editorOptions"
language="javascript"
@editorDidMount="$emit('editorDidMount', $event)"
></monaco-editor>
</div>
<monaco-editor
ref="editor"
class="editor"
:value="value"
:options="editorOptions"
language="javascript"
@editorDidMount="$emit('editorDidMount', $event)"
></monaco-editor>
<slot v-if="fullscreen" name="fullscreenFooter"></slot>
</div>
</template>

Expand Down Expand Up @@ -137,7 +141,7 @@ export default {
bottom: 0;
left: calc(var(--base-nav-panel-width) + var(--base-left-panel-width));
right: var(--base-left-panel-width);
z-index: 10;
z-index: 100;
padding: 10px 16px 16px 16px;
background-color: var(--ti-lowcode-common-component-bg);
height: auto !important;
Expand All @@ -163,6 +167,11 @@ export default {
}
}

.editor-container-content {
flex: 1;
overflow: hidden;
}

.editor {
flex: 1;
overflow: hidden;
Expand Down
72 changes: 49 additions & 23 deletions packages/plugins/state/src/CreateStore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,43 @@
<template #toolbarStart>
<div class="label-left-wrap"></div>
</template>
<template #fullscreenHead>
<div class="fullscreen-head-content">
<span>state</span>
<close-icon @close="cancel"></close-icon>
</div>
</template>
<template #fullscreenFooter>
<div class="fullscreen-footer-content">
<state-tips></state-tips>
</div>
</template>
</monaco-editor>
<div class="tips">
<div>字符串:"string"</div>
<div>数字:123</div>
<div>布尔值:true/false</div>
<div>对象:{"name":"xxx"}</div>
<div>数组:["1","2"]</div>
<div>空值:null</div>
<div>"color":red</div>
<div>"background":"blue"</div>
</div>
<state-tips></state-tips>
</tiny-form-item>
</tiny-collapse-item>
<tiny-collapse-item title="getters" name="getters">
<tiny-form-item prop="getters">
<monaco-editor ref="gettersEditor" class="store-editor" :options="options" :value="getters"> </monaco-editor>
<monaco-editor ref="gettersEditor" class="store-editor" :options="options" :value="getters">
<template #fullscreenHead>
<div class="fullscreen-head-content">
<span>getters</span>
<close-icon @close="cancel"></close-icon>
</div>
</template>
</monaco-editor>
</tiny-form-item>
</tiny-collapse-item>
<tiny-collapse-item title="actions" name="actions">
<tiny-form-item prop="actions">
<monaco-editor ref="actionsEditor" class="store-editor" :options="options" :value="actions"> </monaco-editor>
<monaco-editor ref="actionsEditor" class="store-editor" :options="options" :value="actions">
<template #fullscreenHead>
<div class="fullscreen-head-content">
<span>actions</span>
<close-icon @close="cancel"></close-icon>
</div>
</template>
</monaco-editor>
</tiny-form-item>
</tiny-collapse-item>
</tiny-collapse>
Expand All @@ -62,13 +78,16 @@
<script>
import { getCurrentInstance, reactive, ref, computed, watch } from 'vue'
import { Form, FormItem, Input, Collapse as TinyCollapse, CollapseItem as TinyCollapseItem } from '@opentiny/vue'
import { MonacoEditor } from '@opentiny/tiny-engine-common'
import { MonacoEditor, CloseIcon } from '@opentiny/tiny-engine-common'
import { string2Ast, ast2String, insertName } from '@opentiny/tiny-engine-common/js/ast'
import { verifyJsVarName } from '@opentiny/tiny-engine-common/js/verification'
import StateTips from './StateTips.vue'

export default {
components: {
MonacoEditor,
CloseIcon,
StateTips,
TinyForm: Form,
TinyFormItem: FormItem,
TinyInput: Input,
Expand All @@ -89,6 +108,7 @@ export default {
type: String
}
},
emits: ['close'],
setup(props, { emit }) {
const instance = getCurrentInstance()
const isDemoShow = ref(false)
Expand Down Expand Up @@ -205,6 +225,10 @@ export default {
return Object.prototype.toString.call(variable) === '[object Object]'
}

const cancel = () => {
emit('close')
}

return {
isDemoShow,
state,
Expand All @@ -219,7 +243,8 @@ export default {
actionsEditor,
editorDidMount,
variableEditor,
actions
actions,
cancel
}
}
}
Expand All @@ -229,15 +254,6 @@ export default {
.store-form {
height: calc(100% - 45px);
overflow-y: auto;
.tips {
font-size: 11px;
line-height: 18px;
margin-top: 8px;
border-radius: 4px;
padding: 8px 14px;
background: var(--ti-lowcode-data-source-box-bg);
color: var(--ti-lowcode-datasource-tip-color);
}
:deep(.tiny-collapse-item__wrap) {
padding: 0 12px;
}
Expand All @@ -261,6 +277,16 @@ export default {
color: var(--ti-lowcode-toolbar-icon-color);
display: flex;
}

.fullscreen-head-content {
font-size: 12px;
color: var(--te-common-text-primary);
height: 30px;
line-height: 20px;
width: 100%;
display: flex;
justify-content: space-between;
}
}

.create-content-description {
Expand Down
Loading