all files / document-editor/implementation/format/ cell-format.js

100% Statements 152/152
98.08% Branches 51/52
100% Functions 34/34
100% Lines 152/152
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269   5411× 5411× 5411× 5411× 5411× 5411×     15166×     1895×           14539×     1894×           13128×     1896×           13173×     1897×           15118×     13929×           167791×     2464×           217647×     2554×           20250×     3481×           12448×     2423×           41119×     2467×         530540× 530540× 150717× 150717× 150717×     379823×   34900× 6945×   34900× 3240×     31660× 31660×   10875×   20785×     3240× 3240× 3240× 3240× 3240× 3240× 3240× 3240× 3240× 3240× 3240× 3240×   32400× 32400× 3240×     386768× 386768×   13879× 13879×   13902× 13902×   13913× 13913×   13985× 13985×   777× 777×   126759× 126759×   163646× 163646×   220× 220×   8339× 8339×   31348× 31348×   386768×   8858×         1725× 1708×   1725× 1708×   1725× 1593×   1725× 1725× 1725×   13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13×   581708× 581547× 581547×   161×   1760× 1759× 1757× 1757× 1757× 1757× 1757× 1757× 1757× 1757× 1757× 1757×   1759× 1758× 1758×   1759× 1758× 1758×              
define(["require", "exports", "@syncfusion/ej2-base", "../../base/dictionary", "../../base/unique-format", "../../base/unique-formats", "./borders", "./shading"], function (require, exports, ej2_base_1, dictionary_1, unique_format_1, unique_formats_1, borders_1, shading_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WCellFormat = (function () {
        function WCellFormat(node) {
            this.uniqueCellFormat = undefined;
            this.borders = new borders_1.WBorders(this);
            this.shading = new shading_1.WShading(this);
            this.ownerBase = node;
            this.borders = new borders_1.WBorders(this);
            this.shading = new shading_1.WShading(this);
        }
        Object.defineProperty(WCellFormat.prototype, "leftMargin", {
            get: function () {
                return this.getPropertyValue('leftMargin');
            },
            set: function (value) {
                this.setPropertyValue('leftMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "rightMargin", {
            get: function () {
                return this.getPropertyValue('rightMargin');
            },
            set: function (value) {
                this.setPropertyValue('rightMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "topMargin", {
            get: function () {
                return this.getPropertyValue('topMargin');
            },
            set: function (value) {
                this.setPropertyValue('topMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "bottomMargin", {
            get: function () {
                return this.getPropertyValue('bottomMargin');
            },
            set: function (value) {
                this.setPropertyValue('bottomMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "cellWidth", {
            get: function () {
                return this.getPropertyValue('cellWidth');
            },
            set: function (value) {
                this.setPropertyValue('cellWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "columnSpan", {
            get: function () {
                return this.getPropertyValue('columnSpan');
            },
            set: function (value) {
                this.setPropertyValue('columnSpan', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "rowSpan", {
            get: function () {
                return this.getPropertyValue('rowSpan');
            },
            set: function (value) {
                this.setPropertyValue('rowSpan', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "preferredWidth", {
            get: function () {
                return this.getPropertyValue('preferredWidth');
            },
            set: function (value) {
                this.setPropertyValue('preferredWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "verticalAlignment", {
            get: function () {
                return this.getPropertyValue('verticalAlignment');
            },
            set: function (value) {
                this.setPropertyValue('verticalAlignment', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "preferredWidthType", {
            get: function () {
                return this.getPropertyValue('preferredWidthType');
            },
            set: function (value) {
                this.setPropertyValue('preferredWidthType', value);
            },
            enumerable: true,
            configurable: true
        });
        WCellFormat.prototype.getPropertyValue = function (property) {
            var hasValue = this.hasValue(property);
            if (hasValue) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WCellFormat.uniqueFormatType, property);
                Eif (!ej2_base_1.isNullOrUndefined(this.uniqueCellFormat) && this.uniqueCellFormat.propertiesHash.containsKey(propertyType)) {
                    return this.uniqueCellFormat.propertiesHash.get(propertyType);
                }
            }
            return WCellFormat.getPropertyDefaultValue(property);
        };
        WCellFormat.prototype.setPropertyValue = function (property, value) {
            if (ej2_base_1.isNullOrUndefined(value) || value === '') {
                value = WCellFormat.getPropertyDefaultValue(property);
            }
            if (ej2_base_1.isNullOrUndefined(this.uniqueCellFormat)) {
                this.initializeUniqueCellFormat(property, value);
            }
            else {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueCellFormat.uniqueFormatType, property);
                if (this.uniqueCellFormat.propertiesHash.containsKey(propertyType) &&
                    this.uniqueCellFormat.propertiesHash.get(propertyType) === value) {
                    return;
                }
                this.uniqueCellFormat = WCellFormat.uniqueCellFormats.updateUniqueFormat(this.uniqueCellFormat, property, value);
            }
        };
        WCellFormat.prototype.initializeUniqueCellFormat = function (property, propValue) {
            var uniqueCellFormatTemp = new dictionary_1.Dictionary();
            this.addUniqueCellFormat('leftMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('topMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('bottomMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('rightMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('cellWidth', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('columnSpan', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('rowSpan', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('preferredWidth', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('verticalAlignment', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('preferredWidthType', property, propValue, uniqueCellFormatTemp);
            this.uniqueCellFormat = WCellFormat.uniqueCellFormats.addUniqueFormat(uniqueCellFormatTemp, WCellFormat.uniqueFormatType);
        };
        WCellFormat.prototype.addUniqueCellFormat = function (property, modifiedProperty, propValue, uniqueCellFormatTemp) {
            var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WCellFormat.uniqueFormatType, property);
            if (property === modifiedProperty) {
                uniqueCellFormatTemp.add(propertyType, propValue);
            }
        };
        WCellFormat.getPropertyDefaultValue = function (property) {
            var value = undefined;
            switch (property) {
                case 'leftMargin':
                    value = undefined;
                    break;
                case 'topMargin':
                    value = undefined;
                    break;
                case 'bottomMargin':
                    value = undefined;
                    break;
                case 'rightMargin':
                    value = undefined;
                    break;
                case 'cellWidth':
                    value = 0;
                    break;
                case 'columnSpan':
                    value = 1;
                    break;
                case 'rowSpan':
                    value = 1;
                    break;
                case 'preferredWidth':
                    value = 0;
                    break;
                case 'verticalAlignment':
                    value = 'Top';
                    break;
                case 'preferredWidthType':
                    value = 'Point';
                    break;
            }
            return value;
        };
        WCellFormat.prototype.containsMargins = function () {
            return (!ej2_base_1.isNullOrUndefined(this.leftMargin)
                || !ej2_base_1.isNullOrUndefined(this.rightMargin)
                || !ej2_base_1.isNullOrUndefined(this.bottomMargin)
                || !ej2_base_1.isNullOrUndefined(this.topMargin));
        };
        WCellFormat.prototype.destroy = function () {
            if (!ej2_base_1.isNullOrUndefined(this.borders)) {
                this.borders.destroy();
            }
            if (!ej2_base_1.isNullOrUndefined(this.shading)) {
                this.shading.destroy();
            }
            if (!ej2_base_1.isNullOrUndefined(this.uniqueCellFormat)) {
                WCellFormat.uniqueCellFormats.remove(this.uniqueCellFormat);
            }
            this.uniqueCellFormat = undefined;
            this.borders = undefined;
            this.shading = undefined;
        };
        WCellFormat.prototype.cloneFormat = function () {
            var format = new WCellFormat(undefined);
            format.verticalAlignment = this.verticalAlignment;
            format.leftMargin = this.leftMargin;
            format.rightMargin = this.rightMargin;
            format.topMargin = this.topMargin;
            format.bottomMargin = this.bottomMargin;
            format.preferredWidth = this.preferredWidth;
            format.preferredWidthType = this.preferredWidthType;
            format.cellWidth = this.cellWidth;
            format.borders = ej2_base_1.isNullOrUndefined(this.borders) ? undefined : this.borders.cloneFormat();
            format.shading = ej2_base_1.isNullOrUndefined(this.shading) ? undefined : this.shading.cloneFormat();
            return format;
        };
        WCellFormat.prototype.hasValue = function (property) {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueCellFormat)) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueCellFormat.uniqueFormatType, property);
                return this.uniqueCellFormat.propertiesHash.containsKey(propertyType);
            }
            return false;
        };
        WCellFormat.prototype.copyFormat = function (format) {
            if (!ej2_base_1.isNullOrUndefined(format)) {
                if (!ej2_base_1.isNullOrUndefined(format.uniqueCellFormat)) {
                    this.cellWidth = format.cellWidth;
                    this.leftMargin = format.leftMargin;
                    this.topMargin = format.topMargin;
                    this.rightMargin = format.rightMargin;
                    this.bottomMargin = format.bottomMargin;
                    this.preferredWidth = format.preferredWidth;
                    this.columnSpan = format.columnSpan;
                    this.rowSpan = format.rowSpan;
                    this.preferredWidthType = format.preferredWidthType;
                    this.verticalAlignment = format.verticalAlignment;
                }
                if (!ej2_base_1.isNullOrUndefined(format.shading)) {
                    this.shading = new shading_1.WShading(this);
                    this.shading.copyFormat(format.shading);
                }
                if (!ej2_base_1.isNullOrUndefined(format.borders)) {
                    this.borders = new borders_1.WBorders(this);
                    this.borders.copyFormat(format.borders);
                }
            }
        };
        WCellFormat.clear = function () {
            this.uniqueCellFormats.clear();
        };
        WCellFormat.uniqueCellFormats = new unique_formats_1.WUniqueFormats();
        WCellFormat.uniqueFormatType = 4;
        return WCellFormat;
    }());
    exports.WCellFormat = WCellFormat;
});