all files / blockeditor/managers/ intermediate.js

100% Statements 80/80
100% Branches 10/10
100% Functions 20/20
100% Lines 80/80
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120   1390× 1390×   1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390×   1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390× 1390×   3806×   11374×   33×   127×       127× 127×   171×   28×   27×   26×   1829× 2184×   2184× 2184×   2184×   2184×         1829× 1829× 1829×   34×         34×   34×   33×         33×   33×   85×   1390×        
define(["require", "exports", "../../common/constant", "../../common/constant", "@syncfusion/ej2-base", "../../common/utils/transform"], function (require, exports, constant_1, constants, ej2_base_1, transform_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Intermediate = (function () {
        function Intermediate(editor) {
            this.editor = editor;
            this.wireGlobalEvents();
        }
        Intermediate.prototype.wireGlobalEvents = function () {
            this.editor.blockManager.observer.on('updateEditorBlocks', this.handleModelChanges, this);
            this.editor.blockManager.observer.on('selectionChanged', this.handleSelectionChange, this);
            this.editor.blockManager.observer.on('beforePaste', this.triggerBeforePaste, this);
            this.editor.blockManager.observer.on('afterPaste', this.triggerAfterPaste, this);
            this.editor.blockManager.observer.on('blockActionsMenuClose', this.triggerBlockActionsMenuCloseEvent, this);
            this.editor.blockManager.observer.on('blockActionsMenuOpen', this.triggerBlockActionsMenuOpenEvent, this);
            this.editor.blockManager.observer.on('blockDragging', this.triggerBlockDrag, this);
            this.editor.blockManager.observer.on('blockDragStart', this.triggerBlockStart, this);
            this.editor.blockManager.observer.on('blockDropped', this.triggerBlockDrop, this);
            this.editor.blockManager.observer.on('triggerBlockChange', this.triggerBlockChangeEvent, this);
            this.editor.blockManager.observer.on('renderTemplateBlock', this.editor.renderTemplate, this.editor);
            this.editor.blockManager.observer.on('renderDropdownList', this.renderDropdownList, this);
            this.editor.on(constant_1.events.destroy, this.destroy, this);
        };
        Intermediate.prototype.unWireGlobalEvents = function () {
            this.editor.blockManager.observer.off('updateEditorBlocks', this.handleModelChanges);
            this.editor.blockManager.observer.off('selectionChanged', this.handleSelectionChange);
            this.editor.blockManager.observer.off('beforePaste', this.triggerBeforePaste);
            this.editor.blockManager.observer.off('afterPaste', this.triggerAfterPaste);
            this.editor.blockManager.observer.off('blockActionsMenuClose', this.triggerBlockActionsMenuCloseEvent);
            this.editor.blockManager.observer.off('blockActionsMenuOpen', this.triggerBlockActionsMenuOpenEvent);
            this.editor.blockManager.observer.off('blockDragging', this.triggerBlockDrag);
            this.editor.blockManager.observer.off('blockDragStart', this.triggerBlockStart);
            this.editor.blockManager.observer.off('blockDropped', this.triggerBlockDrop);
            this.editor.blockManager.observer.off('triggerBlockChange', this.triggerBlockChangeEvent);
            this.editor.blockManager.observer.off('renderTemplateBlock', this.editor.renderTemplate);
            this.editor.blockManager.observer.off('renderDropdownList', this.renderDropdownList);
            this.editor.off(constant_1.events.destroy, this.destroy);
        };
        Intermediate.prototype.processActions = function (action, args) {
            this.editor.blockManager.observer.notify(action, args);
        };
        Intermediate.prototype.handleModelChanges = function (state) {
            this.editor.setProperties({ blocks: state.blocks }, true);
        };
        Intermediate.prototype.handleSelectionChange = function (args) {
            this.editor.trigger('selectionChanged', args);
        };
        Intermediate.prototype.triggerBeforePaste = function (args) {
            var eventArgs = {
                cancel: args.cancel,
                content: args.content
            };
            this.editor.trigger('beforePaste', eventArgs);
            args.callback(eventArgs);
        };
        Intermediate.prototype.triggerAfterPaste = function (args) {
            this.editor.trigger('afterPaste', args);
        };
        Intermediate.prototype.triggerBlockDrag = function (args) {
            this.editor.trigger('blockDragging', args);
        };
        Intermediate.prototype.triggerBlockStart = function (args) {
            this.editor.trigger('blockDragStart', args);
        };
        Intermediate.prototype.triggerBlockDrop = function (args) {
            this.editor.trigger('blockDropped', args);
        };
        Intermediate.prototype.triggerBlockChangeEvent = function (changes) {
            var validChanges = changes
                .filter(function (_, index) { return Number.isInteger(index) && changes[index] !== undefined; })
                .map(function (change) {
                var clonedData = transform_1.cloneObject(change.data, ['targetId', 'isMovingUp']);
                if (!ej2_base_1.isNullOrUndefined(change.data.currentParent)) {
                    clonedData.currentParent = change.data.currentParent;
                }
                if (!ej2_base_1.isNullOrUndefined(change.data.prevParent)) {
                    clonedData.prevParent = change.data.prevParent;
                }
                return {
                    action: change.action,
                    data: clonedData
                };
            });
            var blockChangeEventArgs = { changes: validChanges };
            this.editor.eventManager.triggerBlockChangeEvent(blockChangeEventArgs);
            this.editor.blockManager.observer.notify(constants.CLEAREVENTCHANGES);
        };
        Intermediate.prototype.triggerBlockActionsMenuCloseEvent = function (args) {
            var eventArgs = {
                event: args.event,
                items: args.items,
                cancel: args.cancel
            };
            if (this.editor.blockActionMenuSettings.closing) {
                this.editor.blockActionMenuSettings.closing.call(this, eventArgs);
            }
            args.callback(eventArgs);
        };
        Intermediate.prototype.triggerBlockActionsMenuOpenEvent = function (args) {
            var eventArgs = {
                event: args.event,
                items: args.items,
                cancel: args.cancel
            };
            if (this.editor.blockActionMenuSettings.opening) {
                this.editor.blockActionMenuSettings.opening.call(this, eventArgs);
            }
            args.callback(eventArgs);
        };
        Intermediate.prototype.renderDropdownList = function (args) {
            this.editor.dropdownListRenderer.renderDropDownList(args);
        };
        Intermediate.prototype.destroy = function () {
            this.unWireGlobalEvents();
        };
        return Intermediate;
    }());
    exports.Intermediate = Intermediate;
});