import { jsx } from "react/jsx-runtime";
import { Path, Text, Transforms } from "slate";
import isHotkey from "is-hotkey";
import { Slate } from "@makeswift/controls";
import { Plugin } from "../../controls/rich-text-v2/plugin";
const BLOCK_ONE_PATH = [0];
const BLOCK_TWO_PATH = [1];
function withInlineMode(editor) {
  const { normalizeNode } = editor;
  editor.normalizeNode = (entry) => {
    const [normalizationNode, normalizationPath] = entry;
    if (Path.equals(BLOCK_TWO_PATH, normalizationPath)) {
      Transforms.mergeNodes(editor, { at: BLOCK_TWO_PATH });
      return;
    }
    if (Path.isAncestor(BLOCK_ONE_PATH, normalizationPath) && Slate.isBlock(normalizationNode)) {
      Transforms.unwrapNodes(editor, {
        at: normalizationPath
      });
      return;
    }
    if (Path.equals(BLOCK_ONE_PATH, normalizationPath)) {
      Transforms.setNodes(editor, { type: Slate.BlockType.Default }, { at: normalizationPath });
      return;
    }
    normalizeNode(entry);
  };
  return editor;
}
function InlineModePlugin() {
  return Plugin({
    onKeyDown: (e) => {
      if (isHotkey("enter", e))
        e.preventDefault();
    },
    withPlugin: withInlineMode,
    renderElement: (renderElement) => (props) => /* @__PURE__ */ jsx(InlineModePluginComponent, { ...props, renderElement })
  });
}
const minWidth = `${"Write some text...".length}ch`;
function InlineModePluginComponent({
  renderElement,
  ...props
}) {
  if (props.element.children.length === 1) {
    const text = props.element.children[0];
    if (Text.isText(text) && text.text === "") {
      return /* @__PURE__ */ jsx("span", { style: { display: "inline-block", minWidth }, ...props.attributes, children: renderElement(props) });
    }
  }
  return /* @__PURE__ */ jsx("span", { style: { minWidth }, ...props.attributes, children: renderElement(props) });
}
export {
  InlineModePlugin,
  withInlineMode
};
//# sourceMappingURL=index.js.map