"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 layout_selection_decorator_exports = {};
__export(layout_selection_decorator_exports, {
  layoutSelectionDecorationPlugin: () => layoutSelectionDecorationPlugin
});
module.exports = __toCommonJS(layout_selection_decorator_exports);
var import_ricos_content = require("./../../ricos-content/index.js");
var import_tiptap = require("./../../tiptap/index.js");
var import_state = require("./../../tiptap/pm/state.js");
var import_view = require("./../../tiptap/pm/view.js");
const layoutSelectionDecorationPlugin = () => {
  return new import_state.Plugin({
    key: new import_state.PluginKey("layout-selection-decoration"),
    props: {
      decorations(state) {
        const { $from, $to } = state.selection;
        const layoutNode = (0, import_tiptap.findParentNodeClosestToPos)(
          $from,
          (node) => node.type?.name === import_ricos_content.TIPTAP_LAYOUT_TYPE
        )?.node;
        const decorations = [];
        state.doc.forEach((node, pos) => {
          if (node === layoutNode) {
            decorations.push(
              import_view.Decoration.node(pos, pos + node.nodeSize, {
                "data-layout-selection": ""
              })
            );
          }
        });
        if (isNodeSelection(state.selection) && state.selection.node.type.name === import_ricos_content.TIPTAP_LAYOUT_CELL_TYPE) {
          decorations.push(
            import_view.Decoration.node($from.pos, $to.pos, {
              "data-layout-cell-selection": ""
            })
          );
        }
        return import_view.DecorationSet.create(state.doc, decorations);
      }
    }
  });
};
const isNodeSelection = (selection) => {
  return "node" in selection;
};
//# sourceMappingURL=layout-selection-decorator.js.map
