// @ts-ignore // TODO: fix cjs build
import { findParentNodeOfType, hasParentNodeOfType } from 'prosemirror-utils';
import { NoteAttrs } from "../const.js";
import { noteContentType, noteTitleType, noteType } from "../utils.js";
export function isInsideYfmNote(state) {
    return hasParentNodeOfType(noteType(state.schema))(state.selection);
}
const createYfmNoteNode = (schema) => (type, content) => {
    return noteType(schema).create({
        [NoteAttrs.Class]: `yfm-note yfm-accent-${type}`,
        [NoteAttrs.Type]: type,
    }, [
        noteTitleType(schema).createAndFill(),
        noteContentType(schema).createAndFill({}, content),
    ]);
};
export const createYfmNote = (state, dispatch) => {
    const parent = findParentNodeOfType(state.schema.nodes.paragraph)(state.selection);
    if (parent) {
        const yfmNote = createYfmNoteNode(state.schema)('info', parent.node);
        dispatch?.(state.tr.replaceWith(parent.pos, parent.pos + parent.node.nodeSize, yfmNote));
        return true;
    }
    return false;
};
export const toYfmNote = {
    isEnable(state) {
        return createYfmNote(state);
    },
    run(state, dispatch) {
        createYfmNote(state, dispatch);
    },
};
//# sourceMappingURL=toYfmNote.js.map
