|
|
@@ -16,7 +16,6 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import blockTypeRegs from '../../utils/block-type-regs'
|
|
|
import {
|
|
|
MODIFY_ITEM,
|
|
|
ADD_ITEM_AFTER,
|
|
|
@@ -24,9 +23,11 @@ import {
|
|
|
SET_FOCUS_AFTER,
|
|
|
SET_FOCUS_BEFORE,
|
|
|
SET_FOCUS
|
|
|
-} from '../../store/types/editor-types'
|
|
|
-import defaultPlaceholder from '../../utils/default-placeholder'
|
|
|
-import defaultMarkdownFagment from '../../utils/default-markdown-fagment'
|
|
|
+} from '@/store/types/editor-types'
|
|
|
+import defaultPlaceholder from '@/utils/default-placeholder'
|
|
|
+import defaultMarkdownFagment from '@/utils/default-markdown-fragment'
|
|
|
+import { matchType, generateShowInfo } from '@/utils/item-common'
|
|
|
+
|
|
|
export default {
|
|
|
name: 'editable-item',
|
|
|
props: ['item'],
|
|
|
@@ -45,48 +46,11 @@ export default {
|
|
|
},
|
|
|
computed: {
|
|
|
showInfo() {
|
|
|
- if (this.type === 'slideBreak') {
|
|
|
- const content = ''
|
|
|
- return {
|
|
|
- tagName: 'div',
|
|
|
- className: {
|
|
|
- placeholder: true,
|
|
|
- slideBreak: true
|
|
|
- },
|
|
|
- content,
|
|
|
- placeholder: this.item.placeholder
|
|
|
- }
|
|
|
- } else if (this.type === 'div') {
|
|
|
- const content = this.item.content
|
|
|
- return {
|
|
|
- tagName: 'div',
|
|
|
- className: { placeholder: content === '' },
|
|
|
- content,
|
|
|
- placeholder: this.item.placeholder
|
|
|
- }
|
|
|
- } else {
|
|
|
- const content = this.item.content.replace(blockTypeRegs[this.type], '')
|
|
|
- return {
|
|
|
- tagName: this.type,
|
|
|
- className: { placeholder: content === '' },
|
|
|
- content,
|
|
|
- placeholder: this.item.placeholder
|
|
|
- }
|
|
|
- }
|
|
|
+ return generateShowInfo(this.type, this.item)
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- matchType(content) {
|
|
|
- let res = 'div'
|
|
|
- Object.entries(blockTypeRegs)
|
|
|
- .map(array => ({ type: array[0], reg: array[1] }))
|
|
|
- .some(({ type, reg }) => {
|
|
|
- if (reg.test(content)) {
|
|
|
- res = type
|
|
|
- }
|
|
|
- })
|
|
|
- return res
|
|
|
- },
|
|
|
+ matchType,
|
|
|
handleKeyDown(e) {
|
|
|
if (!this.isCompositionStarted) {
|
|
|
switch (e.key) {
|