| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-21 13:36:42 -07:00
										 |  |  | import {BindingDef, BindingFlags, NodeDef, NodeFlags, TextData, ViewData, asTextData} from './types'; | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  | import {checkAndUpdateBinding, getParentRenderElement} from './util'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  | export function textDef(ngContentIndex: number, staticText: string[]): NodeDef { | 
					
						
							|  |  |  |   const bindings: BindingDef[] = new Array(staticText.length - 1); | 
					
						
							|  |  |  |   for (let i = 1; i < staticText.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     bindings[i - 1] = { | 
					
						
							| 
									
										
										
										
											2017-03-17 09:23:28 -07:00
										 |  |  |       flags: BindingFlags.TypeProperty, | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |       name: null, | 
					
						
							|  |  |  |       ns: null, | 
					
						
							|  |  |  |       nonMinifiedName: null, | 
					
						
							|  |  |  |       securityContext: null, | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  |       suffix: staticText[i], | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   return { | 
					
						
							|  |  |  |     // will bet set by the view definition
 | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |     index: -1, | 
					
						
							|  |  |  |     parent: null, | 
					
						
							|  |  |  |     renderParent: null, | 
					
						
							|  |  |  |     bindingIndex: -1, | 
					
						
							|  |  |  |     outputIndex: -1, | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     // regular values
 | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  |     flags: NodeFlags.TypeText, | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |     childFlags: 0, | 
					
						
							| 
									
										
										
										
											2017-02-27 13:00:49 -08:00
										 |  |  |     directChildFlags: 0, | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |     childMatchedQueries: 0, | 
					
						
							|  |  |  |     matchedQueries: {}, | 
					
						
							|  |  |  |     matchedQueryIds: 0, | 
					
						
							|  |  |  |     references: {}, ngContentIndex, | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     childCount: 0, bindings, | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  |     bindingFlags: BindingFlags.TypeProperty, | 
					
						
							| 
									
										
										
										
											2017-02-21 13:56:56 -08:00
										 |  |  |     outputs: [], | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |     element: null, | 
					
						
							|  |  |  |     provider: null, | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  |     text: {prefix: staticText[0]}, | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |     query: null, | 
					
						
							| 
									
										
										
										
											2017-08-16 16:29:39 -07:00
										 |  |  |     ngContent: null, | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 13:45:07 -08:00
										 |  |  | export function createText(view: ViewData, renderHost: any, def: NodeDef): TextData { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   let renderNode: any; | 
					
						
							| 
									
										
										
										
											2017-02-16 13:55:55 -08:00
										 |  |  |   const renderer = view.renderer; | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |   renderNode = renderer.createText(def.text !.prefix); | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |   const parentEl = getParentRenderElement(view, renderHost, def); | 
					
						
							|  |  |  |   if (parentEl) { | 
					
						
							|  |  |  |     renderer.appendChild(parentEl, renderNode); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-25 13:45:07 -08:00
										 |  |  |   return {renderText: renderNode}; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function checkAndUpdateTextInline( | 
					
						
							|  |  |  |     view: ViewData, def: NodeDef, v0: any, v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |     v7: any, v8: any, v9: any): boolean { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   let changed = false; | 
					
						
							| 
									
										
										
										
											2017-02-20 15:06:23 -08:00
										 |  |  |   const bindings = def.bindings; | 
					
						
							|  |  |  |   const bindLen = bindings.length; | 
					
						
							|  |  |  |   if (bindLen > 0 && checkAndUpdateBinding(view, def, 0, v0)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 1 && checkAndUpdateBinding(view, def, 1, v1)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 2 && checkAndUpdateBinding(view, def, 2, v2)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 3 && checkAndUpdateBinding(view, def, 3, v3)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 4 && checkAndUpdateBinding(view, def, 4, v4)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 5 && checkAndUpdateBinding(view, def, 5, v5)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 6 && checkAndUpdateBinding(view, def, 6, v6)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 7 && checkAndUpdateBinding(view, def, 7, v7)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 8 && checkAndUpdateBinding(view, def, 8, v8)) changed = true; | 
					
						
							|  |  |  |   if (bindLen > 9 && checkAndUpdateBinding(view, def, 9, v9)) changed = true; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (changed) { | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |     let value = def.text !.prefix; | 
					
						
							| 
									
										
										
										
											2017-02-20 15:06:23 -08:00
										 |  |  |     if (bindLen > 0) value += _addInterpolationPart(v0, bindings[0]); | 
					
						
							|  |  |  |     if (bindLen > 1) value += _addInterpolationPart(v1, bindings[1]); | 
					
						
							|  |  |  |     if (bindLen > 2) value += _addInterpolationPart(v2, bindings[2]); | 
					
						
							|  |  |  |     if (bindLen > 3) value += _addInterpolationPart(v3, bindings[3]); | 
					
						
							|  |  |  |     if (bindLen > 4) value += _addInterpolationPart(v4, bindings[4]); | 
					
						
							|  |  |  |     if (bindLen > 5) value += _addInterpolationPart(v5, bindings[5]); | 
					
						
							|  |  |  |     if (bindLen > 6) value += _addInterpolationPart(v6, bindings[6]); | 
					
						
							|  |  |  |     if (bindLen > 7) value += _addInterpolationPart(v7, bindings[7]); | 
					
						
							|  |  |  |     if (bindLen > 8) value += _addInterpolationPart(v8, bindings[8]); | 
					
						
							|  |  |  |     if (bindLen > 9) value += _addInterpolationPart(v9, bindings[9]); | 
					
						
							| 
									
										
										
										
											2017-01-25 13:45:07 -08:00
										 |  |  |     const renderNode = asTextData(view, def.index).renderText; | 
					
						
							| 
									
										
										
										
											2017-02-16 13:55:55 -08:00
										 |  |  |     view.renderer.setValue(renderNode, value); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |   return changed; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  | export function checkAndUpdateTextDynamic(view: ViewData, def: NodeDef, values: any[]): boolean { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   const bindings = def.bindings; | 
					
						
							| 
									
										
										
										
											2017-01-20 09:21:09 -08:00
										 |  |  |   let changed = false; | 
					
						
							|  |  |  |   for (let i = 0; i < values.length; i++) { | 
					
						
							|  |  |  |     // Note: We need to loop over all values, so that
 | 
					
						
							|  |  |  |     // the old values are updates as well!
 | 
					
						
							|  |  |  |     if (checkAndUpdateBinding(view, def, i, values[i])) { | 
					
						
							|  |  |  |       changed = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (changed) { | 
					
						
							|  |  |  |     let value = ''; | 
					
						
							|  |  |  |     for (let i = 0; i < values.length; i++) { | 
					
						
							|  |  |  |       value = value + _addInterpolationPart(values[i], bindings[i]); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |     value = def.text !.prefix + value; | 
					
						
							| 
									
										
										
										
											2017-01-25 13:45:07 -08:00
										 |  |  |     const renderNode = asTextData(view, def.index).renderText; | 
					
						
							| 
									
										
										
										
											2017-02-16 13:55:55 -08:00
										 |  |  |     view.renderer.setValue(renderNode, value); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |   return changed; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function _addInterpolationPart(value: any, binding: BindingDef): string { | 
					
						
							|  |  |  |   const valueStr = value != null ? value.toString() : ''; | 
					
						
							|  |  |  |   return valueStr + binding.suffix; | 
					
						
							|  |  |  | } |