Cell.vue 1.59 KB
Newer Older
Anton's avatar
Intial  
Anton committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template lang="pug">

  .cell-item-inner(:class="{'display-preview': preview, 'display-full': display}")
    template(v-if="cellTypeName")
      component(
        :is="cellTypeName",
        :cell="cell",
        :class="'cell-content cell-type-' + cell.type.toLowerCase()",
        :display="display",
        :preview="preview",
        :messenger="messenger")

    template(v-else)
      div Empty cell

    slot

</template>

<script>
  import cellTypes from './cells'

  export default {
    props: ['cell', 'display', 'preview', 'messenger', 'annotation'],
    data () {
      return {
        selected: false
      }
    },
    computed: {
      cellTypeName () {
        return this.cell.type ? this.cellTypeToClassName(this.cell.type) : ''
      }
    },
    mounted () {
      if (this.cellTypeName && cellTypes.hasOwnProperty(this.cellTypeName) === false) {
        throw new Error('This cell type is missing: ' + this.cell.type)
      }
    },
    methods: {
      cellTypeToClassName (type) {
        return 'Cell' + type.slice(0, 1).toUpperCase() + type.slice(1).replace(/[^a-z0-9]/ig, '')
      },
      handleClick () {
        this.selected = !this.selected
      },
      handleDragStart (event) {
        event.dataTransfer.setData('text/plain', JSON.stringify(this.cell))
      }
    },
    components: cellTypes
  }
</script>

<style scoped lang="stylus">

  .display-preview .cell-content
      pointer-events none

  .cell-content
      h1, h2, h3, h4, h5, h6
        font-size: 1em
        font-weight: normal

      a, a:hover, a:visited
        color: black
        text-decoration: underline

</style>