import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
import { mapChildren } from '../utils/slice';
export var transformSliceExpandToNestedExpand = function transformSliceExpandToNestedExpand(slice) {
  var children = [];
  try {
    mapChildren(slice.content, function (currentNode) {
      var _currentNode$type$sch = currentNode.type.schema.nodes,
        expand = _currentNode$type$sch.expand,
        nestedExpand = _currentNode$type$sch.nestedExpand;
      if (currentNode.type === expand) {
        var nestedExpandNode = nestedExpand.createChecked(currentNode.attrs, currentNode.content, currentNode.marks);
        if (nestedExpandNode) {
          children.push(nestedExpandNode);
        }
      } else {
        children.push(currentNode);
      }
    });
  } catch (e) {
    // Will throw error if unable to convert expand to nested expand.
    // Example: expand containing a table being converted to nested expand containing table.
    return null;
  }
  return new Slice(Fragment.fromArray(children), slice.openStart, slice.openEnd);
};