"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getFragmentsFromSelection = void 0;
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
var _contextHelpers = require("./context-helpers");
/**
 * Get the fragments from the selection.
 * @param selection The selection to get the fragments from.
 * @param schema The schema to use to convert the nodes to JSON.
 * @returns The fragments as an array of JSON nodes.
 */
var getFragmentsFromSelection = exports.getFragmentsFromSelection = function getFragmentsFromSelection(selection) {
  if (!selection || selection.empty) {
    return null;
  }
  var slice = (0, _contextHelpers.getSliceFromSelection)(selection);
  var content = slice.content;
  var fragment = [];
  content.forEach(function (node) {
    fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
  });
  return fragment;
};