import isNumber from 'is-number';
import { imageType } from "../../markdown/Image/index.js";
import { ImgSizeAttr } from "./const.js";
export const addImage = (schema) => {
    return {
        isEnable: (state) => state.selection.empty,
        run(state, dispatch, _view, attrs) {
            const params = attrs;
            if (params?.src) {
                const { src, title, alt, width, height } = params;
                const imgAttrs = {
                    [ImgSizeAttr.Src]: src,
                    [ImgSizeAttr.Title]: title ?? '',
                    [ImgSizeAttr.Alt]: alt ?? '',
                };
                if (isNumber(width)) {
                    imgAttrs[ImgSizeAttr.Width] = String(width);
                }
                if (isNumber(height)) {
                    imgAttrs[ImgSizeAttr.Height] = String(height);
                }
                dispatch(state.tr.insert(state.selection.from, imageType(schema).create(imgAttrs)));
            }
        },
    };
};
//# sourceMappingURL=actions.js.map
