Cell.vue 1.84 KB
Newer Older
Anton's avatar
Intial  
Anton committed
1
2
3
4
5
6
7
<template lang="pug">

  .cell-item-inner(:class="{'display-preview': preview, 'display-full': display}")
    template(v-if="cellTypeName")
      component(
        :is="cellTypeName",
        :cell="cell",
8
        :class="cellClasses",
Anton's avatar
Intial  
Anton committed
9
        :display="display",
Anton's avatar
Anton committed
10
        :preview="preview")
Anton's avatar
Intial  
Anton committed
11
12
13
14
15
16
17
18
19
20
21
22

    template(v-else)
      div Empty cell

    slot

</template>

<script>
  import cellTypes from './cells'

  export default {
Anton's avatar
Anton committed
23
    props: ['cell', 'display', 'preview', 'annotation'],
Anton's avatar
Intial  
Anton committed
24
25
26
27
28
29
30
31
    data () {
      return {
        selected: false
      }
    },
    computed: {
      cellTypeName () {
        return this.cell.type ? this.cellTypeToClassName(this.cell.type) : ''
32
33
      },
      cellClasses () {
34
        let classes = ['cell-content']
35
36
        if (this.cell) {
          if (this.cell.type) classes.push(`cell-type-${this.cell.type.toLowerCase()}`)
37
38
39
          if (this.cell.styleClass) {
            classes = classes.concat(this.cell.styleClass.split(' '))
          }
40
41
        }
        return classes
Anton's avatar
Intial  
Anton committed
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
70
71
72
73
74
75
76
77
78
      }
    },
    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>