Implement option mode

This commit is contained in:
Jos de Jong 2020-08-16 11:44:28 +02:00
parent f2b2769727
commit 8b99527604
3 changed files with 14 additions and 2 deletions

View File

@ -52,7 +52,7 @@
</p> </p>
<script type="module"> <script type="module">
import jsoneditor from './dist/es/jsoneditor.js' import jsoneditor, { TreeMode } from './dist/es/jsoneditor.js'
const doc = { const doc = {
'array': [1, 2, 3, { 'array': [1, 2, 3, {
@ -93,6 +93,7 @@
const testEditor = jsoneditor({ const testEditor = jsoneditor({
target: document.getElementById('testEditorContainer'), target: document.getElementById('testEditorContainer'),
mode: TreeMode,
doc, doc,
onChangeJson: doc => console.log('onChangeJson', doc), onChangeJson: doc => console.log('onChangeJson', doc),
validate: doc => { validate: doc => {

View File

@ -3,8 +3,16 @@
import TreeMode from './treemode/TreeMode.svelte' import TreeMode from './treemode/TreeMode.svelte'
export let config = {} export let config = {}
let mode
let restConfig
$: {
let { _mode, ..._restConfig } = config
mode = _mode
restConfig = _restConfig
}
</script> </script>
<Modal> <Modal>
<TreeMode {...config} /> <svelte:component this={mode || TreeMode} {...restConfig} />
</Modal> </Modal>

View File

@ -1,4 +1,5 @@
import JSONEditor from './components/JSONEditor.svelte' import JSONEditor from './components/JSONEditor.svelte'
import _TreeMode from './components/treemode/TreeMode.svelte'
export default function jsoneditor (config) { export default function jsoneditor (config) {
const { target, ...restConfig } = config const { target, ...restConfig } = config
@ -11,4 +12,6 @@ export default function jsoneditor (config) {
}) })
} }
export const TreeMode = _TreeMode
export { createAjvValidator } from './plugins/createAjvValidator.mjs' export { createAjvValidator } from './plugins/createAjvValidator.mjs'