import { jsx as _jsx } from "react/jsx-runtime";
import { addStyleAttributes, createInternalStyleSpec, getStyleParseRules, stylePropsToAttributes, } from "@endexai/blocknote-core";
import { Mark } from "@tiptap/react";
import { renderToDOMSpec } from "./@util/ReactRenderUtil.js";
// A function to create custom block for API consumers
// we want to hide the tiptap node from API consumers and provide a simpler API surface instead
export function createReactStyleSpec(styleConfig, styleImplementation) {
    const mark = Mark.create({
        name: styleConfig.type,
        addAttributes() {
            return stylePropsToAttributes(styleConfig.propSchema);
        },
        parseHTML() {
            return getStyleParseRules(styleConfig);
        },
        renderHTML({ mark }) {
            const props = {};
            if (styleConfig.propSchema === "string") {
                props.value = mark.attrs.stringValue;
            }
            const Content = styleImplementation.render;
            const renderResult = renderToDOMSpec((refCB) => _jsx(Content, { ...props, contentRef: refCB }), undefined);
            return addStyleAttributes(renderResult, styleConfig.type, mark.attrs.stringValue, styleConfig.propSchema);
        },
    });
    return createInternalStyleSpec(styleConfig, {
        mark,
    });
}
//# sourceMappingURL=ReactStyleSpec.js.map