1.2.4-alpha.0 • Published 2 years ago

@kdujs/repl v1.2.4-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@kdujs/repl

Kdu SFC REPL as a Kdu 3 component.

Simple Usage

<script setup>
import { Repl } from '@kdujs/repl'
import '@kdujs/repl/style.css'
</script>

<template>
  <Repl />
</template>

Advanced Usage

<script setup>
import { watchEffect } from 'kdu'
import { Repl, ReplStore } from '@kdujs/repl'

// retrieve some configuration options from the URL
const query = new URLSearchParams(location.search)

const store = new ReplStore({
  // initialize repl with previously serialized state
  serializedState: location.hash.slice(1),

  // starts on the output pane (mobile only) if the URL has a showOutput query
  showOutput: query.has('showOutput'),
  // starts on a different tab on the output pane if the URL has a outputMode query
  // and default to the "preview" tab
  outputMode: (query.get('outputMode') || 'preview'),

  // specify the default URL to import Kdu runtime from in the sandbox
  // default is the CDN link from unpkg.com with version matching Kdu's version
  // from peerDependency
  defaultKduRuntimeURL: 'cdn link to kdu.runtime.esm-browser.js'
})

// persist state to URL hash
watchEffect(() => history.replaceState({}, '', store.serialize()))

// pre-set import map
store.setImportMap({
  imports: {
    myLib: 'cdn link to esm build of myLib'
  }
})

// use a specific version of Kdu
store.setKduVersion('3.2.8')
</script>

<template>
  <Repl :store="store" :showCompileOutput="true" />
</template>