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

99.22% Statements 127/128
94.12% Branches 64/68
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 215   2845211× 2845211× 2845211× 2845211× 2845211×     249×     676×           277956×     720× 536× 488× 488× 67×       184×   720×           339047×     760×           146188× 146188× 143404×     2784× 2784× 3750× 2616× 2616×     1134×       146188× 146020×     168×           618172× 191191× 156010× 156010× 179742× 20965×     158777×     156010× 20965× 20965×         426981× 426981× 426981×     170226×   2156×   2156× 744×     1412× 1412×   49×   1363×     744× 744× 744× 744× 744×   2232× 2232× 744×     170227× 170227×   120306× 120306×   49754× 49754×   167× 167×   170227×   8438× 8438×   94× 94× 94×   8438× 7749×   8438× 42×       14382513× 755274× 755274×   13627239×   7837×     7837× 7837×   17756× 475×   17756× 17756× 17756× 17756×   13×   4550×   17190×   155× 155× 155× 155× 155× 155× 155× 155×        
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) || (!ej2_base_1.isNullOrUndefined(format.baseStyle) && !ej2_base_1.isNullOrUndefined(format.baseStyle.paragraphFormat.listFormat)
                    && !ej2_base_1.isNullOrUndefined(format.baseStyle.paragraphFormat.listFormat.uniqueListFormat) && ej2_base_1.isNullOrUndefined(format.list))) {
                    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;
});