Add some toy example for a contenteditable div
Note: does not work currenty, because the parent attribute overwrites the value. Need to implement something that prevents the overwrite while the element is focused
This commit is contained in:
parent
198c9d75cf
commit
396dc00bc9
|
|
@ -1,5 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
<div class="text-form">
|
<div class="text-form">
|
||||||
|
<div
|
||||||
|
class="text-form__input skillbox-textarea"
|
||||||
|
contenteditable="true"
|
||||||
|
@input="change"
|
||||||
|
v-text="text"
|
||||||
|
/>
|
||||||
<textarea
|
<textarea
|
||||||
:value="text"
|
:value="text"
|
||||||
class="text-form__input skillbox-textarea"
|
class="text-form__input skillbox-textarea"
|
||||||
|
|
@ -11,6 +18,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
let selection;
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
|
|
@ -18,19 +26,32 @@
|
||||||
default: null,
|
default: null,
|
||||||
validator(value) {
|
validator(value) {
|
||||||
return Object.prototype.hasOwnProperty.call(value, 'text');
|
return Object.prototype.hasOwnProperty.call(value, 'text');
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
index: {
|
index: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: -1
|
default: -1,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
text() {
|
text() {
|
||||||
return this.value.text ? this.value.text.replace(/<br(\/)?>/, '\n').replace(/(<([^>]+)>)/ig, '') : '';
|
return this.value.text ? this.value.text.replace(/<br(\/)?>/, '\n').replace(/(<([^>]+)>)/ig, '') : '';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
log(e) {
|
||||||
|
console.log(e);
|
||||||
|
},
|
||||||
|
change(event) {
|
||||||
|
selection = window.getSelection().getRangeAt(0);
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
this.$emit('change-text', event.target.innerText, this.index);
|
||||||
|
window.getSelection().addRange(selection);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -41,5 +62,11 @@
|
||||||
&__input {
|
&__input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__contenteditable {
|
||||||
|
width: 100%;
|
||||||
|
height: 300px;
|
||||||
|
background-color: pink;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue