"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const ReferenceElementWrapper = require("../references/ReferenceElementWrapper.cjs");
const reactErrorBoundary = require("react-error-boundary");
const slateReact = require("slate-react");
const ui = require("@contember/ui");
const react = require("react");
const SortedBlocksContext = require("../state/SortedBlocksContext.cjs");
const SortableRepeaterItem = require("../../../collections/Repeater/SortableRepeaterItem.cjs");
const SortableRepeaterItemHandle = require("../../../collections/Repeater/SortableRepeaterItemHandle.cjs");
const ElementWithReference = require("../elements/ElementWithReference.cjs");
const DragHandle = require("../../../../ui/DragHandle.cjs");
const overrideRenderElement = (editor) => {
  const { renderElement } = editor;
  editor.renderElement = (props) => {
    let children = renderElement(props);
    const path = slateReact.ReactEditor.findPath(editor, props.element);
    if (ElementWithReference.isElementWithReference(props.element)) {
      children = /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactErrorBoundary.ErrorBoundary, { fallback: /* @__PURE__ */ jsxDevRuntime.jsxDEV("span", { style: { background: "red", color: "white" }, children: "Invalid element" }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
        lineNumber: 21,
        columnNumber: 30
      }, void 0), children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ReferenceElementWrapper.ReferenceElementWrapper, { element: props.element, children }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
        lineNumber: 22,
        columnNumber: 6
      }, void 0) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
        lineNumber: 21,
        columnNumber: 5
      }, void 0);
    }
    if (path.length === 1) {
      return /* @__PURE__ */ jsxDevRuntime.jsxDEV(SortableBlock, { element: props.element, children }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
        lineNumber: 27,
        columnNumber: 11
      }, void 0);
    }
    return children;
  };
};
const SortableBlock = ({ children, element }) => {
  const editor = slateReact.useSlateStatic();
  const sortedBlocks = react.useContext(SortedBlocksContext.SortedBlocksContext);
  const [index] = slateReact.ReactEditor.findPath(editor, element);
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(SortableRepeaterItem.SortableRepeaterItem, { index, children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.EditorBlock, { dragHandle: /* @__PURE__ */ jsxDevRuntime.jsxDEV(SortableRepeaterItemHandle.SortableRepeaterItemHandle, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(DragHandle.DragHandle, {}, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
    lineNumber: 41,
    columnNumber: 57
  }, void 0) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
    lineNumber: 41,
    columnNumber: 29
  }, void 0), children }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
    lineNumber: 41,
    columnNumber: 4
  }, void 0) }, sortedBlocks[index]?.id, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/editor/overrideRenderElement.tsx",
    lineNumber: 40,
    columnNumber: 3
  }, void 0);
};
exports.overrideRenderElement = overrideRenderElement;
//# sourceMappingURL=overrideRenderElement.cjs.map
