Skip to content

Commit 0ca8407

Browse files
author
Steven Orvell
committed
Merge branch 'master' into behaviors-no-mixin
2 parents d57e05e + 5341dbd commit 0ca8407

File tree

6 files changed

+236
-7
lines changed

6 files changed

+236
-7
lines changed

externs/polymer-dom-api-externs.js

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/**
2+
* @externs
3+
* @fileoverview Externs for PolymerDomApi for backwards compatibility with
4+
* the Polymer 1 externs.
5+
*/
6+
7+
/**
8+
* A Polymer DOM API for manipulating DOM such that local DOM and light DOM
9+
* trees are properly maintained.
10+
*
11+
* This type exists only to provide compatibility between compiled hybrid
12+
* Polymer V1 and V2 code. Polymer V2 only code should simply use the DomApi
13+
* class type.
14+
*
15+
* @interface
16+
*/
17+
var PolymerDomApi = function() {};
18+
19+
/**
20+
* @param {?Node} node
21+
* @return {boolean}
22+
*/
23+
PolymerDomApi.prototype.deepContains = function(node) {};
24+
25+
/** @param {!Node} node */
26+
PolymerDomApi.prototype.appendChild = function(node) {};
27+
28+
/**
29+
* @param {!Node} oldNode
30+
* @param {!Node} newNode
31+
*/
32+
PolymerDomApi.prototype.replaceChild = function(oldNode, newNode) {};
33+
34+
/**
35+
* @param {!Node} node
36+
* @param {?Node} beforeNode
37+
*/
38+
PolymerDomApi.prototype.insertBefore = function(node, beforeNode) {};
39+
40+
/** @param {!Node} node */
41+
PolymerDomApi.prototype.removeChild = function(node) {};
42+
43+
/** @type {!Array<!HTMLElement>|!NodeList<!HTMLElement>} */
44+
PolymerDomApi.prototype.children;
45+
46+
/** @type {!Array<!Node>|!NodeList<!Node>} */
47+
PolymerDomApi.prototype.childNodes;
48+
49+
/** @type {?Node} */
50+
PolymerDomApi.prototype.parentNode;
51+
52+
/** @type {?Node} */
53+
PolymerDomApi.prototype.firstChild;
54+
55+
/** @type {?Node} */
56+
PolymerDomApi.prototype.lastChild;
57+
58+
/** @type {?HTMLElement} */
59+
PolymerDomApi.prototype.firstElementChild;
60+
61+
/** @type {?HTMLElement} */
62+
PolymerDomApi.prototype.lastElementChild;
63+
64+
/** @type {?Node} */
65+
PolymerDomApi.prototype.previousSibling;
66+
67+
/** @type {?Node} */
68+
PolymerDomApi.prototype.nextSibling;
69+
70+
/** @type {?HTMLElement} */
71+
PolymerDomApi.prototype.previousElementSibling;
72+
73+
/** @type {?HTMLElement} */
74+
PolymerDomApi.prototype.nextElementSibling;
75+
76+
/** @type {string} */
77+
PolymerDomApi.prototype.textContent;
78+
79+
/** @type {string} */
80+
PolymerDomApi.prototype.innerHTML;
81+
82+
/** @type {?HTMLElement} */
83+
PolymerDomApi.prototype.activeElement;
84+
85+
/**
86+
* @param {string} selector
87+
* @return {?Element}
88+
*/
89+
PolymerDomApi.prototype.querySelector = function(selector) {};
90+
91+
/**
92+
* @param {string} selector
93+
* @return {!Array<!Element>|!NodeList<!Element>}
94+
*/
95+
PolymerDomApi.prototype.querySelectorAll = function(selector) {};
96+
97+
/** @return {!Array<!Node>} */
98+
PolymerDomApi.prototype.getDistributedNodes = function() {};
99+
100+
/** @return {!Array<!Node>} */
101+
PolymerDomApi.prototype.getDestinationInsertionPoints = function() {};
102+
103+
/** @return {?Node} */
104+
PolymerDomApi.prototype.getOwnerRoot = function() {};
105+
106+
/**
107+
* @param {string} attribute
108+
* @param {string} value
109+
*/
110+
PolymerDomApi.prototype.setAttribute = function(attribute, value) {};
111+
112+
/** @param {string} attribute */
113+
PolymerDomApi.prototype.removeAttribute = function(attribute) {};
114+
115+
/**
116+
* @typedef {function(!PolymerDomApi.ObserveInfo)}
117+
*/
118+
PolymerDomApi.ObserveCallback;
119+
120+
/**
121+
* @typedef {{
122+
* target: !Node,
123+
* addedNodes: !Array<!Node>,
124+
* removedNodes: !Array<!Node>
125+
* }}
126+
*/
127+
PolymerDomApi.ObserveInfo;
128+
129+
/**
130+
* A virtual type for observer callback handles.
131+
*
132+
* @interface
133+
*/
134+
PolymerDomApi.ObserveHandle = function() {};
135+
136+
/**
137+
* @return {void}
138+
*/
139+
PolymerDomApi.ObserveHandle.prototype.disconnect = function() {};
140+
141+
/**
142+
* Notifies callers about changes to the element's effective child nodes,
143+
* the same list as returned by `getEffectiveChildNodes`.
144+
*
145+
* @param {!PolymerDomApi.ObserveCallback} callback The supplied callback
146+
* is called with an `info` argument which is an object that provides
147+
* the `target` on which the changes occurred, a list of any nodes
148+
* added in the `addedNodes` array, and nodes removed in the
149+
* `removedNodes` array.
150+
*
151+
* @return {!PolymerDomApi.ObserveHandle} Handle which is the argument to
152+
* `unobserveNodes`.
153+
*/
154+
PolymerDomApi.prototype.observeNodes = function(callback) {};
155+
156+
/**
157+
* Stops observing changes to the element's effective child nodes.
158+
*
159+
* @param {!PolymerDomApi.ObserveHandle} handle The handle for the
160+
* callback that should no longer receive notifications. This
161+
* handle is returned from `observeNodes`.
162+
*/
163+
PolymerDomApi.prototype.unobserveNodes = function(handle) {};
164+
165+
/** @type {?DOMTokenList} */
166+
PolymerDomApi.prototype.classList;
167+
168+
/**
169+
* @param {string} selector
170+
* @return {!Array<!HTMLElement>}
171+
*/
172+
PolymerDomApi.prototype.queryDistributedElements = function(selector) {};
173+
174+
/**
175+
* Returns a list of effective child nodes for this element.
176+
*
177+
* @return {!Array<!HTMLElement>}
178+
*/
179+
PolymerDomApi.prototype.getEffectiveChildNodes = function() {};

externs/polymer-iconset-externs.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @externs
3+
* @fileoverview Externs for Polymer.Iconset.
4+
*/
5+
6+
/**
7+
* The interface that iconsets should obey. Iconsets are registered by setting
8+
* their name in the IronMeta 'iconset' db, and a value of type Polymer.Iconset.
9+
*
10+
* Used by iron-icon but needs to live here since iron-icon, iron-iconset, etc don't
11+
* depend on each other at all and talk only through iron-meta.
12+
*
13+
* @interface
14+
*/
15+
Polymer.Iconset = function() {};
16+
17+
/**
18+
* Applies an icon to the given element as a css background image. This
19+
* method does not size the element, and it's usually necessary to set
20+
* the element's height and width so that the background image is visible.
21+
*
22+
* @param {Element} element The element to which the icon is applied.
23+
* @param {string} icon The name of the icon to apply.
24+
* @param {string=} theme (optional) The name or index of the icon to apply.
25+
* @param {number=} scale (optional, defaults to 1) Icon scaling factor.
26+
*/
27+
Polymer.Iconset.prototype.applyIcon = function(
28+
element, icon, theme, scale) {};
29+
30+
/**
31+
* Remove an icon from the given element by undoing the changes effected
32+
* by `applyIcon`.
33+
*
34+
* @param {Element} element The element from which the icon is removed.
35+
*/
36+
Polymer.Iconset.prototype.removeIcon = function(element) {};

gen-tsd.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"../shadycss/custom-style-interface.d.ts"
1313
],
1414
"renameTypes": {
15-
"Polymer_PropertyEffects": "PropertyEffects"
15+
"Polymer_PropertyEffects": "PropertyEffects",
16+
"PolymerDomApi": "DomApi",
17+
"PolymerDomApi.ObserveHandle": "FlattenedNodesObserver"
1618
},
1719
"autoImport": {
1820
"./interfaces": [

gulpfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const runClosureOnly = ({lintOnly}) => () => {
171171
'externs/webcomponents-externs.js',
172172
'externs/closure-types.js',
173173
'externs/polymer-externs.js',
174+
'externs/polymer-dom-api-externs.js',
174175
],
175176
extra_annotation_name: [
176177
'appliesMixin',

lib/legacy/polymer.dom.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const matchesSelector = function(node, selector) {
3939
/**
4040
* Node API wrapper class returned from `Polymer.dom.(target)` when
4141
* `target` is a `Node`.
42-
*
42+
* @implements {PolymerDomApi}
4343
*/
4444
export class DomApi {
4545

@@ -56,7 +56,8 @@ export class DomApi {
5656
*
5757
* @param {function(this:HTMLElement, { target: !HTMLElement, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Called when direct or distributed children
5858
* of this element changes
59-
* @return {!FlattenedNodesObserver} Observer instance
59+
* @return {!PolymerDomApi.ObserveHandle} Observer instance
60+
* @override
6061
*/
6162
observeNodes(callback) {
6263
return new FlattenedNodesObserver(
@@ -66,9 +67,10 @@ export class DomApi {
6667
/**
6768
* Disconnects an observer previously created via `observeNodes`
6869
*
69-
* @param {!FlattenedNodesObserver} observerHandle Observer instance
70+
* @param {!PolymerDomApi.ObserveHandle} observerHandle Observer instance
7071
* to disconnect.
7172
* @return {void}
73+
* @override
7274
*/
7375
unobserveNodes(observerHandle) {
7476
observerHandle.disconnect();
@@ -88,6 +90,7 @@ export class DomApi {
8890
* @param {Node} node Node to test
8991
* @return {boolean} Returns true if the given `node` is contained within
9092
* this element's light or shadow DOM.
93+
* @override
9194
*/
9295
deepContains(node) {
9396
if (this.node.contains(node)) {
@@ -110,6 +113,7 @@ export class DomApi {
110113
* exists. If the node is connected to a document this is either a
111114
* shadowRoot or the document; otherwise, it may be the node
112115
* itself or a node or document fragment containing it.
116+
* @override
113117
*/
114118
getOwnerRoot() {
115119
return this.node.getRootNode();
@@ -120,6 +124,7 @@ export class DomApi {
120124
* an empty array. It is equivalent to `<slot>.addignedNodes({flatten:true})`.
121125
*
122126
* @return {!Array<!Node>} Array of assigned nodes
127+
* @override
123128
*/
124129
getDistributedNodes() {
125130
return (this.node.localName === 'slot') ?
@@ -131,6 +136,7 @@ export class DomApi {
131136
* Returns an array of all slots this element was distributed to.
132137
*
133138
* @return {!Array<!HTMLSlotElement>} Description
139+
* @override
134140
*/
135141
getDestinationInsertionPoints() {
136142
let ip$ = [];
@@ -159,6 +165,7 @@ export class DomApi {
159165
/**
160166
* @return {!Array<!Node>} Returns a flattened list of all child nodes and
161167
* nodes assigned to child slots.
168+
* @override
162169
*/
163170
getEffectiveChildNodes() {
164171
return FlattenedNodesObserver.getFlattenedNodes(
@@ -171,6 +178,7 @@ export class DomApi {
171178
*
172179
* @param {string} selector Selector to filter nodes against
173180
* @return {!Array<!HTMLElement>} List of flattened child elements
181+
* @override
174182
*/
175183
queryDistributedElements(selector) {
176184
let c$ = this.getEffectiveChildNodes();
@@ -189,6 +197,7 @@ export class DomApi {
189197
* shadow root.
190198
*
191199
* @return {Node|undefined} Currently focused element
200+
* @override
192201
*/
193202
get activeElement() {
194203
let node = this.node;
@@ -401,14 +410,14 @@ forwardProperties(DomApi.prototype, [
401410
*/
402411
export const dom = function(obj) {
403412
obj = obj || document;
404-
if (!obj.__domApi) {
413+
if (!obj['__domApi']) {
405414
let helper;
406415
if (obj instanceof Event) {
407416
helper = new EventApi(obj);
408417
} else {
409418
helper = new DomApi(obj);
410419
}
411-
obj.__domApi = helper;
420+
obj['__domApi'] = helper;
412421
}
413-
return obj.__domApi;
422+
return obj['__domApi'];
414423
};

lib/utils/flattened-nodes-observer.js

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function isSlot(node) {
6262
*
6363
* @summary Class that listens for changes (additions or removals) to
6464
* "flattened nodes" on a given `node`.
65+
* @implements {PolymerDomApi.ObserveHandle}
6566
*/
6667
export class FlattenedNodesObserver {
6768

@@ -168,6 +169,7 @@ export class FlattenedNodesObserver {
168169
* the observer.
169170
*
170171
* @return {void}
172+
* @override
171173
*/
172174
disconnect() {
173175
if (isSlot(this._target)) {

0 commit comments

Comments
 (0)