How to use the @instructure/ui-utils.cloneArray function in @instructure/ui-utils

To help you get started, we’ve selected a few @instructure/ui-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github instructure / instructure-ui / packages / ui-elements / src / TruncateText / utils / truncate.js View on Github external
for (let i = 0; i < this._nodeMap.length; i++) {
      const item = this._nodeMap[i]
      if (truncate === 'word' && item.data[item.data.length - 1] === ' ') {
        // remove random whitespace data between nodes
        item.data.length -= 1
      }
      stringData[i] = item.data
      for (let j = 0; j < item.data.length; j++) {
        // map each word or character datum index to its corresponding node
        nodeDataIndexes.push(i)
      }
    }

    this._defaultStringData = cloneArray(stringData)
    this._nodeDataIndexes = cloneArray(nodeDataIndexes)
    this._maxHeight = maxLines === 'auto'
      ? getBoundingClientRect(this._parent).height
      : maxLines * actualLineHeight
    this._maxWidth = measureText(this._nodeMap.map(item => item.node), this._parent)
    this._maxLines = maxLines === 'auto'
      ? Math.round(this._maxHeight / actualLineHeight)
      : maxLines
  }
github instructure / instructure-ui / packages / ui-elements / src / TruncateText / utils / truncate.js View on Github external
const { ellipsis, ignore, position } = this._options
    const middle = position === 'middle'

    let truncated = false
    let fits = false
    let nodeIndex = 0
    let dataIndex = 0
    let truncatedText = ''
    let stringData = null
    let remove = null

    if (!this._stage) {
      return
    }

    stringData = cloneArray(this._defaultStringData)
    dataIndex = middle ? 0 : this._nodeDataIndexes.length - 1

    while (!fits) {
      if (dataIndex < 0) {
        break
      }

      if (middle) {
        // as data is removed from the middle of our set, the node order could
        // change each iteration, so we need to keep updating a node index matrix
        // based on the current string data
        const matrix = this.getNodeIndexes(stringData)
        const center = Math.floor(matrix.length / 2)
        // the node index and word index to remove
        remove = matrix[center]
        if (dataIndex > 0) {
github instructure / instructure-ui / packages / ui-elements / src / TruncateText / utils / truncate.js View on Github external
this._nodeMap = this.getNodeMap(node)

    for (let i = 0; i < this._nodeMap.length; i++) {
      const item = this._nodeMap[i]
      if (truncate === 'word' && item.data[item.data.length - 1] === ' ') {
        // remove random whitespace data between nodes
        item.data.length -= 1
      }
      stringData[i] = item.data
      for (let j = 0; j < item.data.length; j++) {
        // map each word or character datum index to its corresponding node
        nodeDataIndexes.push(i)
      }
    }

    this._defaultStringData = cloneArray(stringData)
    this._nodeDataIndexes = cloneArray(nodeDataIndexes)
    this._maxHeight = maxLines === 'auto'
      ? getBoundingClientRect(this._parent).height
      : maxLines * actualLineHeight
    this._maxWidth = measureText(this._nodeMap.map(item => item.node), this._parent)
    this._maxLines = maxLines === 'auto'
      ? Math.round(this._maxHeight / actualLineHeight)
      : maxLines
  }
github instructure / instructure-ui / packages / ui-elements / src / TruncateText / utils / cleanData.js View on Github external
function cleanData (stringData, options, repeat = false) {
  const {
    truncate,
    ignore,
    ellipsis
  } = options

  let newData = cloneArray(stringData)
  let ellipsisNode = -1
  let ellipsisIndex = -1

  const findEllipsis = () => {
    for (let i = 0; i < newData.length; i++) {
      const nodeData = newData[i]
      if (nodeData.indexOf(ellipsis) !== -1) {
        ellipsisNode = i
        ellipsisIndex = nodeData.indexOf(ellipsis)
      }
    }
  }

  if (truncate === 'character') {
    findEllipsis()