import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import { registerCustoms } from "../../../plugins";
import elementPluginWrapper from "./elementPluginWrapper";
import createElementsPlugin from "./createElementsPlugin";
import renderPluginsWrapper from "../../../render/utils/renderPluginsWrapper";
export var registerCustomPlugin = function registerCustomPlugin(customPlugin) {
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'pc';
  var custPlugin = typeof customPlugin === 'function' ? customPlugin() : customPlugin;
  var plugins = elementPluginWrapper(custPlugin) || [];

  if (plugins.length > 0) {
    registerCustoms(plugins, type);
  }
}; // 注册自定义插件

export var registerCustomPlugins = function registerCustomPlugins(customPlugins) {
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'pc';
  var excludes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  var plugins = getCustomPlugins(customPlugins, excludes);

  if (plugins && plugins.length > 0) {
    registerCustoms(plugins, type);
  }
}; // 注册区块

export var registerBlockPlugin = function registerBlockPlugin(plugin) {
  createElementsPlugin(plugin);
};
export var getCustomPlugins = function getCustomPlugins(customPlugins) {
  var excludes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  var plugins = [];

  if (customPlugins && customPlugins.length > 0) {
    customPlugins.forEach(function (func) {
      var plugin = typeof func === 'function' ? func() : func;
      var itemPlugins = [];

      if (plugin.data) {
        // 暂时不注册table
        if (!excludes.includes(plugin.name)) {
          // editorPlugins
          itemPlugins = elementPluginWrapper(plugin) || [];
        }
      } else {
        // renderPlugin
        itemPlugins = [renderPluginsWrapper(plugin)];
      }

      plugins.push.apply(plugins, _toConsumableArray(itemPlugins));
    });
  }

  return plugins;
}; // 根据customPlugin data生成json

export var getCustomPluginJson = function getCustomPluginJson(item) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var children = [];
  var elements = item.elements,
      data = item.data,
      name = item.name;

  if (Array.isArray(elements)) {
    children = elements;
  }

  if (typeof elements === 'function') {
    children = elements();
  }

  return _objectSpread({
    type: name,
    data: data,
    elements: children
  }, options);
};
//# sourceMappingURL=util.js.map