Sha256: 152ee5819dc302fe479eb6b74a1e83db7372c621b6cecfe6e39381cbf1006421

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

#= require trix/views/text_view

{makeElement, getBlockConfig} = Trix

class Trix.BlockView extends Trix.ObjectView
  constructor: ->
    super
    @block = @object
    @attributes = @block.getAttributes()

  createNodes: ->
    comment = document.createComment("block")
    nodes = [comment]
    if @block.isEmpty()
      nodes.push(makeElement("br"))
    else
      textConfig = getBlockConfig(@block.getLastAttribute())?.text
      textView = @findOrCreateCachedChildView(Trix.TextView, @block.text, {textConfig})
      nodes.push(textView.getNodes()...)
      nodes.push(makeElement("br")) if @shouldAddExtraNewlineElement()

    if @attributes.length
      nodes
    else
      element = makeElement(Trix.config.blockAttributes.default.tagName)
      element.appendChild(node) for node in nodes
      [element]

  createContainerElement: (depth) ->
    attribute = @attributes[depth]
    config = getBlockConfig(attribute)
    makeElement(config.tagName)

  # A single <br> at the end of a block element has no visual representation
  # so add an extra one.
  shouldAddExtraNewlineElement:->
    /\n\n$/.test(@block.toString())

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/vendor/trix/src/trix/views/block_view.coffee
vapid-0.1.2 lib/vapid/vendor/trix/src/trix/views/block_view.coffee
vapid-0.1.1 lib/vapid/vendor/trix/src/trix/views/block_view.coffee
vapid-0.1.0 lib/vapid/vendor/trix/src/trix/views/block_view.coffee