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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        :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) : ''
33
34
35
36
37
      },
      cellClasses () {
        const classes = ['cell-content']
        if (this.cell) {
          if (this.cell.type) classes.push(`cell-type-${this.cell.type.toLowerCase()}`)
38
          if (this.cell.styleClass) classes.push(this.cell.styleClass)
39
40
        }
        return classes
Anton's avatar
Intial  
Anton committed
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
70
71
72
73
74
75
76
77
      }
    },
    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>