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 | 1×
1×
1×
1×
1×
245×
245×
217×
217×
217×
217×
217×
217×
217×
217×
2170×
1085×
217×
245×
28×
28×
245×
1×
217×
651×
651×
4774×
651×
217×
1×
217×
217×
2170×
2170×
2170×
1085×
1×
217×
651×
651×
434×
434×
217×
1953×
1953×
1085×
1085×
1×
231×
14×
217×
217×
217×
217×
1×
231×
231×
235×
231×
1×
1×
78×
78×
78×
78×
78×
78×
702×
702×
1350×
1350×
648×
648×
78×
78×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1, ej2_base_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var StylesHelper = (function () {
function StylesHelper() {
}
StylesHelper.getStyleItems = function (documentEditor, localObj) {
var styles = [];
if (documentEditor && documentEditor.documentHelper && documentEditor.documentHelper.stylesMap) {
var stylesMap = documentEditor.documentHelper.stylesMap;
var defaultStyleNames = [
'Normal', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4',
'Title', 'Subtitle', 'Quote', 'Emphasis', 'Strong'
];
var paragraphStyles = stylesMap.get('Paragraph') || [];
var characterStyles = stylesMap.get('Character') || [];
var linkedStyles = stylesMap.get('Linked') || [];
var stylesMaps = StylesHelper.createStyleMaps(paragraphStyles, linkedStyles, characterStyles);
StylesHelper.addDefaultStyles(styles, defaultStyleNames, stylesMaps, localObj);
var addedStylesMap_1 = {};
defaultStyleNames.forEach(function (name) { if (localObj.getConstant(name) !== '')
addedStylesMap_1[localObj.getConstant(name)] = true; });
StylesHelper.addRemainingStyles(styles, paragraphStyles, linkedStyles, addedStylesMap_1);
}
if (styles.length === 0) {
styles.push({
content: localObj.getConstant('Normal'),
htmlAttributes: {
style: 'font-family: Calibri; font-size: 11pt;',
title: localObj.getConstant('Normal')
}
});
styles.push({
content: localObj.getConstant('Heading 1'),
htmlAttributes: {
style: 'font-family: "Calibri Light"; font-size: 16pt; color: #2F5496; font-weight: bold;',
title: localObj.getConstant('Heading 1')
}
});
}
return styles;
};
StylesHelper.createStyleMaps = function (paragraphStyles, linkedStyles, characterStyles) {
var createStyleMap = function (styles) {
var map = {};
for (var i = 0; i < styles.length; i++) {
map[styles[parseInt(i.toString(), 10)].StyleName] = styles[parseInt(i.toString(), 10)];
}
return map;
};
return {
paragraphStyleMap: createStyleMap(paragraphStyles),
linkedStyleMap: createStyleMap(linkedStyles),
characterStyleMap: createStyleMap(characterStyles)
};
};
StylesHelper.addDefaultStyles = function (styles, defaultStyleNames, stylesMaps, localObj) {
var paragraphStyleMap = stylesMaps.paragraphStyleMap, linkedStyleMap = stylesMaps.linkedStyleMap, characterStyleMap = stylesMaps.characterStyleMap;
for (var i = 0; i < defaultStyleNames.length; i++) {
var styleName = localObj.getConstant(defaultStyleNames[parseInt(i.toString(), 10)]);
var styleInfo = paragraphStyleMap[styleName] ||
linkedStyleMap[styleName] ||
characterStyleMap[styleName];
if (styleInfo) {
styles.push({
content: styleName,
htmlAttributes: {
style: styleInfo.Style,
title: styleName
}
});
}
}
};
StylesHelper.addRemainingStyles = function (styles, paragraphStyles, linkedStyles, addedStylesMap) {
for (var i = 0; i < paragraphStyles.length; i++) {
var style = paragraphStyles[parseInt(i.toString(), 10)];
if (!addedStylesMap[style.StyleName]) {
styles.push({
content: style.StyleName,
htmlAttributes: {
style: style.Style,
title: style.StyleName
}
});
addedStylesMap[style.StyleName] = true;
}
}
for (var i = 0; i < linkedStyles.length; i++) {
var style = linkedStyles[parseInt(i.toString(), 10)];
if (!addedStylesMap[style.StyleName]) {
styles.push({
content: style.StyleName,
htmlAttributes: {
style: style.Style,
title: style.StyleName
}
});
addedStylesMap[style.StyleName] = true;
}
}
};
StylesHelper.getCurrentStyleName = function (documentEditor, localObj) {
if (!documentEditor || !documentEditor.selection) {
return 'Normal';
}
var characterFormat = documentEditor.selection.characterFormat;
var paragraphFormat = documentEditor.selection.paragraphFormat;
Eif (paragraphFormat && paragraphFormat.styleName) {
return localObj.getConstant(paragraphFormat.styleName);
}
else if (characterFormat && characterFormat.styleName &&
characterFormat.styleName !== 'Default Paragraph Font') {
return localObj.getConstant(characterFormat.styleName);
}
return 'Normal';
};
StylesHelper.findStyleIndex = function (styleName, items) {
Iif (!items) {
return -1;
}
for (var i = 0; i < items.length; i++) {
if (items[parseInt(i.toString(), 10)] && items[parseInt(i.toString(), 10)].content === styleName) {
return i;
}
}
return -1;
};
StylesHelper.applyStyle = function (documentEditor, styleName) {
if (!documentEditor.isReadOnly && documentEditor.editorModule) {
documentEditor.editorModule.applyStyle(styleName, true);
}
};
StylesHelper.updateStyleNames = function (documentEditor, style, localObj) {
var styleName = !ej2_base_1.isNullOrUndefined(style.itemData) ? style.itemData.StyleName : undefined;
var stylesMap = documentEditor.documentHelper.stylesMap;
var paraStyles = stylesMap.get('Paragraph') ? stylesMap.get('Paragraph') : [];
var linkedStyles = stylesMap.get('Linked') ? stylesMap.get('Linked') : [];
var charStyles = stylesMap.get('Character') ? stylesMap.get('Character') : [];
for (var _i = 0, linkedStyles_1 = linkedStyles; _i < linkedStyles_1.length; _i++) {
var linkedStyle = linkedStyles_1[_i];
for (var i = 0; i < charStyles.length; i++) {
var charStyle = charStyles[parseInt(i.toString(), 10)];
if (linkedStyle['StyleName'] + ' Char' === charStyle['StyleName']) {
charStyles.splice(i, 1);
break;
}
}
}
style.dataSource = paraStyles.concat(linkedStyles, charStyles);
return styleName;
};
StylesHelper.applyStyleValue = function (documentEditor, args) {
if (!documentEditor.isReadOnly && documentEditor.editorModule) {
var styleName = documentEditor.stylesDialogModule.getStyleName(ej2_base_2.SanitizeHtmlHelper.sanitize(args.itemData.StyleName));
if (!ej2_base_1.isNullOrUndefined(documentEditor.documentHelper.styles.findByName(styleName))) {
documentEditor.editorModule.applyStyle(styleName, true);
var treeViewResult = document.getElementById(documentEditor.containerId + '_treeDiv');
if (!ej2_base_1.isNullOrUndefined(treeViewResult) &&
!ej2_base_1.isNullOrUndefined(documentEditor.optionsPaneModule) &&
documentEditor.optionsPaneModule.isOptionsPaneShow &&
documentEditor.optionsPaneModule.isHeadingTab) {
treeViewResult.innerHTML = '';
documentEditor.optionsPaneModule.data = documentEditor.optionsPaneModule.dataForTreeview();
documentEditor.optionsPaneModule.initHeadingTab();
}
}
}
};
return StylesHelper;
}());
exports.StylesHelper = StylesHelper;
});
|