import { TIPTAP_LAYOUT_CELL_TYPE, TIPTAP_LAYOUT_TYPE } from "./../../ricos-content/index.js";
import { findParentNodeClosestToPos } from "./../../tiptap/index.js";
import { Plugin, PluginKey } from "./../../tiptap/pm/state.js";
import { Decoration, DecorationSet } from "./../../tiptap/pm/view.js";
const layoutSelectionDecorationPlugin = () => {
  return new Plugin({
    key: new PluginKey("layout-selection-decoration"),
    props: {
      decorations(state) {
        const { $from, $to } = state.selection;
        const layoutNode = findParentNodeClosestToPos(
          $from,
          (node) => node.type?.name === TIPTAP_LAYOUT_TYPE
        )?.node;
        const decorations = [];
        state.doc.forEach((node, pos) => {
          if (node === layoutNode) {
            decorations.push(
              Decoration.node(pos, pos + node.nodeSize, {
                "data-layout-selection": ""
              })
            );
          }
        });
        if (isNodeSelection(state.selection) && state.selection.node.type.name === TIPTAP_LAYOUT_CELL_TYPE) {
          decorations.push(
            Decoration.node($from.pos, $to.pos, {
              "data-layout-cell-selection": ""
            })
          );
        }
        return DecorationSet.create(state.doc, decorations);
      }
    }
  });
};
const isNodeSelection = (selection) => {
  return "node" in selection;
};
export {
  layoutSelectionDecorationPlugin
};
//# sourceMappingURL=layout-selection-decorator.js.map
