placeholder.js
4.84 KB
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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var /** @type {?} */ TAG_TO_PLACEHOLDER_NAMES = {
'A': 'LINK',
'B': 'BOLD_TEXT',
'BR': 'LINE_BREAK',
'EM': 'EMPHASISED_TEXT',
'H1': 'HEADING_LEVEL1',
'H2': 'HEADING_LEVEL2',
'H3': 'HEADING_LEVEL3',
'H4': 'HEADING_LEVEL4',
'H5': 'HEADING_LEVEL5',
'H6': 'HEADING_LEVEL6',
'HR': 'HORIZONTAL_RULE',
'I': 'ITALIC_TEXT',
'LI': 'LIST_ITEM',
'LINK': 'MEDIA_LINK',
'OL': 'ORDERED_LIST',
'P': 'PARAGRAPH',
'Q': 'QUOTATION',
'S': 'STRIKETHROUGH_TEXT',
'SMALL': 'SMALL_TEXT',
'SUB': 'SUBSTRIPT',
'SUP': 'SUPERSCRIPT',
'TBODY': 'TABLE_BODY',
'TD': 'TABLE_CELL',
'TFOOT': 'TABLE_FOOTER',
'TH': 'TABLE_HEADER_CELL',
'THEAD': 'TABLE_HEADER',
'TR': 'TABLE_ROW',
'TT': 'MONOSPACED_TEXT',
'U': 'UNDERLINED_TEXT',
'UL': 'UNORDERED_LIST',
};
/**
* Creates unique names for placeholder with different content.
*
* Returns the same placeholder name when the content is identical.
*
* \@internal
*/
export var PlaceholderRegistry = (function () {
function PlaceholderRegistry() {
this._placeHolderNameCounts = {};
this._signatureToName = {};
}
/**
* @param {?} tag
* @param {?} attrs
* @param {?} isVoid
* @return {?}
*/
PlaceholderRegistry.prototype.getStartTagPlaceholderName = function (tag, attrs, isVoid) {
var /** @type {?} */ signature = this._hashTag(tag, attrs, isVoid);
if (this._signatureToName[signature]) {
return this._signatureToName[signature];
}
var /** @type {?} */ upperTag = tag.toUpperCase();
var /** @type {?} */ baseName = TAG_TO_PLACEHOLDER_NAMES[upperTag] || "TAG_" + upperTag;
var /** @type {?} */ name = this._generateUniqueName(isVoid ? baseName : "START_" + baseName);
this._signatureToName[signature] = name;
return name;
};
/**
* @param {?} tag
* @return {?}
*/
PlaceholderRegistry.prototype.getCloseTagPlaceholderName = function (tag) {
var /** @type {?} */ signature = this._hashClosingTag(tag);
if (this._signatureToName[signature]) {
return this._signatureToName[signature];
}
var /** @type {?} */ upperTag = tag.toUpperCase();
var /** @type {?} */ baseName = TAG_TO_PLACEHOLDER_NAMES[upperTag] || "TAG_" + upperTag;
var /** @type {?} */ name = this._generateUniqueName("CLOSE_" + baseName);
this._signatureToName[signature] = name;
return name;
};
/**
* @param {?} name
* @param {?} content
* @return {?}
*/
PlaceholderRegistry.prototype.getPlaceholderName = function (name, content) {
var /** @type {?} */ upperName = name.toUpperCase();
var /** @type {?} */ signature = "PH: " + upperName + "=" + content;
if (this._signatureToName[signature]) {
return this._signatureToName[signature];
}
var /** @type {?} */ uniqueName = this._generateUniqueName(upperName);
this._signatureToName[signature] = uniqueName;
return uniqueName;
};
/**
* @param {?} name
* @return {?}
*/
PlaceholderRegistry.prototype.getUniquePlaceholder = function (name) {
return this._generateUniqueName(name.toUpperCase());
};
/**
* @param {?} tag
* @param {?} attrs
* @param {?} isVoid
* @return {?}
*/
PlaceholderRegistry.prototype._hashTag = function (tag, attrs, isVoid) {
var /** @type {?} */ start = "<" + tag;
var /** @type {?} */ strAttrs = Object.keys(attrs).sort().map(function (name) { return (" " + name + "=" + attrs[name]); }).join('');
var /** @type {?} */ end = isVoid ? '/>' : "></" + tag + ">";
return start + strAttrs + end;
};
/**
* @param {?} tag
* @return {?}
*/
PlaceholderRegistry.prototype._hashClosingTag = function (tag) { return this._hashTag("/" + tag, {}, false); };
/**
* @param {?} base
* @return {?}
*/
PlaceholderRegistry.prototype._generateUniqueName = function (base) {
var /** @type {?} */ seen = this._placeHolderNameCounts.hasOwnProperty(base);
if (!seen) {
this._placeHolderNameCounts[base] = 1;
return base;
}
var /** @type {?} */ id = this._placeHolderNameCounts[base];
this._placeHolderNameCounts[base] = id + 1;
return base + "_" + id;
};
return PlaceholderRegistry;
}());
function PlaceholderRegistry_tsickle_Closure_declarations() {
/** @type {?} */
PlaceholderRegistry.prototype._placeHolderNameCounts;
/** @type {?} */
PlaceholderRegistry.prototype._signatureToName;
}
//# sourceMappingURL=placeholder.js.map