"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addImage = void 0;
const tslib_1 = require("tslib");
const is_number_1 = tslib_1.__importDefault(require("is-number"));
const Image_1 = require("../../markdown/Image/index.js");
const const_1 = require("./const.js");
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 = {
                    [const_1.ImgSizeAttr.Src]: src,
                    [const_1.ImgSizeAttr.Title]: title ?? '',
                    [const_1.ImgSizeAttr.Alt]: alt ?? '',
                };
                if ((0, is_number_1.default)(width)) {
                    imgAttrs[const_1.ImgSizeAttr.Width] = String(width);
                }
                if ((0, is_number_1.default)(height)) {
                    imgAttrs[const_1.ImgSizeAttr.Height] = String(height);
                }
                dispatch(state.tr.insert(state.selection.from, (0, Image_1.imageType)(schema).create(imgAttrs)));
            }
        },
    };
};
exports.addImage = addImage;
//# sourceMappingURL=actions.js.map
