| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Custom DOM elements. | 6 * Custom DOM elements. |
| 7 * | 7 * |
| 8 * This library provides access to the Polymer project's | 8 * This library provides access to the Polymer project's |
| 9 * [Custom Elements] | 9 * [Custom Elements] |
| 10 * (http://www.polymer-project.org/platform/custom-elements.html) | 10 * (http://www.polymer-project.org/platform/custom-elements.html) |
| 11 * API, which lets you define your own elements. With custom elements, you | 11 * API, which lets you define your own elements. With custom elements, you |
| 12 * associate code with custom tag names, and then use those custom tag names | 12 * associate code with custom tag names, and then use those custom tag names |
| 13 * as you would any standard tag. For more information, see the | 13 * as you would any standard tag. For more information, see the |
| 14 * [Polymer.dart homepage](https://www.dartlang.org/polymer-dart/) and its | 14 * [Polymer.dart homepage](https://www.dartlang.org/polymer-dart/) and its |
| 15 * [custom element example] | 15 * [custom element example] |
| 16 * (https://www.dartlang.org/polymer-dart/#custom-elements). | 16 * (https://www.dartlang.org/polymer-dart/#custom-elements). |
| 17 */ | 17 */ |
| 18 library custom_element; | 18 library custom_element; |
| 19 | 19 |
| 20 import 'dart:async'; | 20 import 'dart:async'; |
| 21 import 'dart:html'; | 21 import 'dart:html'; |
| 22 import 'package:mdv/mdv.dart' as mdv; | 22 import 'package:mdv/mdv.dart' as mdv; |
| 23 import 'package:meta/meta.dart'; | 23 import 'package:meta/meta.dart'; |
| 24 import 'src/custom_tag_name.dart'; | 24 import 'src/custom_tag_name.dart'; |
| 25 | 25 |
| 26 part 'src/attribute_map.dart'; |
| 27 |
| 26 // TODO(jmesserly): replace with a real custom element polyfill. | 28 // TODO(jmesserly): replace with a real custom element polyfill. |
| 27 // This is just something temporary. | 29 // This is just something temporary. |
| 28 /** | 30 /** |
| 29 * *Warning*: this implementation is a work in progress. It only implements | 31 * *Warning*: this implementation is a work in progress. It only implements |
| 30 * the specification partially. | 32 * the specification partially. |
| 31 * | 33 * |
| 32 * Registers a custom HTML element with [localName] and the associated | 34 * Registers a custom HTML element with [localName] and the associated |
| 33 * constructor. This will ensure the element is detected and | 35 * constructor. This will ensure the element is detected and |
| 34 * | 36 * |
| 35 * See the specification at: | 37 * See the specification at: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 * interface, it also provides lifecycle methods: | 110 * interface, it also provides lifecycle methods: |
| 109 * - [created] | 111 * - [created] |
| 110 * - [inserted] | 112 * - [inserted] |
| 111 * - [attributeChanged] | 113 * - [attributeChanged] |
| 112 * - [removed] | 114 * - [removed] |
| 113 */ | 115 */ |
| 114 class CustomElement implements Element { | 116 class CustomElement implements Element { |
| 115 /** The web component element wrapped by this class. */ | 117 /** The web component element wrapped by this class. */ |
| 116 Element _host; | 118 Element _host; |
| 117 List _shadowRoots; | 119 List _shadowRoots; |
| 120 _AttributeMap _attributes; |
| 118 | 121 |
| 119 /** | 122 /** |
| 120 * Shadow roots generated by dwc for each custom element, indexed by the | 123 * Shadow roots generated by dwc for each custom element, indexed by the |
| 121 * custom element tag name. | 124 * custom element tag name. |
| 122 */ | 125 */ |
| 123 Map<String, dynamic> _generatedRoots = {}; | 126 Map<String, dynamic> _generatedRoots = {}; |
| 124 | 127 |
| 125 /** | 128 /** |
| 126 * Temporary property until components extend [Element]. An element can | 129 * Temporary property until components extend [Element]. An element can |
| 127 * only be associated with one host, and it is an error to use a web component | 130 * only be associated with one host, and it is an error to use a web component |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 /** Invoked when this component gets inserted in the DOM tree. */ | 181 /** Invoked when this component gets inserted in the DOM tree. */ |
| 179 void inserted() {} | 182 void inserted() {} |
| 180 @deprecated | 183 @deprecated |
| 181 void enteredView() {} | 184 void enteredView() {} |
| 182 | 185 |
| 183 /** Invoked when this component is removed from the DOM tree. */ | 186 /** Invoked when this component is removed from the DOM tree. */ |
| 184 void removed() {} | 187 void removed() {} |
| 185 @deprecated | 188 @deprecated |
| 186 void leftView() {} | 189 void leftView() {} |
| 187 | 190 |
| 188 // TODO(jmesserly): how do we implement this efficiently? | |
| 189 // See https://github.com/dart-lang/web-ui/issues/37 | |
| 190 /** Invoked when any attribute of the component is modified. */ | 191 /** Invoked when any attribute of the component is modified. */ |
| 191 void attributeChanged(String name, String oldValue, String newValue) {} | 192 void attributeChanged(String name, String oldValue) {} |
| 192 | 193 |
| 193 get model => host.model; | 194 get model => host.model; |
| 194 | 195 |
| 195 void set model(newModel) { | 196 void set model(newModel) { |
| 196 host.model = newModel; | 197 host.model = newModel; |
| 197 } | 198 } |
| 198 | 199 |
| 199 get templateInstance => host.templateInstance; | 200 get templateInstance => host.templateInstance; |
| 200 get isTemplate => host.isTemplate; | 201 get isTemplate => host.isTemplate; |
| 201 get ref => host.ref; | 202 get ref => host.ref; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 bool contains(Node other) => host.contains(other); | 269 bool contains(Node other) => host.contains(other); |
| 269 | 270 |
| 270 bool hasChildNodes() => host.hasChildNodes(); | 271 bool hasChildNodes() => host.hasChildNodes(); |
| 271 | 272 |
| 272 Node insertBefore(Node newChild, Node refChild) => | 273 Node insertBefore(Node newChild, Node refChild) => |
| 273 host.insertBefore(newChild, refChild); | 274 host.insertBefore(newChild, refChild); |
| 274 | 275 |
| 275 Node insertAllBefore(Iterable<Node> newChild, Node refChild) => | 276 Node insertAllBefore(Iterable<Node> newChild, Node refChild) => |
| 276 host.insertAllBefore(newChild, refChild); | 277 host.insertAllBefore(newChild, refChild); |
| 277 | 278 |
| 278 Map<String, String> get attributes => host.attributes; | 279 Map<String, String> get attributes { |
| 280 if (_attributes == null) _attributes = new _AttributeMap(this); |
| 281 return _attributes; |
| 282 } |
| 279 set attributes(Map<String, String> value) { | 283 set attributes(Map<String, String> value) { |
| 280 host.attributes = value; | 284 (attributes as _AttributeMap)._replaceAll(value); |
| 281 } | 285 } |
| 282 | 286 |
| 283 List<Element> get elements => host.children; | 287 List<Element> get elements => host.children; |
| 284 | 288 |
| 285 set elements(List<Element> value) { | 289 set elements(List<Element> value) { |
| 286 host.children = value; | 290 host.children = value; |
| 287 } | 291 } |
| 288 | 292 |
| 289 List<Element> get children => host.children; | 293 List<Element> get children => host.children; |
| 290 | 294 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 312 => host.getComputedStyle(pseudoElement); | 316 => host.getComputedStyle(pseudoElement); |
| 313 | 317 |
| 314 Element clone(bool deep) => host.clone(deep); | 318 Element clone(bool deep) => host.clone(deep); |
| 315 | 319 |
| 316 Element get parent => host.parent; | 320 Element get parent => host.parent; |
| 317 | 321 |
| 318 Node get parentNode => host.parentNode; | 322 Node get parentNode => host.parentNode; |
| 319 | 323 |
| 320 String get nodeValue => host.nodeValue; | 324 String get nodeValue => host.nodeValue; |
| 321 | 325 |
| 322 @deprecated | 326 Events get on => host.on; |
| 323 // TODO(sigmund): restore the old return type and call host.on when | |
| 324 // dartbug.com/8131 is fixed. | |
| 325 dynamic get on { throw new UnsupportedError('on is deprecated'); } | |
| 326 | 327 |
| 327 String get contentEditable => host.contentEditable; | 328 String get contentEditable => host.contentEditable; |
| 328 set contentEditable(String v) { host.contentEditable = v; } | 329 set contentEditable(String v) { host.contentEditable = v; } |
| 329 | 330 |
| 330 String get dir => host.dir; | 331 String get dir => host.dir; |
| 331 set dir(String v) { host.dir = v; } | 332 set dir(String v) { host.dir = v; } |
| 332 | 333 |
| 333 bool get draggable => host.draggable; | 334 bool get draggable => host.draggable; |
| 334 set draggable(bool v) { host.draggable = v; } | 335 set draggable(bool v) { host.draggable = v; } |
| 335 | 336 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 for (var removed in record.removedNodes) { | 647 for (var removed in record.removedNodes) { |
| 647 if (identical(node, removed)) { | 648 if (identical(node, removed)) { |
| 648 observer.disconnect(); | 649 observer.disconnect(); |
| 649 element.removed(); | 650 element.removed(); |
| 650 return; | 651 return; |
| 651 } | 652 } |
| 652 } | 653 } |
| 653 } | 654 } |
| 654 }).observe(element.parentNode, childList: true); | 655 }).observe(element.parentNode, childList: true); |
| 655 } | 656 } |
| OLD | NEW |