"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getNestingRulesFromSchema = void 0;
var _schemaDefault = require("@atlaskit/adf-schema/schema-default");
var getNestingRulesFromSchema = exports.getNestingRulesFromSchema = function getNestingRulesFromSchema() {
  var KEYWORDS = ['inline', 'block', 'text', 'leaf', 'group', 'unsupportedBlock', 'unsupportedInline'];
  var rules = {};
  for (var _i = 0, _Object$keys = Object.keys(_schemaDefault.defaultSchema.nodes); _i < _Object$keys.length; _i++) {
    var _defaultSchema$nodes$;
    var nodeType = _Object$keys[_i];
    var contentStr = (_defaultSchema$nodes$ = _schemaDefault.defaultSchema.nodes[nodeType]) === null || _defaultSchema$nodes$ === void 0 ? void 0 : _defaultSchema$nodes$.spec.content;
    if (!contentStr) {
      continue;
    }
    var allowedChildren =
    // eslint-disable-next-line require-unicode-regexp
    (String(contentStr).match(/\b([a-zA-Z_][a-zA-Z0-9_]*)\b/g) || []).filter(function (match, index, arr) {
      return !KEYWORDS.includes(match) && _schemaDefault.defaultSchema.nodes[match] && arr.indexOf(match) === index;
    });
    if (allowedChildren.length > 0) {
      rules[nodeType] = allowedChildren;
    }
  }
  return rules;
};