Update LiveEditor
parent
1c2a064aa3
commit
c5d7dd06a9
|
@ -158,6 +158,16 @@
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.liveEditorButton a,
|
||||||
|
.liveEditorSplitButton a {
|
||||||
|
padding: 0.75rem 0.5rem;
|
||||||
|
font-weight: normal;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
<template>
|
<template>
|
||||||
<span v-if="showEditor">
|
<span v-if="showEditor">
|
||||||
<Button @click="postSandboxParameters()" label="Edit in CodeSandbox" class="liveEditorButton" />
|
<template v-if="!editComposition">
|
||||||
|
<Button @click="postSandboxParameters('core')" label="Edit in CodeSandbox" class="liveEditorButton" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<SplitButton :model="items" label="Edit in CodeSandbox" class="liveEditorSplitButton" />
|
||||||
|
</template>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -10,9 +15,18 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
sandbox_id: null,
|
sandbox_id: null,
|
||||||
showCodeHighlight: false
|
showCodeHighlight: false,
|
||||||
|
items: [
|
||||||
|
{label: "Core", command: () => { this.postSandboxParameters('core') }},
|
||||||
|
{label: "Composition API", command: () => { this.postSandboxParameters('api') }}
|
||||||
|
],
|
||||||
|
editComposition: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
if(this.sources.api) this.editComposition = true;
|
||||||
|
else this.editComposition = false;
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -48,14 +62,14 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
postSandboxParameters() {
|
postSandboxParameters(sourceType) {
|
||||||
fetch('https://codesandbox.io/api/v1/sandboxes/define?json=1', {
|
fetch('https://codesandbox.io/api/v1/sandboxes/define?json=1', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(this.getSandboxParameters())
|
body: JSON.stringify(this.getSandboxParameters(sourceType))
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => window.open(`https://codesandbox.io/s/${data.sandbox_id}`, '_blank'))
|
.then(data => window.open(`https://codesandbox.io/s/${data.sandbox_id}`, '_blank'))
|
||||||
|
@ -79,11 +93,16 @@ export default {
|
||||||
'primeflex': dependencies['primeflex'],
|
'primeflex': dependencies['primeflex'],
|
||||||
'primeicons': 'latest',
|
'primeicons': 'latest',
|
||||||
'@babel/cli': dependencies['@babel/cli'],
|
'@babel/cli': dependencies['@babel/cli'],
|
||||||
'@vue/cli-plugin-babel': dependencies['@vue/cli-plugin-babel'],
|
|
||||||
'@vue/cli-service': dependencies['@vue/cli-service'],
|
|
||||||
'@vue/compiler-sfc': dependencies['@vue/compiler-sfc'],
|
|
||||||
'core-js': dependencies['core-js']
|
'core-js': dependencies['core-js']
|
||||||
},
|
},
|
||||||
|
devDependencies: {
|
||||||
|
'@vue/cli-plugin-babel': dependencies['@vue/cli-plugin-babel'],
|
||||||
|
'@vue/cli-plugin-eslint': dependencies['@vue/cli-plugin-eslint'],
|
||||||
|
'@vue/cli-service': dependencies['@vue/cli-service'],
|
||||||
|
'@vue/compiler-sfc': dependencies['@vue/compiler-sfc'],
|
||||||
|
'eslint': dependencies['eslint'],
|
||||||
|
'eslint-plugin-vue': dependencies['eslint-plugin-vue']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'babel.config.js': {
|
'babel.config.js': {
|
||||||
|
@ -114,21 +133,33 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getSandboxParameters() {
|
getSandboxParameters(sourceType) {
|
||||||
let name = this.name;
|
let name = this.name;
|
||||||
let extension = '.vue';
|
let extension = '.vue';
|
||||||
let extDependencies = this.dependencies || {};
|
let extDependencies = this.dependencies || {};
|
||||||
let content = this.sources.template.content;
|
let content = this.sources.template.content;
|
||||||
let style = this.sources.template.style || '';
|
let style = this.sources.template.style || '';
|
||||||
|
let api = this.sources.api ? this.sources.api.content : '';
|
||||||
let scriptText = 'script';
|
let scriptText = 'script';
|
||||||
let _files = {}, importElement = '', element = '', components = '', imports = '', directives = '';
|
let _files = {}, importElement = '', element = '', components = '', imports = '', directives = '';
|
||||||
|
|
||||||
|
if(sourceType === 'core') {
|
||||||
_files[`src/components/${name}${extension}`] = {
|
_files[`src/components/${name}${extension}`] = {
|
||||||
content: `${content}
|
content: `${content}
|
||||||
</${scriptText}>
|
</${scriptText}>
|
||||||
|
|
||||||
${style}`
|
${style}`
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(sourceType === 'api') {
|
||||||
|
_files[`src/components/${name}${extension}`] = {
|
||||||
|
content: `${api}
|
||||||
|
</${scriptText}>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let mittComponents = ['ToastDemo', 'OrganizationChartDemo', 'ConfirmDialogDemo', 'ConfirmPopupDemo', 'TerminalDemo', 'SplitButtonDemo', 'DeferredContentDemo', 'OverlayPanelDemo', 'FileUploadDemo'];
|
let mittComponents = ['ToastDemo', 'OrganizationChartDemo', 'ConfirmDialogDemo', 'ConfirmPopupDemo', 'TerminalDemo', 'SplitButtonDemo', 'DeferredContentDemo', 'OverlayPanelDemo', 'FileUploadDemo'];
|
||||||
|
|
||||||
|
@ -531,3 +562,12 @@ ${services[this.service]}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.liveEditorSplitButton {
|
||||||
|
color: red;
|
||||||
|
a:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in New Issue