|
|
@ -26,38 +26,49 @@ const indicator = h(LoadingOutlined, { |
|
|
|
|
|
|
|
|
|
|
|
const { copy } = useCopy() |
|
|
|
const { copy } = useCopy() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isCopied = ref(false) |
|
|
|
|
|
|
|
|
|
|
|
const langs = [ |
|
|
|
const langs = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'shell', |
|
|
|
name: 'shell', |
|
|
|
clients: ['curl', 'wget'], |
|
|
|
clients: ['curl', 'wget'], |
|
|
|
|
|
|
|
icon: iconMap.langShell, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'javascript', |
|
|
|
name: 'javascript', |
|
|
|
clients: ['axios', 'fetch', 'jquery', 'xhr'], |
|
|
|
clients: ['axios', 'fetch', 'jquery', 'xhr'], |
|
|
|
|
|
|
|
icon: iconMap.langJavascript, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'node', |
|
|
|
name: 'node', |
|
|
|
clients: ['axios', 'fetch', 'request', 'native', 'unirest'], |
|
|
|
clients: ['axios', 'fetch', 'request', 'native', 'unirest'], |
|
|
|
|
|
|
|
icon: iconMap.langNode, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'nocodb-sdk', |
|
|
|
name: 'NocoDB-SDK', |
|
|
|
clients: ['javascript', 'node'], |
|
|
|
clients: ['javascript', 'node'], |
|
|
|
|
|
|
|
icon: iconMap.langNocodbSdk, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'php', |
|
|
|
name: 'php', |
|
|
|
|
|
|
|
icon: iconMap.langPhp, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'python', |
|
|
|
name: 'python', |
|
|
|
clients: ['python3', 'requests'], |
|
|
|
clients: ['python3', 'requests'], |
|
|
|
|
|
|
|
icon: iconMap.langPython, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'ruby', |
|
|
|
name: 'ruby', |
|
|
|
|
|
|
|
icon: iconMap.langRuby, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'java', |
|
|
|
name: 'java', |
|
|
|
|
|
|
|
icon: iconMap.langJava, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'c', |
|
|
|
name: 'c', |
|
|
|
|
|
|
|
icon: iconMap.langC, |
|
|
|
}, |
|
|
|
}, |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
@ -96,8 +107,9 @@ const snippet = computed( |
|
|
|
const activeLang = computed(() => langs.find((lang) => lang.name === selectedLangName.value)) |
|
|
|
const activeLang = computed(() => langs.find((lang) => lang.name === selectedLangName.value)) |
|
|
|
|
|
|
|
|
|
|
|
const code = computed(() => { |
|
|
|
const code = computed(() => { |
|
|
|
if (activeLang.value?.name === 'nocodb-sdk') { |
|
|
|
if (activeLang.value?.name === 'NocoDB-SDK') { |
|
|
|
return `${selectedClient.value === 'node' ? 'const { Api } = require("nocodb-sdk");' : 'import { Api } from "nocodb-sdk";'} |
|
|
|
return `${selectedClient.value === 'node' ? 'const { Api } = require("nocodb-sdk");' : 'import { Api } from "nocodb-sdk";'} |
|
|
|
|
|
|
|
|
|
|
|
const api = new Api({ |
|
|
|
const api = new Api({ |
|
|
|
baseURL: "${(appInfo.value && appInfo.value.ncSiteUrl) || '/'}", |
|
|
|
baseURL: "${(appInfo.value && appInfo.value.ncSiteUrl) || '/'}", |
|
|
|
headers: { |
|
|
|
headers: { |
|
|
@ -113,14 +125,13 @@ api.dbViewRow.list( |
|
|
|
console.log(data); |
|
|
|
console.log(data); |
|
|
|
}).catch(function (error) { |
|
|
|
}).catch(function (error) { |
|
|
|
console.error(error); |
|
|
|
console.error(error); |
|
|
|
}); |
|
|
|
});` |
|
|
|
` |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return snippet.value.convert( |
|
|
|
return snippet.value.convert( |
|
|
|
activeLang.value?.name, |
|
|
|
activeLang.value?.name, |
|
|
|
selectedClient.value || (activeLang.value?.clients && activeLang.value?.clients[0]), |
|
|
|
selectedClient.value || (activeLang.value?.clients && activeLang.value?.clients[0]), |
|
|
|
{}, |
|
|
|
{ indent: '\t' }, |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -129,6 +140,12 @@ const onCopyToClipboard = async () => { |
|
|
|
await copy(code.value) |
|
|
|
await copy(code.value) |
|
|
|
// Copied to clipboard |
|
|
|
// Copied to clipboard |
|
|
|
message.info(t('msg.info.copiedToClipboard')) |
|
|
|
message.info(t('msg.info.copiedToClipboard')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isCopied.value = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
isCopied.value = false |
|
|
|
|
|
|
|
}, 5000) |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
message.error(e.message) |
|
|
|
message.error(e.message) |
|
|
|
} |
|
|
|
} |
|
|
@ -137,64 +154,175 @@ const onCopyToClipboard = async () => { |
|
|
|
watch(activeLang, (newLang) => { |
|
|
|
watch(activeLang, (newLang) => { |
|
|
|
selectedClient.value = newLang?.clients?.[0] |
|
|
|
selectedClient.value = newLang?.clients?.[0] |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const supportedDocs = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'Data APIs', |
|
|
|
|
|
|
|
href: 'https://data-apis-v2.nocodb.com/', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'Meta APIs', |
|
|
|
|
|
|
|
href: 'https://meta-apis-v2.nocodb.com/', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'Create API Token', |
|
|
|
|
|
|
|
href: 'https://docs.nocodb.com/account-settings/api-tokens/#create-api-token', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: 'Swagger', |
|
|
|
|
|
|
|
href: 'https://docs.nocodb.com/bases/actions-on-base/#rest-apis', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
] as { |
|
|
|
|
|
|
|
title: string |
|
|
|
|
|
|
|
href: string |
|
|
|
|
|
|
|
}[] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleNavigateToDocs = (href: string) => { |
|
|
|
|
|
|
|
navigateTo(href, { |
|
|
|
|
|
|
|
open: navigateToBlankTargetOpenOption, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div class="flex flex-col w-full h-full px-6 mt-1"> |
|
|
|
<div |
|
|
|
<NcTabs v-model:activeKey="selectedLangName" class="!h-full"> |
|
|
|
class="p-6" |
|
|
|
<a-tab-pane v-for="item in langs" :key="item.name" class="!h-full"> |
|
|
|
:style="{ |
|
|
|
<template #tab> |
|
|
|
height: 'calc(100vh - var(--topbar-height) - var(--toolbar-height) - 16px)', |
|
|
|
<div class="text-sm capitalize select-none"> |
|
|
|
maxHeight: 'calc(100vh - var(--topbar-height) - var(--toolbar-height) - 16px)', |
|
|
|
|
|
|
|
}" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<div class="flex gap-4 max-w-[1000px] mx-auto h-full"> |
|
|
|
|
|
|
|
<NcMenu class="nc-api-snippets-menu !h-full w-[252px] min-w-[252px] nc-scrollbar-thin !pr-3"> |
|
|
|
|
|
|
|
<div |
|
|
|
|
|
|
|
class="p-2 text-xs text-gray-500 uppercase font-semibold" |
|
|
|
|
|
|
|
:style="{ |
|
|
|
|
|
|
|
letterSpacing: '0.3px', |
|
|
|
|
|
|
|
}" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{{ $t('general.languages') }} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<NcMenuItem |
|
|
|
|
|
|
|
v-for="item in langs" |
|
|
|
|
|
|
|
:key="item.name" |
|
|
|
|
|
|
|
class="rounded-md capitalize select-none" |
|
|
|
|
|
|
|
:class="{ |
|
|
|
|
|
|
|
'active-menu': selectedLangName === item.name, |
|
|
|
|
|
|
|
}" |
|
|
|
|
|
|
|
@click="selectedLangName = item.name" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<div class="flex gap-2 items-center"> |
|
|
|
|
|
|
|
<component :is="item.icon" class="!stroke-transparent h-5 w-5" /> |
|
|
|
{{ item.name }} |
|
|
|
{{ item.name }} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</NcMenuItem> |
|
|
|
|
|
|
|
|
|
|
|
<div class="flex flex-row w-full space-x-3 my-4 items-center"> |
|
|
|
<NcDivider class="!my-3" /> |
|
|
|
<NcSelect |
|
|
|
|
|
|
|
v-if="activeLang?.clients" |
|
|
|
<div class="flex flex-col gap-1"> |
|
|
|
v-model:value="selectedClient" |
|
|
|
<div |
|
|
|
style="width: 10rem" |
|
|
|
class="p-2 text-xs text-gray-500 uppercase font-semibold" |
|
|
|
class="capitalize" |
|
|
|
:style="{ |
|
|
|
dropdown-class-name="nc-dropdown-snippet-active-lang" |
|
|
|
letterSpacing: '0.3px', |
|
|
|
|
|
|
|
}" |
|
|
|
> |
|
|
|
> |
|
|
|
<a-select-option v-for="(client, i) in activeLang?.clients" :key="i" class="!w-full capitalize" :value="client"> |
|
|
|
{{ $t('labels.documentation') }} |
|
|
|
<div class="flex items-center w-full justify-between w-full gap-2"> |
|
|
|
|
|
|
|
<div class="truncate flex-1">{{ client }}</div> |
|
|
|
|
|
|
|
<component |
|
|
|
|
|
|
|
:is="iconMap.check" |
|
|
|
|
|
|
|
v-if="selectedClient === client" |
|
|
|
|
|
|
|
id="nc-selected-item-icon" |
|
|
|
|
|
|
|
class="text-primary w-4 h-4" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</a-select-option> |
|
|
|
|
|
|
|
</NcSelect> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div v-for="(doc, idx) of supportedDocs" :key="idx" class="flex items-center gap-2 px-2 h-7"> |
|
|
|
|
|
|
|
<GeneralIcon icon="bookOpen" class="flex-none w-4 h-4 text-gray-600" /> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a |
|
|
|
|
|
|
|
:href="doc.href" |
|
|
|
|
|
|
|
target="_blank" |
|
|
|
|
|
|
|
rel="noopener noreferrer" |
|
|
|
|
|
|
|
class="!text-gray-700 text-small leading-[18px] !no-underline !hover:underline" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{{ doc.title }} |
|
|
|
|
|
|
|
</a> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</NcMenu> |
|
|
|
|
|
|
|
<div class="w-[calc(100%_-_264px)] flex flex-col gap-6 h-full max-h-full"> |
|
|
|
|
|
|
|
<div class="nc-api-clents-tab-wrapper h-[calc(100%_-_56px)] flex flex-col mt-2"> |
|
|
|
|
|
|
|
<NcTabs v-model:activeKey="selectedClient" class="nc-api-clents-tab"> |
|
|
|
|
|
|
|
<template #rightExtra> |
|
|
|
<NcButton |
|
|
|
<NcButton |
|
|
|
v-e="[ |
|
|
|
v-e="[ |
|
|
|
'c:snippet:copy', |
|
|
|
'c:snippet:copy', |
|
|
|
{ client: activeLang?.clients && (selectedClient || activeLang?.clients[0]), lang: activeLang?.name }, |
|
|
|
{ client: activeLang?.clients && (selectedClient || activeLang?.clients[0]), lang: activeLang?.name }, |
|
|
|
]" |
|
|
|
]" |
|
|
|
type="secondary" |
|
|
|
type="text" |
|
|
|
size="small" |
|
|
|
size="small" |
|
|
|
|
|
|
|
class="!hover:bg-gray-200" |
|
|
|
@click="onCopyToClipboard" |
|
|
|
@click="onCopyToClipboard" |
|
|
|
> |
|
|
|
> |
|
|
|
<div class="flex items-center"> |
|
|
|
<div class="flex items-center gap-2 text-small leading-[18px] min-w-80px justify-center"> |
|
|
|
<GeneralIcon icon="copy" class="mr-1" /> |
|
|
|
<GeneralIcon |
|
|
|
{{ $t('general.copy') }} code |
|
|
|
:icon="isCopied ? 'circleCheck' : 'copy'" |
|
|
|
|
|
|
|
class="h-4 w-4" |
|
|
|
|
|
|
|
:class="{ |
|
|
|
|
|
|
|
'text-gray-700': !isCopied, |
|
|
|
|
|
|
|
'text-green-700': isCopied, |
|
|
|
|
|
|
|
}" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
{{ isCopied ? $t('general.copied') : $t('general.copy') }} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</NcButton> |
|
|
|
</NcButton> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a-tab-pane v-for="client in activeLang?.clients || ['default']" :key="client" class="!h-full"> |
|
|
|
|
|
|
|
<template #tab> |
|
|
|
|
|
|
|
<div class="text-small leading-[18px] capitalize select-none"> |
|
|
|
|
|
|
|
{{ client }} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
<div></div> |
|
|
|
|
|
|
|
</a-tab-pane> |
|
|
|
|
|
|
|
</NcTabs> |
|
|
|
<Suspense> |
|
|
|
<Suspense> |
|
|
|
<MonacoEditor |
|
|
|
<MonacoEditor |
|
|
|
class="border-1 border-gray-200 py-4 rounded-lg" |
|
|
|
class="h-[calc(100%_-_36px)] !bg-gray-50 pl-2" |
|
|
|
style="height: calc(100vh - (var(--topbar-height) * 2) - 8rem)" |
|
|
|
|
|
|
|
:model-value="code" |
|
|
|
:model-value="code" |
|
|
|
:read-only="true" |
|
|
|
:read-only="true" |
|
|
|
lang="typescript" |
|
|
|
lang="typescript" |
|
|
|
:validate="false" |
|
|
|
:validate="false" |
|
|
|
:disable-deep-compare="true" |
|
|
|
:disable-deep-compare="true" |
|
|
|
|
|
|
|
:monaco-config="{ |
|
|
|
|
|
|
|
minimap: { |
|
|
|
|
|
|
|
enabled: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
fontSize: 13, |
|
|
|
|
|
|
|
lineHeight: 18, |
|
|
|
|
|
|
|
padding: { |
|
|
|
|
|
|
|
top: 12, |
|
|
|
|
|
|
|
bottom: 12, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
overviewRulerBorder: false, |
|
|
|
|
|
|
|
overviewRulerLanes: 0, |
|
|
|
|
|
|
|
hideCursorInOverviewRuler: true, |
|
|
|
|
|
|
|
lineDecorationsWidth: 12, |
|
|
|
|
|
|
|
lineNumbersMinChars: 0, |
|
|
|
|
|
|
|
roundedSelection: false, |
|
|
|
|
|
|
|
selectOnLineNumbers: false, |
|
|
|
|
|
|
|
scrollBeyondLastLine: false, |
|
|
|
|
|
|
|
contextmenu: false, |
|
|
|
|
|
|
|
glyphMargin: false, |
|
|
|
|
|
|
|
folding: false, |
|
|
|
|
|
|
|
bracketPairColorization: { enabled: false }, |
|
|
|
|
|
|
|
wordWrap: 'on', |
|
|
|
|
|
|
|
scrollbar: { |
|
|
|
|
|
|
|
horizontal: 'hidden', |
|
|
|
|
|
|
|
verticalScrollbarSize: 6, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
wrappingStrategy: 'advanced', |
|
|
|
|
|
|
|
renderLineHighlight: 'none', |
|
|
|
|
|
|
|
tabSize: 4, |
|
|
|
|
|
|
|
detectIndentation: false, |
|
|
|
|
|
|
|
insertSpaces: true, |
|
|
|
|
|
|
|
lineNumbers: 'off', |
|
|
|
|
|
|
|
}" |
|
|
|
hide-minimap |
|
|
|
hide-minimap |
|
|
|
/> |
|
|
|
/> |
|
|
|
<template #fallback> |
|
|
|
<template #fallback> |
|
|
@ -203,13 +331,71 @@ watch(activeLang, (newLang) => { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
</Suspense> |
|
|
|
</Suspense> |
|
|
|
</a-tab-pane> |
|
|
|
</div> |
|
|
|
</NcTabs> |
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
<style lang="scss" scoped> |
|
|
|
:deep(.ant-tabs-tab + .ant-tabs-tab) { |
|
|
|
.nc-api-snippets-menu { |
|
|
|
@apply !ml-7; |
|
|
|
@apply border-r-0 !py-0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.ant-menu-item) { |
|
|
|
|
|
|
|
@apply h-7 leading-5 my-1.5 px-2 text-gray-700 flex items-center; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.nc-menu-item-inner { |
|
|
|
|
|
|
|
@apply text-small leading-[18px] text-current font-weight-500; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
&:hover:not(.active-menu) { |
|
|
|
|
|
|
|
@apply !bg-gray-100; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
&.active-menu { |
|
|
|
|
|
|
|
@apply bg-brand-50; |
|
|
|
|
|
|
|
.nc-menu-item-inner { |
|
|
|
|
|
|
|
@apply text-brand-600 font-semibold; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.nc-api-clents-tab.ant-tabs) { |
|
|
|
|
|
|
|
.ant-tabs-nav { |
|
|
|
|
|
|
|
@apply px-3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.ant-tabs-tab { |
|
|
|
|
|
|
|
@apply px-3 pt-2 pb-2.5; |
|
|
|
|
|
|
|
& + .ant-tabs-tab { |
|
|
|
|
|
|
|
@apply !ml-2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
&.ant-tabs-tab-active { |
|
|
|
|
|
|
|
@apply font-semibold; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.ant-tabs-content { |
|
|
|
|
|
|
|
@apply h-full; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
</style> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss"> |
|
|
|
|
|
|
|
.nc-api-clents-tab-wrapper { |
|
|
|
|
|
|
|
@apply bg-gray-50 border-1 border-gray-200 rounded-lg flex-1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.monaco-editor { |
|
|
|
|
|
|
|
@apply !border-0 !rounded-none pr-3; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.overflow-guard { |
|
|
|
|
|
|
|
@apply !border-0 !rounded-none; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.monaco-editor, |
|
|
|
|
|
|
|
.monaco-diff-editor, |
|
|
|
|
|
|
|
.monaco-component { |
|
|
|
|
|
|
|
--vscode-editor-background: #f9f9fa; |
|
|
|
|
|
|
|
--vscode-editorGutter-background: #f9f9fa; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |
|
|
|