Example #1
0
  children.forEach(child => {
    if (Node.isNodeList(child)) {
      child.forEach(c => push(c))
    }

    if (Node.isNode(child)) {
      push(child)
    }

    if (typeof child === 'string') {
      push(child)
    }

    if (isPoint(child)) {
      if (!nodes.size) {
        push('')
      }

      let last = nodes.last()

      if (last.object !== 'text') {
        push('')
        last = nodes.last()
      }

      if (!last || !last.__string) {
        push('')
        last = nodes.last()
      }

      setPoint(last, child, last.text.length)
    }
  })
Example #2
0
function findDOMNode(key) {
  if (_slate.Node.isNode(key)) {
    key = key.key;
  }

  var el = window.document.querySelector('[data-key="' + key + '"]');

  if (!el) {
    throw new Error('Unable to find a DOM node for "' + key + '". This is often because of forgetting to add `props.attributes` to a custom component.');
  }

  return el;
}
Example #3
0
  children.forEach(child => {
    if (Node.isNode(child)) {
      if (others.length) {
        const text = createText('text', {}, others)
        nodes.push(text)
      }

      nodes.push(child)
      others = []
    } else {
      others.push(child)
    }
  })
Example #4
0
function findDOMNode(key, win = window) {
  if (Node.isNode(key)) {
    key = key.key
  }

  const el = win.document.querySelector(`[data-key="${key}"]`)

  if (!el) {
    throw new Error(`Unable to find a DOM node for "${key}". This is often because of forgetting to add \`props.attributes\` to a custom component.`)
  }

  return el
}
Example #5
0
  fixtures(__dirname, 'models/node', ({ module }) => {
    const { input, output } = module
    const fn = module.default
    let actual = fn(input)
    let expected = output

    if (Node.isNode(actual)) {
      actual = actual.toJSON()
    }

    if (List.isList(actual)) {
      actual = actual.toJSON()
    }

    if (Node.isNode(expected)) {
      expected = expected.toJSON()
    }

    if (List.isList(expected)) {
      expected = expected.toJSON()
    }

    assert.deepEqual(actual, expected)
  })
Example #6
0
  children.forEach(child => {
    // If the child is a non-text node, push the current node and the new child
    // onto the array, then creating a new node for future selection tracking.
    if (Node.isNode(child) && !Text.isText(child)) {
      if (node.text.length || node.__anchor != null || node.__focus != null)
        array.push(node)
      array.push(child)
      node = Text.create()
      length = 0
    }

    // If the child is a string insert it into the node.
    if (typeof child == 'string') {
      setNode(node.insertText(node.text.length, child, options.marks))
      length += child.length
    }

    // If the node is a `Text` add its text and marks to the existing node. If
    // the existing node is empty, and the `key` option wasn't set, preserve the
    // child's key when updating the node.
    if (Text.isText(child)) {
      const { __anchor, __focus } = child
      let i = node.text.length

      if (!options.key && node.text.length == 0) {
        setNode(node.set('key', child.key))
      }

      child.getLeaves().forEach(leaf => {
        let { marks } = leaf
        if (options.marks) marks = marks.union(options.marks)
        setNode(node.insertText(i, leaf.text, marks))
        i += leaf.text.length
      })

      if (__anchor != null) node.__anchor = __anchor + length
      if (__focus != null) node.__focus = __focus + length

      length += child.text.length
    }

    // If the child is a selection object store the current position.
    if (child == ANCHOR || child == CURSOR) node.__anchor = length
    if (child == FOCUS || child == CURSOR) node.__focus = length
  })
 node: create('Node', function (v) {
   return slate.Node.isNode(v);
 }),
Example #8
0
 node: create('Node', v => Node.isNode(v)),