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

97.83% Statements 225/230
88.89% Branches 64/72
96.08% Functions 49/51
97.83% Lines 225/230
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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411   2540× 2540× 2540× 2540× 2540× 2540× 2540× 2540×     38108×     1238×           5226×     1005×           1643×     970×           10653×     1239×           5848×     1003×           1106×     967×           7323×     1253×           9942×     1258×           1276×     1076×           28864×     3060× 181×   2879× 2499×   3060×           71121×     1767× 511×     1256×   1767×           1071×     1061×           995×     976×           1071×     1061×           1283×     1076×         185622× 185622× 125067× 125067× 125067×     60555×   19010× 3645×   19010× 1642×     17368× 17368×   1873×   15495×     1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642× 1642×   26272× 26272× 1642×     64200× 64200×   5723× 5723×   7071× 7071×   76× 76×   4148× 4148×   20978× 20978×   4593× 4593×   1430× 1430×   5898× 5898×   5122× 5122×   992× 992×   1822× 1822×   1822× 1822×   1822× 1822×   1822× 1822×   881× 881×   64200×             23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23×     21×   23×   235054× 233026× 233026×   2028×   945× 944× 941× 941× 941× 941× 941× 941× 941× 941× 941× 941× 941× 941× 941× 941× 941×   944× 942× 942× 942×   944× 123×     821×       736× 726×   736× 720×   736× 736× 736× 736×       16622× 16622×             1006× 1006×       171× 171×   171×         114× 114×   1193×   2124× 2124× 2001×   2124×        
define(["require", "exports", "@syncfusion/ej2-base", "../../base/dictionary", "../../base/unique-format", "../../base/unique-formats", "./borders", "../track-changes/track-changes"], function (require, exports, ej2_base_1, dictionary_1, unique_format_1, unique_formats_1, borders_1, track_changes_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WRowFormat = (function () {
        function WRowFormat(node) {
            this.uniqueRowFormat = undefined;
            this.borders = new borders_1.WBorders(this);
            this.ownerBase = undefined;
            this.beforeWidth = 0;
            this.afterWidth = 0;
            this.revisions = [];
            this.removedIds = [];
            this.ownerBase = node;
        }
        Object.defineProperty(WRowFormat.prototype, "gridBefore", {
            get: function () {
                return this.getPropertyValue('gridBefore');
            },
            set: function (value) {
                this.setPropertyValue('gridBefore', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "gridBeforeWidth", {
            get: function () {
                return this.getPropertyValue('gridBeforeWidth');
            },
            set: function (value) {
                this.setPropertyValue('gridBeforeWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "gridBeforeWidthType", {
            get: function () {
                return this.getPropertyValue('gridBeforeWidthType');
            },
            set: function (value) {
                this.setPropertyValue('gridBeforeWidthType', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "gridAfter", {
            get: function () {
                return this.getPropertyValue('gridAfter');
            },
            set: function (value) {
                this.setPropertyValue('gridAfter', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "gridAfterWidth", {
            get: function () {
                return this.getPropertyValue('gridAfterWidth');
            },
            set: function (value) {
                this.setPropertyValue('gridAfterWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "gridAfterWidthType", {
            get: function () {
                return this.getPropertyValue('gridAfterWidthType');
            },
            set: function (value) {
                this.setPropertyValue('gridAfterWidthType', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "allowBreakAcrossPages", {
            get: function () {
                return this.getPropertyValue('allowBreakAcrossPages');
            },
            set: function (value) {
                this.setPropertyValue('allowBreakAcrossPages', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "isHeader", {
            get: function () {
                return this.getPropertyValue('isHeader');
            },
            set: function (value) {
                this.setPropertyValue('isHeader', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "rightMargin", {
            get: function () {
                return this.getPropertyValue('rightMargin');
            },
            set: function (value) {
                this.setPropertyValue('rightMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "height", {
            get: function () {
                return this.getPropertyValue('height');
            },
            set: function (value) {
                if (value === 0 && (this.heightType === 'AtLeast' || this.heightType === 'Exactly')) {
                    value = 1;
                }
                else if (this.heightType === 'Auto') {
                    value = 0;
                }
                this.setPropertyValue('height', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "heightType", {
            get: function () {
                return this.getPropertyValue('heightType');
            },
            set: function (value) {
                if (value === 'AtLeast' || value === 'Exactly') {
                    this.height = 1;
                }
                else {
                    this.height = 0;
                }
                this.setPropertyValue('heightType', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "bottomMargin", {
            get: function () {
                return this.getPropertyValue('bottomMargin');
            },
            set: function (value) {
                this.setPropertyValue('bottomMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "leftIndent", {
            get: function () {
                return this.getPropertyValue('leftIndent');
            },
            set: function (value) {
                this.setPropertyValue('leftIndent', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "topMargin", {
            get: function () {
                return this.getPropertyValue('topMargin');
            },
            set: function (value) {
                this.setPropertyValue('topMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WRowFormat.prototype, "leftMargin", {
            get: function () {
                return this.getPropertyValue('leftMargin');
            },
            set: function (value) {
                this.setPropertyValue('leftMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        WRowFormat.prototype.getPropertyValue = function (property) {
            var hasValue = this.hasValue(property);
            if (hasValue) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WRowFormat.uniqueFormatType, property);
                Eif (!ej2_base_1.isNullOrUndefined(this.uniqueRowFormat) && this.uniqueRowFormat.propertiesHash.containsKey(propertyType)) {
                    return this.uniqueRowFormat.propertiesHash.get(propertyType);
                }
            }
            return WRowFormat.getPropertyDefaultValue(property);
        };
        WRowFormat.prototype.setPropertyValue = function (property, value) {
            if (ej2_base_1.isNullOrUndefined(value) || value === '') {
                value = WRowFormat.getPropertyDefaultValue(property);
            }
            if (ej2_base_1.isNullOrUndefined(this.uniqueRowFormat)) {
                this.initializeUniqueRowFormat(property, value);
            }
            else {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueRowFormat.uniqueFormatType, property);
                if (this.uniqueRowFormat.propertiesHash.containsKey(propertyType) &&
                    this.uniqueRowFormat.propertiesHash.get(propertyType) === value) {
                    return;
                }
                this.uniqueRowFormat = WRowFormat.uniqueRowFormats.updateUniqueFormat(this.uniqueRowFormat, property, value);
            }
        };
        WRowFormat.prototype.initializeUniqueRowFormat = function (property, propValue) {
            var uniqueRowFormatTemp = new dictionary_1.Dictionary();
            this.addUniqueRowFormat('allowBreakAcrossPages', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('isHeader', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('height', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('heightType', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridBefore', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridBeforeWidth', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridBeforeWidthType', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridAfter', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridAfterWidth', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridgridAfterWidth', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('gridBeforeWidthType', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('leftMargin', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('rightMargin', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('topMargin', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('bottomMargin', property, propValue, uniqueRowFormatTemp);
            this.addUniqueRowFormat('leftIndent', property, propValue, uniqueRowFormatTemp);
            this.uniqueRowFormat = WRowFormat.uniqueRowFormats.addUniqueFormat(uniqueRowFormatTemp, WRowFormat.uniqueFormatType);
        };
        WRowFormat.prototype.addUniqueRowFormat = function (property, modifiedProperty, propValue, uniqueRowFormatTemp) {
            var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WRowFormat.uniqueFormatType, property);
            if (property === modifiedProperty) {
                uniqueRowFormatTemp.add(propertyType, propValue);
            }
        };
        WRowFormat.getPropertyDefaultValue = function (property) {
            var value = undefined;
            switch (property) {
                case 'allowBreakAcrossPages':
                    value = true;
                    break;
                case 'isHeader':
                    value = false;
                    break;
                case 'height':
                    value = 0;
                    break;
                case 'heightType':
                    value = 'Auto';
                    break;
                case 'gridBefore':
                    value = 0;
                    break;
                case 'gridBeforeWidth':
                    value = 0;
                    break;
                case 'gridBeforeWidthType':
                    value = 'Point';
                    break;
                case 'gridAfter':
                    value = 0;
                    break;
                case 'gridAfterWidth':
                    value = 0;
                    break;
                case 'gridAfterWidthType':
                    value = 'Point';
                    break;
                case 'leftMargin':
                    value = undefined;
                    break;
                case 'topMargin':
                    value = undefined;
                    break;
                case 'bottomMargin':
                    value = undefined;
                    break;
                case 'rightMargin':
                    value = undefined;
                    break;
                case 'leftIndent':
                    value = 0;
                    break;
            }
            return value;
        };
        WRowFormat.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));
        };
        WRowFormat.prototype.cloneFormat = function () {
            var format = new WRowFormat();
            format.allowBreakAcrossPages = this.allowBreakAcrossPages;
            format.heightType = this.heightType;
            format.height = this.height;
            format.isHeader = this.isHeader;
            format.gridBefore = this.gridBefore;
            format.gridBeforeWidth = this.gridBeforeWidth;
            format.gridBeforeWidthType = this.gridBeforeWidthType;
            format.gridAfter = this.gridAfter;
            format.gridAfterWidth = this.gridAfterWidth;
            format.gridAfterWidthType = this.gridAfterWidthType;
            format.leftMargin = this.leftMargin;
            format.rightMargin = this.rightMargin;
            format.topMargin = this.topMargin;
            format.bottomMargin = this.bottomMargin;
            format.leftIndent = this.leftIndent;
            if (this.revisions.length > 0) {
                format.removedIds = track_changes_1.Revision.cloneRevisions(this.revisions);
            }
            else {
                format.removedIds = this.removedIds.slice();
            }
            return format;
        };
        WRowFormat.prototype.hasValue = function (property) {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueRowFormat)) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueRowFormat.uniqueFormatType, property);
                return this.uniqueRowFormat.propertiesHash.containsKey(propertyType);
            }
            return false;
        };
        WRowFormat.prototype.copyFormat = function (format) {
            if (!ej2_base_1.isNullOrUndefined(format)) {
                if (!ej2_base_1.isNullOrUndefined(format.uniqueRowFormat)) {
                    this.allowBreakAcrossPages = format.allowBreakAcrossPages;
                    this.isHeader = format.isHeader;
                    this.heightType = format.heightType;
                    this.height = format.height;
                    this.gridBefore = format.gridBefore;
                    this.gridBeforeWidth = format.gridBeforeWidth;
                    this.gridBeforeWidthType = format.gridBeforeWidthType;
                    this.gridAfter = format.gridAfter;
                    this.gridAfterWidth = format.gridAfterWidth;
                    this.gridAfterWidthType = format.gridAfterWidthType;
                    this.leftMargin = format.leftMargin;
                    this.topMargin = format.topMargin;
                    this.rightMargin = format.rightMargin;
                    this.bottomMargin = format.bottomMargin;
                    this.leftIndent = format.leftIndent;
                }
                if (!ej2_base_1.isNullOrUndefined(format.borders)) {
                    this.borders = new borders_1.WBorders(this);
                    this.borders.ownerBase = format;
                    this.borders.copyFormat(format.borders);
                }
                if (format.revisions.length > 0) {
                    this.removedIds = track_changes_1.Revision.cloneRevisions(format.revisions);
                }
                else {
                    this.removedIds = format.removedIds.slice();
                }
            }
        };
        WRowFormat.prototype.destroy = function () {
            if (!ej2_base_1.isNullOrUndefined(this.borders)) {
                this.borders.destroy();
            }
            if (!ej2_base_1.isNullOrUndefined(this.uniqueRowFormat)) {
                WRowFormat.uniqueRowFormats.remove(this.uniqueRowFormat);
            }
            this.beforeWidth = undefined;
            this.afterWidth = undefined;
            this.borders = undefined;
            this.uniqueRowFormat = undefined;
        };
        WRowFormat.clear = function () {
            this.uniqueRowFormats.clear();
        };
        Object.defineProperty(WRowFormat.prototype, "revisionLength", {
            get: function () {
                Eif (!ej2_base_1.isNullOrUndefined(this.revisions)) {
                    return this.revisions.length;
                }
                return 0;
            },
            enumerable: true,
            configurable: true
        });
        WRowFormat.prototype.getRevision = function (index) {
            Eif (!ej2_base_1.isNullOrUndefined(this.revisions)) {
                return this.revisions[index];
            }
            return undefined;
        };
        WRowFormat.prototype.addRevision = function (revision) {
            Eif (this.revisions.indexOf(revision) === -1) {
                this.revisions.push(revision);
            }
            revision.hasChanges = true;
        };
        WRowFormat.prototype.insertRevisionAt = function (index, revision) {
            this.revisions.splice(index, 0, revision);
            revision.hasChanges = true;
        };
        WRowFormat.prototype.removeRevision = function (index) {
            var revision = this.revisions.splice(index, 1)[0];
            revision.hasChanges = true;
        };
        WRowFormat.prototype.getAllRevision = function () {
            return this.revisions;
        };
        WRowFormat.prototype.getRevisionRange = function (revision) {
            var range = [];
            if (this.revisions.indexOf(revision) !== -1) {
                range.push(this);
            }
            return range;
        };
        WRowFormat.uniqueRowFormats = new unique_formats_1.WUniqueFormats();
        WRowFormat.uniqueFormatType = 6;
        return WRowFormat;
    }());
    exports.WRowFormat = WRowFormat;
});