|
|
@@ -9,13 +9,19 @@
|
|
|
@keydown.stop="handleKeyDown"
|
|
|
contenteditable
|
|
|
v-html="item.content"
|
|
|
+ :class="item.content ? '' : 'placeholder'"
|
|
|
+ :placeholder="item.placeholder"
|
|
|
>
|
|
|
</component>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import blockTypeRegs from '../../utils/block-type-regs'
|
|
|
-import { MODIFY_ITEM, ADD_ITEM_AFTER } from '../../store/types/editor-types'
|
|
|
+import {
|
|
|
+ MODIFY_ITEM,
|
|
|
+ ADD_ITEM_AFTER,
|
|
|
+ DELETE_ITEM
|
|
|
+} from '../../store/types/editor-types'
|
|
|
import { mapState } from 'vuex'
|
|
|
export default {
|
|
|
name: 'editable-item',
|
|
|
@@ -51,7 +57,23 @@ export default {
|
|
|
const focusNode = document.getElementById(this.item.id).nextSibling
|
|
|
focusNode.focus()
|
|
|
})
|
|
|
+ break
|
|
|
|
|
|
+ case 'Backspace':
|
|
|
+ if (!this.isCompositionStarted && !this.item.content) {
|
|
|
+ e.preventDefault()
|
|
|
+ this.$store.commit(DELETE_ITEM, {
|
|
|
+ pageId: this.pageId,
|
|
|
+ itemId: this.item.id
|
|
|
+ })
|
|
|
+ const focusNode = document.getElementById(this.item.id)
|
|
|
+ .previousElementSibling
|
|
|
+ this.$nextTick(() => {
|
|
|
+ focusNode.focus()
|
|
|
+ const focusRange = window.getSelection().getRangeAt(0)
|
|
|
+ focusRange.setStart(focusRange.startContainer.parentNode, 1)
|
|
|
+ })
|
|
|
+ }
|
|
|
break
|
|
|
|
|
|
default:
|
|
|
@@ -81,7 +103,9 @@ export default {
|
|
|
const offset = this.range.startOffset
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
- this.range.setStart(this.range.startContainer.firstChild, offset)
|
|
|
+ if (this.range.startContainer.firstChild) {
|
|
|
+ this.range.setStart(this.range.startContainer.firstChild, offset)
|
|
|
+ }
|
|
|
|
|
|
this.range.collapse()
|
|
|
window.getSelection().removeAllRanges()
|
|
|
@@ -95,7 +119,8 @@ export default {
|
|
|
<style lang="scss" scoped>
|
|
|
* [contenteditable] {
|
|
|
outline: none;
|
|
|
- padding: 10px;
|
|
|
+ padding: 10px 5px;
|
|
|
+ width: 100%;
|
|
|
|
|
|
&:hover {
|
|
|
background: #fafcfe;
|
|
|
@@ -104,5 +129,10 @@ export default {
|
|
|
&:focus {
|
|
|
background: #f9fafc;
|
|
|
}
|
|
|
+
|
|
|
+ &:empty:before {
|
|
|
+ content: attr(placeholder);
|
|
|
+ color: #bbb;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|