-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to modify props and data in preview pane (#32)
* chore: add a json input component * chore: retain modified scope of document * chore: show document scope for rendering component * chore: provide default value as scope to component catalog * feat: enable to update props / data value in preview
- Loading branch information
Showing
11 changed files
with
523 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<template> | ||
<input class="input-json" type="text" :value="jsonValue" @change="onChange"> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue' | ||
export default Vue.extend({ | ||
name: 'InputJson', | ||
props: { | ||
value: [Number, String, Boolean, Object, Array] | ||
}, | ||
computed: { | ||
jsonValue(): string { | ||
try { | ||
return this.value === undefined | ||
? 'undefined' | ||
: JSON.stringify(this.value) | ||
} catch (e) { | ||
return 'undefined' | ||
} | ||
} | ||
}, | ||
methods: { | ||
onChange(event: Event) { | ||
const input = event.target as HTMLInputElement | ||
const jsonValue = input.value | ||
try { | ||
const value = | ||
jsonValue === 'undefined' ? undefined : JSON.parse(jsonValue) | ||
this.$emit('change', value) | ||
} catch (e) { | ||
input.value = this.jsonValue | ||
this.$emit('error', jsonValue) | ||
} | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.input-json { | ||
padding: 0; | ||
border-width: 0; | ||
background: none; | ||
font-size: inherit; | ||
font-family: inherit; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.