"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 open_floating_prompt_input_exports = {};
__export(open_floating_prompt_input_exports, {
  openFloatingPromptInput: () => openFloatingPromptInput
});
module.exports = __toCommonJS(open_floating_prompt_input_exports);
var import_floating_prompt_input = require("./floating-prompt-input.js");
const openFloatingPromptInput = ({
  nodeId,
  editor,
  modals,
  getColorPalette
}) => {
  const { view } = editor;
  const rootLevelNodePosition = view.state.selection.$from.before(1);
  const nodeDOM = view.nodeDOM(rootLevelNodePosition);
  const referenceElement = nodeDOM instanceof Element ? nodeDOM : view.dom;
  try {
    if (rootLevelNodePosition > 0) {
      editor.commands.setTextSelection(rootLevelNodePosition - 1);
    }
  } catch (error) {
    console.error("Error selecting text before the node", error);
  }
  modals.openModal({
    id: import_floating_prompt_input.FLOATING_PROMPT_INPUT_MODAL_ID,
    Component: import_floating_prompt_input.FloatingPromptInput,
    componentProps: { nodeId, getColorPalette },
    type: "exclusive",
    layout: "manual",
    positioning: {
      placement: "bottom",
      referenceElement: {
        getBoundingClientRect: () => referenceElement.getBoundingClientRect(),
        focus: () => view.focus()
      }
    },
    returnFocusToEditor: true
  });
};
//# sourceMappingURL=open-floating-prompt-input.js.map
