"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var card_paste_plugin_exports = {};
__export(card_paste_plugin_exports, {
  createCardPastePlugin: () => createCardPastePlugin
});
module.exports = __toCommonJS(card_paste_plugin_exports);
var import_ricos_content = require("./../ricos-content/index.js");
var import_model = require("./../tiptap/pm/model.js");
var import_state = require("./../tiptap/pm/state.js");
const isCardWrapperType = (typeName) => typeName === import_ricos_content.TIPTAP_CARD_HEADER_TYPE || typeName === import_ricos_content.TIPTAP_CARD_FOOTER_TYPE;
const transformPastedNode = (node) => {
  if (node.isText) {
    return [node];
  }
  const newChildren = [];
  node.content.forEach((child) => {
    newChildren.push(...transformPastedNode(child));
  });
  if (isCardWrapperType(node.type.name)) {
    return newChildren;
  }
  let attrs = node.attrs;
  if (node.type.name === import_ricos_content.TIPTAP_LAYOUT_TYPE && attrs?.banner) {
    attrs = { ...attrs, banner: null };
  }
  if (attrs?.id) {
    attrs = { ...attrs, id: (0, import_ricos_content.generateId)() };
  }
  return [node.type.create(attrs, import_model.Fragment.from(newChildren), node.marks)];
};
const createCardPastePlugin = () => {
  return new import_state.Plugin({
    key: new import_state.PluginKey("card-paste"),
    props: {
      transformPasted(slice) {
        const newChildren = [];
        slice.content.forEach((child) => {
          newChildren.push(...transformPastedNode(child));
        });
        return new import_model.Slice(import_model.Fragment.from(newChildren), slice.openStart, slice.openEnd);
      }
    }
  });
};
//# sourceMappingURL=card-paste-plugin.js.map
