all files / editor-manager/plugin/ ai-assitant-actions.js

100% Statements 31/31
100% Branches 9/9
100% Functions 8/8
100% Lines 31/31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50   2746× 2746×   2746× 2746×   2744× 2744×   10× 10×                       2744× 2744×        
define(["require", "exports", "../../common/constant", "./inserthtml", "@syncfusion/ej2-base"], function (require, exports, EVENTS, inserthtml_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AIAssistantActions = (function () {
        function AIAssistantActions(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        AIAssistantActions.prototype.addEventListener = function () {
            this.parent.observer.on(EVENTS.AI_ASSISTANT_ACTIONS, this.actionHandler, this);
            this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
        };
        AIAssistantActions.prototype.removeEventListener = function () {
            this.parent.observer.off(EVENTS.AI_ASSISTANT_ACTIONS, this.actionHandler);
            this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
        };
        AIAssistantActions.prototype.actionHandler = function (args) {
            var subCommand = args.subCommand;
            if (subCommand === 'InsertResponseContent') {
                this.parent.nodeSelection.restore();
                var currentRange = this.parent.nodeSelection.getRange(this.parent.currentDocument);
                var closestBlockElement = this.parent.domNode.blockNodes()[0];
                if (currentRange.collapsed && !ej2_base_1.isNullOrUndefined(closestBlockElement) && closestBlockElement.textContent.length > 0) {
                    currentRange.selectNodeContents(closestBlockElement);
                }
                inserthtml_1.InsertHtml.Insert(this.parent.currentDocument, args.value, this.parent.editableElement, true, args.enterAction, this.parent);
                this.callBack(args);
            }
            else if (subCommand === 'ReplaceEditorContent') {
                this.parent.editableElement.innerHTML = args.value;
            }
        };
        AIAssistantActions.prototype.callBack = function (event) {
            event.callBack({
                requestType: event.command,
                action: event.subCommand,
                editorMode: 'HTML',
                range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
                elements: this.parent.nodeSelection.getSelectedNodes(this.parent.currentDocument)
            });
        };
        AIAssistantActions.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        return AIAssistantActions;
    }());
    exports.AIAssistantActions = AIAssistantActions;
});