"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isTaskList = exports.isBulletOrOrderedList = exports.getSupportedListTypesSet = exports.getSupportedListTypes = exports.convertBlockToInlineContent = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
// List type utilities
var isBulletOrOrderedList = exports.isBulletOrOrderedList = function isBulletOrOrderedList(nodeType) {
  return nodeType.name === 'bulletList' || nodeType.name === 'orderedList';
};
var isTaskList = exports.isTaskList = function isTaskList(nodeType) {
  return nodeType.name === 'taskList';
};
var getSupportedListTypes = exports.getSupportedListTypes = function getSupportedListTypes(nodes) {
  return [nodes.bulletList, nodes.orderedList, nodes.taskList].filter(Boolean);
};
var getSupportedListTypesSet = exports.getSupportedListTypesSet = function getSupportedListTypesSet(nodes) {
  return new Set(getSupportedListTypes(nodes));
};

/**
 * Convert a block node to inline content suitable for task items
 */
var convertBlockToInlineContent = exports.convertBlockToInlineContent = function convertBlockToInlineContent(node, schema) {
  var _schema$nodes = schema.nodes,
    paragraph = _schema$nodes.paragraph,
    hardBreak = _schema$nodes.hardBreak;
  if (node.type === paragraph) {
    return (0, _toConsumableArray2.default)(node.content.content);
  }
  if (node.isBlock) {
    var textContent = node.textContent;
    var lines = textContent.split('\n');
    var newText = [];
    lines.forEach(function (line, index) {
      if (line !== '') {
        newText.push(line ? schema.text(line) : schema.text(' '));
      }
      if (lines.length > 1 && index !== lines.length - 1) {
        newText.push(hardBreak.create());
      }
    });
    return newText;
  }
  return [node];
};