Skip to content

Commit

Permalink
feat(core): support $editor.clear, bug fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
marsprince committed Sep 21, 2020
1 parent 1039e74 commit bf33790
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions packages/slate-vue/components/slate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ export const Slate = tsx.component({
// prepare two objects, one for immer, the other for vue
// when we get immer result, patch it to vue
;(this as any).renderSlate()
;(this as any).$editor.clear = () => {
this.renderSlate(JSON.stringify([
{
children: [
{ text: '' },
],
},
]))
}
},
watch: {
value(newVal, oldVal) {
if(newVal!==oldVal) {
if(!newVal) {
// slate empty
newVal = JSON.stringify([
{
children: [
{ text: '' },
],
},
])
}
this.renderSlate(newVal)
}
}
Expand All @@ -53,11 +52,17 @@ export const Slate = tsx.component({
* @param newVal
*/
renderSlate(newVal: any) {
const value = newVal || this.value
;(this as any).$editor.children = JSON.parse(value);
const value = newVal || (this as any).value
const editor = (this as any).$editor
editor.children = JSON.parse(value);
const $$data = JSON.parse(value);
;(this as any).$editor._state= Vue.observable($$data)
editor._state= Vue.observable($$data)

;(this as any).clearEditor();
;(this as any).name = this.genUid()
},
clearEditor() {
;(this as any).$editor.selection = null
}
},
render() {
Expand Down
2 changes: 1 addition & 1 deletion site/pages/plaintext/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
methods: {
clear() {
this.value = ''
this.$editor.clear()
}
}
};
Expand Down

0 comments on commit bf33790

Please sign in to comment.