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

99.22% Statements 127/128
95.24% Branches 60/63
100% Functions 23/23
99.22% Lines 127/128
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   41258× 41258× 41258× 41258× 41258×     208×     320×           4504845×     384× 218× 179× 179× 49×       166×   384×           323257×     380×           144360× 144360× 102334×     42026× 42026× 43844× 41901× 41901×     1943×       144360× 144235×     125×           4829005× 4539470× 1841477× 1841477× 2181842× 132302×     2049540×     1841477× 132302× 132302×         289535× 289535× 289535×     4407168×   1084×   1084× 376×     708× 708×   17×   691×     376× 376× 376× 376× 376×   1128× 1128× 376×     4407169× 4407169×   4336063× 4336063×   70943× 70943×   163× 163×   4407169×   6496× 6496× 57× 57× 57×   6496× 5910×   6496× 15×       13864804× 533288× 533288×   13331516×   5643×     5643× 5643×   13877× 139×   13877× 13877× 13877× 13877×   13×   3298×   14301×   151× 151× 151× 151× 151× 151× 151× 151×        
define(["require", "exports", "@syncfusion/ej2-base", "../../base/dictionary", "../../base/unique-format", "../../base/unique-formats", "./style"], function (require, exports, ej2_base_1, dictionary_1, unique_format_1, unique_formats_1, style_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WListFormat = (function () {
        function WListFormat(node) {
            this.uniqueListFormat = undefined;
            this.ownerBase = undefined;
            this.baseStyle = undefined;
            this.list = undefined;
            this.ownerBase = node;
        }
        Object.defineProperty(WListFormat.prototype, "nsid", {
            get: function () {
                return this.getPropertyValue('nsid');
            },
            set: function (id) {
                this.setPropertyValue('nsid', id);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WListFormat.prototype, "listId", {
            get: function () {
                return this.getPropertyValue('listId');
            },
            set: function (listId) {
                if (listId >= 0) {
                    if (!ej2_base_1.isNullOrUndefined(this.ownerBase)) {
                        var helper = this.ownerBase.getDocumentHelperObject();
                        if (!ej2_base_1.isNullOrUndefined(helper)) {
                            this.list = helper.getListById(listId);
                        }
                    }
                }
                else if (!ej2_base_1.isNullOrUndefined(this.list) && listId < 0) {
                    this.list = undefined;
                }
                this.setPropertyValue('listId', listId);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WListFormat.prototype, "listLevelNumber", {
            get: function () {
                return this.getPropertyValue('listLevelNumber');
            },
            set: function (value) {
                this.setPropertyValue('listLevelNumber', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WListFormat.prototype, "listLevel", {
            get: function () {
                var list = undefined;
                if (!ej2_base_1.isNullOrUndefined(this.list)) {
                    list = this.list;
                }
                else {
                    var baseListStyle = this.baseStyle;
                    while (!ej2_base_1.isNullOrUndefined(baseListStyle) && baseListStyle instanceof style_1.WParagraphStyle) {
                        if (baseListStyle.paragraphFormat.listFormat.list) {
                            list = baseListStyle.paragraphFormat.listFormat.list;
                            break;
                        }
                        else {
                            baseListStyle = baseListStyle.basedOn;
                        }
                    }
                }
                if (!ej2_base_1.isNullOrUndefined(list)) {
                    return list.getListLevel(this.listLevelNumber);
                }
                else {
                    return undefined;
                }
            },
            enumerable: true,
            configurable: true
        });
        WListFormat.prototype.getPropertyValue = function (property) {
            if (!this.hasValue(property)) {
                if (this.baseStyle instanceof style_1.WParagraphStyle) {
                    var baseStyle = this.baseStyle;
                    while (!ej2_base_1.isNullOrUndefined(baseStyle)) {
                        if (baseStyle.paragraphFormat.listFormat.hasValue(property)) {
                            break;
                        }
                        else {
                            baseStyle = baseStyle.basedOn;
                        }
                    }
                    if (!ej2_base_1.isNullOrUndefined(baseStyle)) {
                        var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WListFormat.uniqueFormatType, property);
                        return baseStyle.paragraphFormat.listFormat.uniqueListFormat.propertiesHash.get(propertyType);
                    }
                }
            }
            else {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WListFormat.uniqueFormatType, property);
                Eif (!ej2_base_1.isNullOrUndefined(this.uniqueListFormat) && this.uniqueListFormat.propertiesHash.containsKey(propertyType)) {
                    return this.uniqueListFormat.propertiesHash.get(propertyType);
                }
            }
            return WListFormat.getPropertyDefaultValue(property);
        };
        WListFormat.prototype.setPropertyValue = function (property, value) {
            if (ej2_base_1.isNullOrUndefined(value) || value === '') {
                value = WListFormat.getPropertyDefaultValue(property);
            }
            if (ej2_base_1.isNullOrUndefined(this.uniqueListFormat)) {
                this.initializeUniqueListFormat(property, value);
            }
            else {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueListFormat.uniqueFormatType, property);
                if (this.uniqueListFormat.propertiesHash.containsKey(propertyType) &&
                    this.uniqueListFormat.propertiesHash.get(propertyType) === value) {
                    return;
                }
                this.uniqueListFormat = WListFormat.uniqueListFormats.updateUniqueFormat(this.uniqueListFormat, property, value);
            }
        };
        WListFormat.prototype.initializeUniqueListFormat = function (property, propValue) {
            var uniqueListFormatTemp = new dictionary_1.Dictionary();
            this.addUniqueListFormat('listId', property, propValue, uniqueListFormatTemp);
            this.addUniqueListFormat('listLevelNumber', property, propValue, uniqueListFormatTemp);
            this.addUniqueListFormat('nsid', property, propValue, uniqueListFormatTemp);
            this.uniqueListFormat = WListFormat.uniqueListFormats.addUniqueFormat(uniqueListFormatTemp, WListFormat.uniqueFormatType);
        };
        WListFormat.prototype.addUniqueListFormat = function (property, modifiedProperty, propValue, uniqueListFormatTemp) {
            var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WListFormat.uniqueFormatType, property);
            if (property === modifiedProperty) {
                uniqueListFormatTemp.add(propertyType, propValue);
            }
        };
        WListFormat.getPropertyDefaultValue = function (property) {
            var value = undefined;
            switch (property) {
                case 'listId':
                    value = -1;
                    break;
                case 'listLevelNumber':
                    value = 0;
                    break;
                case 'nsid':
                    value = -1;
                    break;
            }
            return value;
        };
        WListFormat.prototype.copyFormat = function (format) {
            Eif (!ej2_base_1.isNullOrUndefined(format)) {
                if (!ej2_base_1.isNullOrUndefined(format.uniqueListFormat)) {
                    this.listId = format.listId;
                    this.listLevelNumber = format.listLevelNumber;
                    this.nsid = format.nsid;
                }
                if (!ej2_base_1.isNullOrUndefined(format.baseStyle)) {
                    this.baseStyle = format.baseStyle;
                }
                if (!ej2_base_1.isNullOrUndefined(format.list)) {
                    this.list = format.list;
                }
            }
        };
        WListFormat.prototype.hasValue = function (property) {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueListFormat)) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueListFormat.uniqueFormatType, property);
                return this.uniqueListFormat.propertiesHash.containsKey(propertyType);
            }
            return false;
        };
        WListFormat.prototype.clearFormat = function () {
            Iif (!ej2_base_1.isNullOrUndefined(this.uniqueListFormat) && this.uniqueListFormat.referenceCount === 0) {
                WListFormat.uniqueListFormats.remove(this.uniqueListFormat);
            }
            this.uniqueListFormat = undefined;
            this.list = undefined;
        };
        WListFormat.prototype.destroy = function () {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueListFormat)) {
                WListFormat.uniqueListFormats.remove(this.uniqueListFormat);
            }
            this.uniqueListFormat = undefined;
            this.list = undefined;
            this.ownerBase = undefined;
            this.baseStyle = undefined;
        };
        WListFormat.clear = function () {
            this.uniqueListFormats.clear();
        };
        WListFormat.prototype.applyStyle = function (baseStyle) {
            this.baseStyle = baseStyle;
        };
        WListFormat.prototype.getValue = function (property) {
            return this.hasValue(property) ? this.getPropertyValue(property) : undefined;
        };
        WListFormat.prototype.cloneListFormat = function () {
            var format = new WListFormat(undefined);
            format.list = this.list;
            format.listId = this.listId;
            format.nsid = this.nsid;
            format.baseStyle = this.baseStyle;
            format.listLevelNumber = this.listLevelNumber;
            format.uniqueListFormat = this.uniqueListFormat;
            return format;
        };
        WListFormat.uniqueListFormats = new unique_formats_1.WUniqueFormats();
        WListFormat.uniqueFormatType = 7;
        return WListFormat;
    }());
    exports.WListFormat = WListFormat;
});