Browse Source

feat: new snippet ui

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1950/head
Pranav C 2 years ago
parent
commit
0d13fbabc6
  1. 163
      packages/nc-gui/components/project/spreadsheet/components/codeSnippet.vue

163
packages/nc-gui/components/project/spreadsheet/components/codeSnippet.vue

@ -1,52 +1,65 @@
<template> <template>
<v-dialog v-model="modal"> <div class="nc-container" :class="{active:modal}" @click="modal=false">
<v-card style="overflow: hidden"> <div class="nc-snippet elevation-3 pa-4" @click.stop>
<v-tabs v-model="tab" height="30" @change="client=null"> <h3 class="font-weight-medium mb-4">
<v-tab Code Snippet
v-for="{lang} in langs" </h3>
:key="lang"
class="caption" <v-icon class="nc-snippet-close" @click="modal=false">
> mdi-close
{{ lang }} </v-icon>
</v-tab>
</v-tabs> <div style="overflow: hidden">
<div class="nc-snippet-wrapper"> <v-tabs v-model="tab" height="30" @change="client=null">
<div class="nc-snippet-actions d-flex"> <v-tab
<v-btn color="primary" class="rounded caption " @click="copyToClipboard"> v-for="{lang} in langs"
<v-icon small> :key="lang"
mdi-clipboard-outline class="caption"
</v-icon> Copy To Clipboard
</v-btn>
<div
v-if="langs[tab].clients"
class=" ml-2 d-flex align-center"
> >
<v-menu bottom offset-y> {{ lang }}
<template #activator="{on}"> </v-tab>
<v-btn class="caption" color="primary" v-on="on"> </v-tabs>
{{ client || langs[tab].clients[0] }} <v-icon small> <div class="nc-snippet-wrapper mt-4">
mdi-chevron-down <div class="nc-snippet-actions d-flex">
</v-icon> <v-btn color="primary" class="rounded caption " @click="copyToClipboard">
</v-btn> <v-icon small>
</template> mdi-clipboard-outline
<v-list dense> </v-icon>
<v-list-item v-for="c in langs[tab].clients" :key="c" dense @click="client = c"> Copy To Clipboard
<v-list-item-title>{{ c }}</v-list-item-title> </v-btn>
</v-list-item> <div
</v-list> v-if="langs[tab].clients"
</v-menu> class=" ml-2 d-flex align-center"
>
<v-menu bottom offset-y>
<template #activator="{on}">
<v-btn class="caption" color="primary" v-on="on">
{{ client || langs[tab].clients[0] }}
<v-icon small>
mdi-chevron-down
</v-icon>
</v-btn>
</template>
<v-list dense>
<v-list-item v-for="c in langs[tab].clients" :key="c" dense @click="client = c">
<v-list-item-title>{{ c }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</div>
</div> </div>
<custom-monaco-editor :theme="$store.state.windows.darkTheme ? 'vs-dark' : 'vs-light'" style="min-height:500px;max-width: 100%" :value="code" read-only />
</div> </div>
<custom-monaco-editor style="min-height:500px;max-width: 100%" :value="code" read-only />
</div> </div>
</v-card> </div>
</v-dialog> </div>
</template> </template>
<script> <script>
import HTTPSnippet from 'httpsnippet' import HTTPSnippet from 'httpsnippet'
import CustomMonacoEditor from '~/components/monaco/CustomMonacoEditor' import CustomMonacoEditor from '~/components/monaco/CustomMonacoEditor'
import { copyTextToClipboard } from '~/helpers/xutils' import { copyTextToClipboard } from '~/helpers/xutils'
export default { export default {
name: 'CodeSnippet', name: 'CodeSnippet',
components: { CustomMonacoEditor }, components: { CustomMonacoEditor },
@ -129,7 +142,7 @@ export default {
return `${ return `${
this.client === 'node' this.client === 'node'
? 'const { Api } require("nocodb-sdk");' ? 'const { Api } require("nocodb-sdk");'
: 'import { Api } from "nocodb-sdk";' : 'import { Api } from "nocodb-sdk";'
} }
const api = new Api({ const api = new Api({
@ -155,6 +168,13 @@ api.dbViewRow.list(
return this.snippet.convert(this.langs[this.tab].lang, this.client || (this.langs[this.tab].clients && this.langs[this.tab].clients[0]), {}) return this.snippet.convert(this.langs[this.tab].lang, this.client || (this.langs[this.tab].clients && this.langs[this.tab].clients[0]), {})
} }
}, },
mounted() {
(document.querySelector('[data-app]') || this.$root.$el).append(this.$el)
},
destroyed() {
this.$el.parentNode && this.$el.parentNode.removeChild(this.$el)
},
methods: { methods: {
copyToClipboard() { copyToClipboard() {
copyTextToClipboard(this.code) copyTextToClipboard(this.code)
@ -164,14 +184,69 @@ api.dbViewRow.list(
} }
</script> </script>
<style scoped> <style scoped lang="scss">
.nc-snippet-wrapper{ .nc-snippet-wrapper {
position:relative; position: relative;
} }
.nc-snippet-actions{
.nc-snippet-actions {
position: absolute; position: absolute;
right: 10px; right: 10px;
bottom:10px; bottom: 10px;
z-index: 99999; z-index: 99999;
} }
.nc-container {
position: fixed;
pointer-events: none;
width: 100vw;
height: 100vh;
z-index: 9999;
right: 0;
top: 0;
.nc-snippet {
background-color: var(--v-backgroundColorDefault-base);
height: 100%;
width: max(50%, 700px);
position: absolute;
bottom: 0;
top: 0;
right: min(-50%, -700px);
transition: .3s right;
}
&.active {
pointer-events: all;
& > .nc-snippet {
right: 0
}
}
.nc-snippet-close {
position: absolute;
right: 16px;
top: 16px;
}
}
::v-deep {
.v-tabs {
height: 100%;
.v-tabs-items {
height: calc(100% - 30px);
.v-window__container {
height: 100%;
}
}
}
.v-slide-group__prev--disabled {
display: none
}
}
</style> </style>

Loading…
Cancel
Save