/**
 * DevExtreme (cjs/ui/html_editor/matchers/wordLists.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.default = void 0;

function getListType(matches) {
    const prefix = matches[1];
    return prefix.match(/\S+\./) ? "ordered" : "bullet"
}

function getIndent(node) {
    const style = node.getAttribute("style");
    if (style) {
        const level = style.replace(/\n+/g, "").match(/level(\d+)/);
        return level ? level[1] - 1 : 0
    } else {
        return false
    }
}

function removeNewLineChar(operations) {
    const newLineOperation = operations[operations.length - 1];
    newLineOperation.insert = newLineOperation.insert.trim()
}
const getMatcher = quill => {
    const Delta = quill.import("delta");
    return (node, delta) => {
        const ops = delta.ops.slice();
        const insertOperation = ops[0];
        insertOperation.insert = insertOperation.insert.replace(/^\s+/, "");
        const listDecoratorMatches = insertOperation.insert.match(/^(\S+)\s+/);
        const indent = listDecoratorMatches && getIndent(node);
        if (!listDecoratorMatches || false === indent) {
            return delta
        }
        insertOperation.insert = insertOperation.insert.substring(listDecoratorMatches[0].length, insertOperation.insert.length);
        removeNewLineChar(ops);
        ops.push({
            insert: "\n",
            attributes: {
                list: getListType(listDecoratorMatches),
                indent: indent
            }
        });
        return new Delta(ops)
    }
};
var _default = getMatcher;
exports.default = _default;
module.exports = exports.default;
module.exports.default = exports.default;
