2023-02-28 08:29:30 +00:00
import sdk from '@stackblitz/sdk' ;
import { getVueApp } from './templates' ;
const useCodeSandbox = ( language , code , service , extPages , dependencies , component , extFiles ) => {
const getSandboxParameters = ( sourceType ) => {
const { files , dependenciesDemo , sourceFileName } = getVueApp ( { code , service , extPages , dependencies , component , extFiles } , sourceType ) ;
files [ 'sandbox.config.json' ] = {
content : {
infiniteLoopProtection : false
}
} ;
return { files , dependenciesDemo , sourceFileName } ;
} ;
const sandboxParameters = getSandboxParameters ( { language } ) ;
fetch ( 'https://codesandbox.io/api/v1/sandboxes/define?json=1' , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
Accept : 'application/json'
} ,
body : JSON . stringify ( sandboxParameters )
} )
. then ( ( response ) => response . json ( ) )
. then ( ( data ) => window . open ( ` https://codesandbox.io/s/ ${ data . sandbox _id } ` , '_blank' ) ) ;
} ;
2023-07-25 19:30:22 +00:00
const useStackBlitz = ( language , code , service , extPages , dependencies , component , extFiles , embedded = false ) => {
2023-02-28 08:29:30 +00:00
const getStackBlitzParameters = ( sourceType ) => {
2023-07-25 19:30:22 +00:00
const { files , dependenciesDemo , sourceFileName } = getVueApp ( { code , service , extPages , dependencies , component , extFiles , embedded } , sourceType ) ;
2023-02-28 08:29:30 +00:00
return { files , dependenciesDemo , sourceFileName } ;
} ;
const stackBlitzParameters = getStackBlitzParameters ( { language } ) ;
let files = { } ;
Object . entries ( stackBlitzParameters . files ) . forEach ( ( [ k , v ] ) => ( files [ ` ${ k } ` ] = typeof v . content === 'object' ? JSON . stringify ( v . content , null , 2 ) : v . content ) ) ;
2023-07-25 19:30:22 +00:00
const primevueproject = {
title : embedded ? 'PrimeVue Tailwind Demo' : 'PrimeVue Demo' ,
template : 'node' ,
description : embedded
? "This example demonstrates how to style components with Tailwind CSS using PrimeVue's unstyled property. As mentioned in the PrimeVue documentation, components can be styled or have HTML attributes added using a global or inline pass through approach. In this example, we utilize the global PT approach with Tailwind CSS."
: '**\n PrimeVue is an open source UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, which has 400+ ready to use UI blocks to build spectacular applications in no time.' ,
dependencies : stackBlitzParameters . dependencies ,
files
} ;
if ( embedded ) {
sdk . embedProject ( 'embed' , primevueproject , {
openFile : 'src/main.js' ,
view : 'default' ,
height : '800px'
} ) ;
} else {
sdk . openProject ( primevueproject , {
2023-02-28 08:29:30 +00:00
newWindow : true ,
openFile : [ stackBlitzParameters . sourceFileName ]
2023-07-25 19:30:22 +00:00
} ) ;
}
2023-02-28 08:29:30 +00:00
} ;
export { useCodeSandbox , useStackBlitz } ;