Merge branch '2.0-scrub' into 2.0-styling-fallbacks

This commit is contained in:
Daniel Freedman 2017-02-14 23:02:11 -08:00
commit 2c9954f950
51 changed files with 551 additions and 746 deletions

View File

@ -1,2 +1,4 @@
<!DOCTYPE html> <link rel="import" href="src/mixins/element-mixin.html">
<link rel="import" href="src/elements/element.html"> <script>
Polymer.Element = Polymer.ElementMixin(HTMLElement);
</script>

View File

@ -1,4 +0,0 @@
<!DOCTYPE html>
<link rel="import" href="src/legacy/legacy-element.html">
<link rel="import" href="src/legacy/polymer-fn.html">
<link rel="import" href="src/legacy/class.html">

View File

@ -1,10 +1,16 @@
<!DOCTYPE html> <link rel="import" href="src/legacy/legacy-element-mixin.html">
<link rel="import" href="polymer-legacy.html"> <link rel="import" href="src/legacy/polymer-fn.html">
<link rel="import" href="src/legacy/class.html">
<!-- template elements --> <!-- template elements -->
<link rel="import" href="src/legacy/templatizer-behavior.html"> <link rel="import" href="src/legacy/templatizer-behavior.html">
<link rel="import" href="src/data-elements/dom-bind.html"> <link rel="import" href="src/elements/dom-bind.html">
<link rel="import" href="src/data-elements/dom-repeat.html"> <link rel="import" href="src/elements/dom-repeat.html">
<link rel="import" href="src/data-elements/dom-if.html"> <link rel="import" href="src/elements/dom-if.html">
<link rel="import" href="src/data-elements/array-selector.html"> <link rel="import" href="src/elements/array-selector.html">
<!-- custom-style --> <!-- custom-style -->
<link rel="import" href="src/styling/custom-style.html"> <link rel="import" href="src/elements/custom-style.html">
<script>
Polymer.LegacyElement = Polymer.LegacyElementMixin(HTMLElement);
// bc
Polymer.Base = Polymer.LegacyElement.prototype;
</script>

View File

@ -1,207 +0,0 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../utils/boot.html">
<link rel="import" href="../utils/utils.html">
<link rel="import" href="../utils/case-map.html">
<script>
(function() {
'use strict';
var caseMap = Polymer.CaseMap;
Polymer.Attributes = Polymer.Utils.dedupingMixin(function(superClass) {
/**
* @unrestricted
*/
class Attributes extends superClass {
constructor() {
super();
this.__serializing = false;
}
/**
* Ensures the element has the given attribute. If it does not,
* assigns the given value to the attribute.
*
*
* @method _ensureAttribute
* @param {string} attribute Name of attribute to ensure is set.
* @param {string} value of the attribute.
*/
_ensureAttribute(attribute, value) {
if (!this.hasAttribute(attribute)) {
this._valueToNodeAttribute(this, value, attribute);
}
}
/**
* Deserializes an attribute to its associated property.
*
* This method calls the `_deserializeAttribute` method to convert the string to
* a typed value.
*
* @method _attributeToProperty
* @param {string} attribute Name of attribute to deserialize.
* @param {string} value of the attribute.
* @param {*} type type to deserialize to.
*/
_attributeToProperty(attribute, value, type) {
// Don't deserialize back to property if currently reflecting
if (!this.__serializing) {
var property = caseMap.dashToCamelCase(attribute);
this[property] = this._deserializeAttribute(value, type);
}
}
/**
* Serializes a property to its associated attribute.
*
* @method _propertyToAttribute
* @param {string} property Property name to reflect.
* @param {string=} attribute Attribute name to reflect.
* @param {*=} value Property value to refect.
*/
_propertyToAttribute(property, attribute, value) {
this.__serializing = true;
value = (arguments.length < 3) ? this[property] : value;
this._valueToNodeAttribute(this, value,
attribute || caseMap.camelToDashCase(property));
this.__serializing = false;
}
/**
* Sets a typed value to an HTML attribute on a node.
*
* This method calls the `_serializeAttribute` method to convert the typed
* value to a string. If the `_serializeAttribute` method returns `undefined`,
* the attribute will be removed (this is the default for boolean
* type `false`).
*
* @method _valueToNodeAttribute
* @param {Element} node Element to set attribute to.
* @param {*} value Value to serialize.
* @param {string} attribute Attribute name to serialize to.
*/
_valueToNodeAttribute(node, value, attribute) {
var str = this._serializeAttribute(value);
if (str === undefined) {
node.removeAttribute(attribute);
} else {
node.setAttribute(attribute, str);
}
}
/**
* Converts a typed value to a string.
*
* This method is called by Polymer when setting JS property values to
* HTML attributes. Users may override this method on Polymer element
* prototypes to provide serialization for custom types.
*
* @method _serializeAttribute
* @param {*} value Property value to serialize.
* @return {string | undefined} String serialized from the provided property value.
*/
_serializeAttribute(value) {
/* eslint-disable no-fallthrough */
switch (typeof value) {
case 'boolean':
return value ? '' : undefined;
case 'object':
if (value instanceof Date) {
return value.toString();
} else if (value) {
try {
return JSON.stringify(value);
} catch(x) {
return '';
}
}
default:
return value != null ? value.toString() : undefined;
}
}
/**
* Converts a string to a typed value.
*
* This method is called by Polymer when reading HTML attribute values to
* JS properties. Users may override this method on Polymer element
* prototypes to provide deserialization for custom `type`s. Note,
* the `type` argument is the value of the `type` field provided in the
* `properties` configuration object for a given property, and is
* by convention the constructor for the type to deserialize.
*
* Note: The return value of `undefined` is used as a sentinel value to
* indicate the attribute should be removed.
*
* @method _deserializeAttribute
* @param {string} value Attribute value to deserialize.
* @param {*} type Type to deserialize the string to.
* @return {*} Typed value deserialized from the provided string.
*/
_deserializeAttribute(value, type) {
/**
* @type {*}
*/
let outValue;
switch (type) {
case Number:
outValue = Number(value);
break;
case Boolean:
outValue = (value !== null);
break;
case Object:
try {
outValue = JSON.parse(value);
} catch(x) {
// allow non-JSON literals like Strings and Numbers
}
break;
case Array:
try {
outValue = JSON.parse(value);
} catch(x) {
outValue = null;
console.warn('Polymer::Attributes: couldn`t decode Array as JSON');
}
break;
case Date:
outValue = new Date(value);
break;
case String:
default:
outValue = value;
break;
}
return outValue;
}
/* eslint-enable no-fallthrough */
}
return Attributes;
});
})();
</script>

View File

@ -63,8 +63,8 @@ is false, `selected` is a property representing the last selected item. When
--> -->
<link rel="import" href="../../polymer-element.html"> <link rel="import" href="../../polymer-element.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="../utils/array-splice.html"> <link rel="import" href="../lib/array-splice.html">
<script> <script>
(function() { (function() {
@ -283,7 +283,7 @@ is false, `selected` is a property representing the last selected item. When
_selectedIndexForItemIndex(idx) { _selectedIndexForItemIndex(idx) {
let selected = this.__dataLinkedPaths['items.' + idx]; let selected = this.__dataLinkedPaths['items.' + idx];
if (selected) { if (selected) {
return parseInt(selected.slice('selected.'.length), 10); return parseInt(selected.slice('selected.'.length), 10);
} }
} }

View File

@ -1,4 +1,3 @@
<!doctype html>
<!-- <!--
@license @license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
@ -9,15 +8,14 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../../../shadycss/custom-style-interface.html"> <link rel="import" href="../../../shadycss/custom-style-interface.html">
<link rel="import" href="../../../shadycss/element-style-interface.html"> <link rel="import" href="../lib/style-gather.html">
<link rel="import" href="style-gather.html">
<script> <script>
(function() { (function() {
'use strict'; 'use strict';
const attr = 'include'; const attr = 'include';
const CustomStyleInterface = window.CustomStyleInterface; const CustomStyleInterface = window.ShadyCSS.CustomStyleInterface;
class CustomStyle extends HTMLElement { class CustomStyle extends HTMLElement {
constructor() { constructor() {

View File

@ -8,11 +8,8 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../../src/properties/property-effects.html"> <link rel="import" href="../mixins/property-effects.html">
<link rel="import" href="../../src/attributes/attributes.html">
<link rel="import" href="../../src/template/template-stamp.html">
<link rel="import" href="../../src/events/gesture-event-listeners.html">
<script> <script>

View File

@ -9,9 +9,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
--> -->
<link rel="import" href="../../polymer-element.html"> <link rel="import" href="../../polymer-element.html">
<link rel="import" href="templatize.html"> <link rel="import" href="../lib/templatize.html">
<link rel="import" href="../utils/debounce.html"> <link rel="import" href="../lib/debounce.html">
<link rel="import" href="../utils/flush.html"> <link rel="import" href="../lib/flush.html">
<script> <script>

View File

@ -1,4 +1,5 @@
<link rel="import" href="../utils/boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../lib/resolve-url.html">
<script> <script>
(function() { (function() {
@ -41,18 +42,15 @@
} }
get assetpath() { get assetpath() {
let assetpath = this.__assetpath || this.getAttribute('assetpath'); let assetpath = this.__assetpath;
// Don't override existing assetpath. // Don't override existing assetpath.
if (assetpath) {} if (!assetpath) {
// Polyfilled import. // note: assetpath set via an attribute must be relative to this
else if (window.HTMLImports && !HTMLImports.useNative && // element's location.
HTMLImports.importForElement) { assetpath = this.getAttribute('assetpath') || '';
const imp = HTMLImports.importForElement(this); const root = window.HTMLImports && HTMLImports.importForElement ?
assetpath = imp ? imp.href : ''; HTMLImports.importForElement(this) || document : this.ownerDocument;
} assetpath = Polymer.ResolveUrl.resolveUrl(assetpath, root.baseURI);
// Native import.
else if (this.ownerDocument !== document && this.baseURI) {
assetpath = this.baseURI;
} }
// Memoize. // Memoize.
this.__assetpath = assetpath; this.__assetpath = assetpath;

View File

@ -99,9 +99,9 @@ Then the `observe` property should be configured as follows:
--> -->
<link rel="import" href="../../polymer-element.html"> <link rel="import" href="../../polymer-element.html">
<link rel="import" href="templatize.html"> <link rel="import" href="../lib/templatize.html">
<link rel="import" href="../utils/debounce.html"> <link rel="import" href="../lib/debounce.html">
<link rel="import" href="../utils/flush.html"> <link rel="import" href="../lib/flush.html">
<script> <script>
(function() { (function() {

View File

@ -1,55 +0,0 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../utils/boot.html">
<link rel="import" href="../utils/utils.html">
<script>
(function() {
'use strict';
function createNodeEventHandler(context, eventName, methodName) {
// Instances can optionally have a _methodHost which allows redirecting where
// to find methods. Currently used by `templatize`.
context = context._methodHost || context;
var handler = function(e) {
if (context[methodName]) {
context[methodName](e, e.detail);
} else {
console.warn('listener method `' + methodName + '` not defined');
}
};
return handler;
}
Polymer.EventListeners = Polymer.Utils.dedupingMixin(function(superClass) {
return class EventListeners extends superClass {
_addMethodEventListenerToNode(node, eventName, methodName, context) {
context = context || node;
var handler = createNodeEventHandler(context, eventName, methodName);
this._addEventListenerToNode(node, eventName, handler);
return handler;
}
_addEventListenerToNode(node, eventName, handler) {
node.addEventListener(eventName, handler);
}
_removeEventListenerFromNode(node, eventName, handler) {
node.removeEventListener(eventName, handler);
}
}
});
})();
</script>

View File

@ -7,8 +7,8 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="legacy-element.html"> <link rel="import" href="legacy-element-mixin.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/utils.html">
<script> <script>
(function() { (function() {

View File

@ -9,15 +9,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
--> -->
<link rel="import" href="../../../shadycss/apply-shim.html"> <link rel="import" href="../../../shadycss/apply-shim.html">
<link rel="import" href="../../../shadycss/element-style-interface.html"> <link rel="import" href="../mixins/element-mixin.html">
<link rel="import" href="../elements/element.html"> <link rel="import" href="../mixins/gesture-event-listeners.html">
<link rel="import" href="../styling/style-util.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="../events/gesture-event-listeners.html"> <link rel="import" href="../lib/async-render.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/unresolved.html">
<link rel="import" href="../utils/async-render.html"> <link rel="import" href="polymer.dom.html">
<link rel="import" href="../utils/polymer.dom.html">
<link rel="import" href="../utils/unresolved.html">
<link rel="import" href="../legacy/logging.html">
<script> <script>
(function() { (function() {
@ -25,12 +22,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'use strict'; 'use strict';
var utils = Polymer.Utils; var utils = Polymer.Utils;
var styleInterface = window.ElementStyleInterface; var styleInterface = window.ShadyCSS;
const hasColor = (window.chrome && !(/edge/i.test(navigator.userAgent))) || (/firefox/i.test(navigator.userAgent));
const prefix = hasColor ? ['%c[%s::%s]:', 'font-weight: bold; background-color:#EEEE00;'] : ['[%s::%s]:'];
Polymer.LegacyElementMixin = Polymer.Utils.dedupingMixin(function(base) { Polymer.LegacyElementMixin = Polymer.Utils.dedupingMixin(function(base) {
const mixin = Polymer.Logging( const mixin = Polymer.GestureEventListeners(Polymer.ElementMixin(base));
Polymer.GestureEventListeners(Polymer.ElementMixin(base)));
return class LegacyElement extends mixin { return class LegacyElement extends mixin {
@ -87,11 +86,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_applyListeners() {} _applyListeners() {}
serialize(value) { serialize(value) {
return this._serializeAttribute(value); return this._serializeValue(value);
} }
deserialize(value, type) { deserialize(value, type) {
return this._deserializeAttribute(value, type); return this._deserializeValue(value, type);
} }
reflectPropertyToAttribute(property, attribute, value) { reflectPropertyToAttribute(property, attribute, value) {
@ -715,13 +714,39 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return null; return null;
} }
// logging
_logger(level, args) {
// accept ['foo', 'bar'] and [['foo', 'bar']]
if (Array.isArray(args) && args.length === 1) {
args = args[0];
}
switch(level) {
case 'log':
case 'warn':
case 'error':
console[level](...args);
}
}
_log(...args) {
this._logger('log', args);
}
_warn(...args) {
this._logger('warn', args);
}
_error(...args) {
this._logger('error', args)
}
_logf(...args) {
return prefix.concat(this.is).concat(args);
}
} }
}); });
// bc
Polymer.LegacyElement = Polymer.LegacyElementMixin(HTMLElement);
Polymer.Base = Polymer.LegacyElement.prototype;
})(); })();
</script> </script>

View File

@ -1,46 +0,0 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../utils/utils.html">
<script>
(function() {
'use strict';
Polymer.Logging = Polymer.Utils.dedupingMixin(function(superClass) {
const hasColor = (window.chrome && !(/edge/i.test(navigator.userAgent))) || (/firefox/i.test(navigator.userAgent));
const prefix = hasColor ? ['%c[%s::%s]:', 'font-weight: bold; background-color:#EEEE00;'] : ['[%s::%s]:']
return class Logging extends superClass {
_logger(level, args) {
// accept ['foo', 'bar'] and [['foo', 'bar']]
if (Array.isArray(args) && args.length === 1) {
args = args[0];
}
switch(level) {
case 'log':
case 'warn':
case 'error':
console[level](...args);
}
}
_log(...args) {
this._logger('log', args);
}
_warn(...args) {
this._logger('warn', args);
}
_error(...args) {
this._logger('error', args)
}
_logf(...args) {
return prefix.concat(this.is).concat(args);
}
};
});
})();
</script>

View File

@ -7,11 +7,11 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="utils.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="array-splice.html"> <link rel="import" href="../lib/array-splice.html">
<link rel="import" href="async.html"> <link rel="import" href="../lib/async.html">
<link rel="import" href="flush.html"> <link rel="import" href="../lib/flush.html">
<script> <script>
(function() { (function() {

View File

@ -8,7 +8,7 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../data-elements/templatize.html"> <link rel="import" href="../lib/templatize.html">
<script> <script>
(function() { (function() {
@ -30,7 +30,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return Polymer.Templatize.modelForElement(this._templatizerTemplate, el); return Polymer.Templatize.modelForElement(this._templatizerTemplate, el);
} }
}; };
Polymer.Templatizer = Templatizer; Polymer.Templatizer = Templatizer;
})(); })();

View File

@ -7,8 +7,8 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/boot.html"> <link rel="import" href="boot.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="utils.html">
<link rel="import" href="async.html"> <link rel="import" href="async.html">
<script> <script>
@ -36,7 +36,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
setConfig(asyncModule, cb) { setConfig(asyncModule, cb) {
this._asyncModule = asyncModule; this._asyncModule = asyncModule;
this._callback = cb; this._callback = cb;
this._timer = this._asyncModule.run(this._callback); this._timer = this._asyncModule.run(this.flush);
}, },
/** /**

View File

@ -7,6 +7,8 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="boot.html">
<script> <script>
(function() { (function() {

View File

@ -1,4 +1,3 @@
<!doctype html>
<!-- <!--
@license @license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
@ -8,7 +7,7 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../template/resolve-url.html"> <link rel="import" href="resolve-url.html">
<script> <script>
(function() { (function() {
'use strict'; 'use strict';

View File

@ -8,11 +8,8 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/boot.html"> <link rel="import" href="boot.html">
<link rel="import" href="../../src/properties/property-effects.html"> <link rel="import" href="../mixins/property-effects.html">
<link rel="import" href="../../src/attributes/attributes.html">
<link rel="import" href="../../src/template/template-stamp.html">
<link rel="import" href="../../src/events/gesture-event-listeners.html">
<script> <script>
(function() { (function() {
@ -130,7 +127,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @override * @override
*/ */
_setUnmanagedPropertyToNode(node, prop, value) { _setUnmanagedPropertyToNode(node, prop, value) {
if (node.__hideTemplateChildren__ && if (node.__hideTemplateChildren__ &&
node.nodeType == Node.TEXT_NODE && prop == 'textContent') { node.nodeType == Node.TEXT_NODE && prop == 'textContent') {
node.__polymerTextContent__ = value; node.__polymerTextContent__ = value;
} else { } else {

View File

@ -8,14 +8,12 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../legacy/dom-module.html"> <link rel="import" href="../lib/case-map.html">
<link rel="import" href="../utils/case-map.html"> <link rel="import" href="../lib/style-gather.html">
<link rel="import" href="../events/event-listeners.html"> <link rel="import" href="../lib/resolve-url.html">
<link rel="import" href="../template/template-stamp.html"> <link rel="import" href="../elements/dom-module.html">
<link rel="import" href="../properties/property-effects.html"> <link rel="import" href="property-effects.html">
<link rel="import" href="../styling/style-gather.html">
<link rel="import" href="../../../shadycss/element-style-interface.html">
<script> <script>
(function() { (function() {
@ -23,7 +21,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'use strict'; 'use strict';
let caseMap = Polymer.CaseMap; let caseMap = Polymer.CaseMap;
let styleInterface = window.ElementStyleInterface; let styleInterface = window.ShadyCSS;
// Same as Polymer.Utils.mixin, but upgrades shorthand type // Same as Polymer.Utils.mixin, but upgrades shorthand type
// syntax to { type: Type } // syntax to { type: Type }
@ -399,12 +397,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {string} Rewritten URL relative to the import * @return {string} Rewritten URL relative to the import
*/ */
resolveUrl(url) { resolveUrl(url) {
var module = Polymer.DomModule.import(this.constructor.is); const module = Polymer.DomModule.import(this.constructor.is);
var root = ''; const root = module ? module.assetpath : document.baseURI;
if (module) {
root = Polymer.ResolveUrl.resolveUrl(
module.assetpath, module.ownerDocument.baseURI);
}
return Polymer.ResolveUrl.resolveUrl(url, root); return Polymer.ResolveUrl.resolveUrl(url, root);
} }
@ -457,8 +451,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
} }
}; };
Polymer.Element = Polymer.ElementMixin(HTMLElement);
Polymer.updateStyles = function(props) { Polymer.updateStyles = function(props) {
styleInterface.styleDocument(props); styleInterface.styleDocument(props);
}; };

View File

@ -7,11 +7,10 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/async.html"> <link rel="import" href="../lib/async.html">
<link rel="import" href="../utils/boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="../utils/debounce.html"> <link rel="import" href="../lib/debounce.html">
<link rel="import" href="event-listeners.html">
<script> <script>
(function() { (function() {
@ -732,17 +731,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.GestureEventListeners = Polymer.Utils.dedupingMixin(function(superClass) { Polymer.GestureEventListeners = Polymer.Utils.dedupingMixin(function(superClass) {
const mixin = Polymer.EventListeners(superClass); return class GestureEventListeners extends superClass {
return class GestureEventListeners extends mixin {
_addEventListenerToNode(node, eventName, handler) { _addEventListenerToNode(node, eventName, handler) {
if (!gestures.addListener(node, eventName, handler)) { if (!gestures.addListener(node, eventName, handler) &&
super._addEventListenerToNode) {
super._addEventListenerToNode(node, eventName, handler); super._addEventListenerToNode(node, eventName, handler);
} }
} }
_removeEventListenerFromNode(node, eventName, handler) { _removeEventListenerFromNode(node, eventName, handler) {
if (!gestures.removeListener(node, eventName, handler)) { if (!gestures.removeListener(node, eventName, handler) &&
super._removeEventListenerFromNode) {
super._removeEventListenerFromNode(node, eventName, handler); super._removeEventListenerFromNode(node, eventName, handler);
} }
} }

View File

@ -8,14 +8,20 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="../lib/case-map.html">
<link rel="import" href="../lib/async.html">
<script> <script>
(function() { (function() {
'use strict'; 'use strict';
var caseMap = Polymer.CaseMap;
var microtask = Polymer.Async.microTask;
// Save map of native properties; this forms a blacklist or properties // Save map of native properties; this forms a blacklist or properties
// that won't have their values "saved" by `saveAccessorValue`, since // that won't have their values "saved" by `saveAccessorValue`, since
// reading from an HTMLElement accessor from the context of a prototype throws // reading from an HTMLElement accessor from the context of a prototype throws
@ -68,27 +74,223 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return class PropertyAccessors extends superClass { return class PropertyAccessors extends superClass {
static createPropertiesForAttributes() {
let a$ = this.observedAttributes;
for (let i=0; i < a$.length; i++) {
this.prototype._createPropertyAccessor(caseMap.dashToCamelCase(a$[i]));
}
}
constructor() { constructor() {
super(); super();
this._initializeProperties(); this._initializeProperties();
} }
attributeChangedCallback(name, old, value) {
if (old !== value) {
this._attributeToProperty(name, value);
}
}
/** /**
* Initializes the local storage for property accessors. * Initializes the local storage for property accessors.
* *
* Override to initialize with e.g. default values by setting values into * Default initialization via initializing
* accessors. * local property & pending data storage with any accessor values saved
* in `__dataProto`. If instance properties had been set before the
* element upgraded and gained accessors on its prototype, these values
* are set into the prototype's accessors after being deleted from the
* instance.
* *
* @protected * @protected
*/ */
_initializeProperties() { _initializeProperties() {
this.__data = {}; this.__serializing = false;
this.__dataCounter = 0; this.__dataCounter = 0;
this.__dataInvalid = false;
// initialize data with prototype values saved when creating accessors
this.__data = {};
this.__dataPending = null; this.__dataPending = null;
this.__dataOld = null; this.__dataOld = null;
this.__dataInvalid = false; if (this.__dataProto) {
this._initializeProtoProperties(this.__dataProto);
}
} }
_initializeProtoProperties(props) {
for (let p in props) {
this._setProperty(p, props[p]);
}
}
/**
* Ensures the element has the given attribute. If it does not,
* assigns the given value to the attribute.
*
*
* @method _ensureAttribute
* @param {string} attribute Name of attribute to ensure is set.
* @param {string} value of the attribute.
*/
_ensureAttribute(attribute, value) {
if (!this.hasAttribute(attribute)) {
this._valueToNodeAttribute(this, value, attribute);
}
}
/**
* Deserializes an attribute to its associated property.
*
* This method calls the `_deserializeValue` method to convert the string to
* a typed value.
*
* @method _attributeToProperty
* @param {string} attribute Name of attribute to deserialize.
* @param {string} value of the attribute.
* @param {*} type type to deserialize to.
*/
_attributeToProperty(attribute, value, type) {
// Don't deserialize back to property if currently reflecting
if (!this.__serializing) {
var property = caseMap.dashToCamelCase(attribute);
this[property] = this._deserializeValue(value, type);
}
}
/**
* Serializes a property to its associated attribute.
*
* @method _propertyToAttribute
* @param {string} property Property name to reflect.
* @param {string=} attribute Attribute name to reflect.
* @param {*=} value Property value to refect.
*/
_propertyToAttribute(property, attribute, value) {
this.__serializing = true;
value = (arguments.length < 3) ? this[property] : value;
this._valueToNodeAttribute(this, value,
attribute || caseMap.camelToDashCase(property));
this.__serializing = false;
}
/**
* Sets a typed value to an HTML attribute on a node.
*
* This method calls the `_serializeValue` method to convert the typed
* value to a string. If the `_serializeValue` method returns `undefined`,
* the attribute will be removed (this is the default for boolean
* type `false`).
*
* @method _valueToNodeAttribute
* @param {Element} node Element to set attribute to.
* @param {*} value Value to serialize.
* @param {string} attribute Attribute name to serialize to.
*/
_valueToNodeAttribute(node, value, attribute) {
var str = this._serializeValue(value);
if (str === undefined) {
node.removeAttribute(attribute);
} else {
node.setAttribute(attribute, str);
}
}
/**
* Converts a typed value to a string.
*
* This method is called by Polymer when setting JS property values to
* HTML attributes. Users may override this method on Polymer element
* prototypes to provide serialization for custom types.
*
* @method _serializeValue
* @param {*} value Property value to serialize.
* @return {string | undefined} String serialized from the provided property value.
*/
_serializeValue(value) {
/* eslint-disable no-fallthrough */
switch (typeof value) {
case 'boolean':
return value ? '' : undefined;
case 'object':
if (value instanceof Date) {
return value.toString();
} else if (value) {
try {
return JSON.stringify(value);
} catch(x) {
return '';
}
}
default:
return value != null ? value.toString() : undefined;
}
}
/**
* Converts a string to a typed value.
*
* This method is called by Polymer when reading HTML attribute values to
* JS properties. Users may override this method on Polymer element
* prototypes to provide deserialization for custom `type`s. Note,
* the `type` argument is the value of the `type` field provided in the
* `properties` configuration object for a given property, and is
* by convention the constructor for the type to deserialize.
*
* Note: The return value of `undefined` is used as a sentinel value to
* indicate the attribute should be removed.
*
* @method _deserializeValue
* @param {string} value Attribute value to deserialize.
* @param {*} type Type to deserialize the string to.
* @return {*} Typed value deserialized from the provided string.
*/
_deserializeValue(value, type) {
/**
* @type {*}
*/
let outValue;
switch (type) {
case Number:
outValue = Number(value);
break;
case Boolean:
outValue = (value !== null);
break;
case Object:
try {
outValue = JSON.parse(value);
} catch(x) {
// allow non-JSON literals like Strings and Numbers
}
break;
case Array:
try {
outValue = JSON.parse(value);
} catch(x) {
outValue = null;
console.warn('Polymer::Attributes: couldn`t decode Array as JSON');
}
break;
case Date:
outValue = new Date(value);
break;
case String:
default:
outValue = value;
break;
}
return outValue;
}
/* eslint-enable no-fallthrough */
/** /**
* Creates a setter/getter pair for the named property with its own * Creates a setter/getter pair for the named property with its own
* local storage. The getter returns the value in the local storage, * local storage. The getter returns the value in the local storage,
@ -183,7 +385,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_invalidateProperties() { _invalidateProperties() {
if (!this.__dataInvalid) { if (!this.__dataInvalid) {
this.__dataInvalid = true; this.__dataInvalid = true;
Promise.resolve().then(() => { microtask.run(() => {
if (this.__dataInvalid) { if (this.__dataInvalid) {
this.__dataInvalid = false; this.__dataInvalid = false;
this._flushProperties(); this._flushProperties();

View File

@ -9,15 +9,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
--> -->
<link rel="import" href="../utils/boot.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="../utils/path.html"> <link rel="import" href="../lib/path.html">
<link rel="import" href="property-accessors.html">
<link rel="import" href="../attributes/attributes.html">
<!-- for notify, reflect --> <!-- for notify, reflect -->
<link rel="import" href="../utils/case-map.html"> <link rel="import" href="../lib/case-map.html">
<link rel="import" href="property-accessors.html">
<!-- for annotated effects --> <!-- for annotated effects -->
<link rel="import" href="../template/template-stamp.html"> <link rel="import" href="template-stamp.html">
<script> <script>
@ -151,7 +150,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* If no trigger is given, the path is deemed to match. * If no trigger is given, the path is deemed to match.
* *
* @param {string} path Path or property that changed * @param {string} path Path or property that changed
* @param {Object} trigger Descriptor * @param {Object} trigger Descriptor
* @return {boolean} Whether the path matched the trigger * @return {boolean} Whether the path matched the trigger
*/ */
function pathMatchesTrigger(path, trigger) { function pathMatchesTrigger(path, trigger) {
@ -1185,8 +1184,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.PropertyEffects = Polymer.Utils.dedupingMixin(function(superClass) { Polymer.PropertyEffects = Polymer.Utils.dedupingMixin(function(superClass) {
const mixin = Polymer.TemplateStamp( const mixin = Polymer.TemplateStamp(Polymer.PropertyAccessors(superClass));
Polymer.Attributes(Polymer.PropertyAccessors(superClass)));
/** /**
* @unrestricted * @unrestricted
@ -1197,8 +1195,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return TYPES; return TYPES;
} }
constructor() { _initializeProperties() {
super(); super._initializeProperties();
this._asyncEffects = false; this._asyncEffects = false;
this.__dataInitialized = false; this.__dataInitialized = false;
this.__dataPendingClients = null; this.__dataPendingClients = null;
@ -1209,29 +1207,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// May be set on instance prior to upgrade // May be set on instance prior to upgrade
this.__dataCompoundStorage = this.__dataCompoundStorage || null; this.__dataCompoundStorage = this.__dataCompoundStorage || null;
this.__dataHost = this.__dataHost || null; this.__dataHost = this.__dataHost || null;
}
/**
* Adds to default initialization in `PropertyAccessors` by initializing
* local property & pending data storage with any accessor values saved
* in `__dataProto`. If instance properties had been set before the
* element upgraded and gained accessors on its prototype, these values
* are set into the prototype's accessors after being deleted from the
* instance.
*
* @override
*/
_initializeProperties() {
super._initializeProperties();
this.__dataTemp = {}; this.__dataTemp = {};
// initialize data with prototype values saved when creating accessors
if (this.__dataProto) {
this.__data = Object.create(this.__dataProto);
this.__dataPending = Object.create(this.__dataProto);
this.__dataOld = {};
} else {
this.__dataPending = null;
}
// update instance properties // update instance properties
for (let p in this.__propertyEffects) { for (let p in this.__propertyEffects) {
if (this.hasOwnProperty(p)) { if (this.hasOwnProperty(p)) {
@ -1242,6 +1218,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
} }
} }
_initializeProtoProperties(props) {
this.__data = Object.create(props);
this.__dataPending = Object.create(props);
this.__dataOld = {};
}
// Prototype setup ---------------------------------------- // Prototype setup ----------------------------------------
/** /**
@ -1418,7 +1400,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
/** /**
* Applies a value to a non-Polymer element/node's property. * Applies a value to a non-Polymer element/node's property.
* *
* The implementation makes a best-effort at binding interop: * The implementation makes a best-effort at binding interop:
* Some native element properties have side-effects when * Some native element properties have side-effects when
* re-setting the same value (e.g. setting <input>.value resets the * re-setting the same value (e.g. setting <input>.value resets the
@ -1427,7 +1409,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* accept objects, we explicitly re-set object changes coming from the * accept objects, we explicitly re-set object changes coming from the
* Polymer world (which may include deep object changes without the * Polymer world (which may include deep object changes without the
* top reference changing), erring on the side of providing more * top reference changing), erring on the side of providing more
* information. * information.
* *
* Users may override this method to provide alternate approaches. * Users may override this method to provide alternate approaches.
* *

View File

@ -7,67 +7,114 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
Code distributed by Google as part of the polymer project is also Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
--> -->
<link rel="import" href="../utils/boot.html">
<link rel="import" href="../utils/utils.html"> <link rel="import" href="../lib/boot.html">
<link rel="import" href="../utils/case-map.html"> <link rel="import" href="../lib/utils.html">
<link rel="import" href="resolve-url.html">
<script> <script>
/**
* Scans a template to produce an annotation list that that associates
* metadata culled from markup with tree locations
* metadata and information to associate the metadata with nodes in an instance.
*
* Supported expressions include:
*
* Double-mustache annotations in text content. The annotation must be the only
* content in the tag, compound expressions are not supported.
*
* <[tag]>{{annotation}}<[tag]>
*
* Double-escaped annotations in an attribute, either {{}} or [[]].
*
* <[tag] someAttribute="{{annotation}}" another="[[annotation]]"><[tag]>
*
* `on-` style event declarations.
*
* <[tag] on-<event-name>="annotation"><[tag]>
*
* Note that the `annotations` feature does not implement any behaviors
* associated with these expressions, it only captures the data.
*
* Generated data-structure:
*
* [
* {
* id: '<id>',
* events: [
* {
* name: '<name>'
* value: '<annotation>'
* }, ...
* ],
* bindings: [
* {
* kind: ['text'|'attribute'],
* mode: ['{'|'['],
* name: '<name>'
* value: '<annotation>'
* }, ...
* ],
* // TODO(sjmiles): this is annotation-parent, not node-parent
* parent: <reference to parent annotation object>,
* index: <integer index in parent's childNodes collection>
* },
* ...
* ]
*
* @class Annotations feature
*/
(function() { (function() {
'use strict'; 'use strict';
/**
* Scans a template to produce an annotation object that stores expression
* metadata along with information to associate the metadata with nodes in an
* instance.
*
* Elements with `id` in the template are noted and marshaled into an
* the `$` hash in an instance.
*
* Example
*
* &lt;template>
* &lt;div id="foo">&lt;/div>
* &lt;/template>
* &lt;script>
* Polymer({
* task: function() {
* this.$.foo.style.color = 'red';
* }
* });
* &lt;/script>
*
* Other expressions that are noted include:
*
* Double-mustache annotations in text content. The annotation must be the only
* content in the tag, compound expressions are not (currently) supported.
*
* <[tag]>{{path.to.host.property}}<[tag]>
*
* Double-mustache annotations in an attribute.
*
* <[tag] someAttribute="{{path.to.host.property}}"><[tag]>
*
* Only immediate host properties can automatically trigger side-effects.
* Setting `host.path` in the example above triggers the binding, setting
* `host.path.to.host.property` does not.
*
* `on-` style event declarations.
*
* <[tag] on-<event-name>="{{hostMethodName}}"><[tag]>
*
* Note: **the `annotations` feature does not actually implement the behaviors
* associated with these expressions, it only captures the data**.
*
* Other optional features contain actual data implementations.
*
* @class standard feature: annotations
*/
/*
Scans a template to produce an annotation map that stores expression metadata
and information that associates the metadata to nodes in a template instance.
Supported annotations are:
* id attributes
* binding annotations in text nodes
* double-mustache expressions: {{expression}}
* double-bracket expressions: [[expression]]
* binding annotations in attributes
* attribute-bind expressions: name="{{expression}} || [[expression]]"
* property-bind expressions: name*="{{expression}} || [[expression]]"
* property-bind expressions: name:="expression"
* event annotations
* event delegation directives: on-<eventName>="expression"
Generated data-structure:
[
{
id: '<id>',
events: [
{
mode: ['auto'|''],
name: '<name>'
value: '<expression>'
}, ...
],
bindings: [
{
kind: ['text'|'attribute'|'property'],
mode: ['auto'|''],
name: '<name>'
value: '<expression>'
}, ...
],
// TODO(sjmiles): confusingly, this is annotation-parent, not node-parent
parent: <reference to parent annotation>,
index: <integer index in parent's childNodes collection>
},
...
]
TODO(sjmiles): this module should produce either syntactic metadata
(e.g. double-mustache, double-bracket, star-attr), or semantic metadata
(e.g. manual-bind, auto-bind, property-bind). Right now it's half and half.
*/
// null-array (shared empty array to avoid null-checks) // null-array (shared empty array to avoid null-checks)
const emptyArray = []; const emptyArray = [];
@ -388,9 +435,72 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.ResolveUrl.resolveAttrs(element, currentTemplate.ownerDocument); Polymer.ResolveUrl.resolveAttrs(element, currentTemplate.ownerDocument);
} }
Polymer.Annotations = Polymer.Utils.dedupingMixin(function(superClass) { // construct `$` map (from id annotations)
function applyIdToMap(inst, map, dom, note) {
if (note.id) {
map[note.id] = inst._findTemplateAnnotatedNode(dom, note);
}
}
return class Annotations extends superClass { // install event listeners (from event annotations)
function applyEventListener(inst, dom, note, host) {
if (note.events && note.events.length) {
var node = inst._findTemplateAnnotatedNode(dom, note);
for (var j=0, e$=note.events, e; (j<e$.length) && (e=e$[j]); j++) {
inst._addMethodEventListenerToNode(node, e.name, e.value, host);
}
}
}
// push configuration references at configure time
function applyTemplateContent(inst, dom, note) {
if (note.templateContent) {
var node = inst._findTemplateAnnotatedNode(dom, note);
node._content = note.templateContent;
}
}
function createNodeEventHandler(context, eventName, methodName) {
// Instances can optionally have a _methodHost which allows redirecting where
// to find methods. Currently used by `templatize`.
context = context._methodHost || context;
var handler = function(e) {
if (context[methodName]) {
context[methodName](e, e.detail);
} else {
console.warn('listener method `' + methodName + '` not defined');
}
};
return handler;
}
Polymer.TemplateStamp = Polymer.Utils.dedupingMixin(function(superClass) {
return class TemplateStamp extends superClass {
constructor() {
super();
this.$ = null;
}
_stampTemplate(template) {
// Polyfill support: bootstrap the template if it has not already been
if (template && !template.content &&
window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
HTMLTemplateElement.decorate(template);
}
var notes = this._parseTemplateAnnotations(template);
var dom = document.importNode(template._content || template.content, true);
// NOTE: ShadyDom optimization indicating there is an insertion point
dom.__noInsertionPoint = !notes._hasInsertionPoint;
this.$ = {};
for (var i=0, l=notes.length, note; (i<l) && (note=notes[i]); i++) {
applyIdToMap(this, this.$, dom, note);
applyTemplateContent(this, dom, note);
applyEventListener(this, dom, note, this);
}
return dom;
}
// preprocess-time // preprocess-time
@ -425,6 +535,21 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
} }
} }
_addMethodEventListenerToNode(node, eventName, methodName, context) {
context = context || node;
var handler = createNodeEventHandler(context, eventName, methodName);
this._addEventListenerToNode(node, eventName, handler);
return handler;
}
_addEventListenerToNode(node, eventName, handler) {
node.addEventListener(eventName, handler);
}
_removeEventListenerFromNode(node, eventName, handler) {
node.removeEventListener(eventName, handler);
}
} }
}); });

View File

@ -1,36 +0,0 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<script>
(function() {
'use strict';
let StyleUtil = {
isTargetedBuild(buildType) {
return (!window.ShadyDOM || !ShadyDOM.inUse) ?
buildType === 'shadow' : buildType === 'shady';
},
cssBuildTypeForModule(module) {
let dm = Polymer.DomModule.import(module);
if (dm) {
return this.getCssBuildType(dm);
}
},
getCssBuildType(element) {
return element.getAttribute('css-build');
}
};
Polymer.StyleUtil = StyleUtil;
})();
</script>

View File

@ -1,178 +0,0 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../utils/boot.html">
<link rel="import" href="../utils/utils.html">
<link rel="import" href="../events/event-listeners.html">
<link rel="import" href="annotations.html">
<script>
(function() {
'use strict';
/**
* Scans a template to produce an annotation object that stores expression
* metadata along with information to associate the metadata with nodes in an
* instance.
*
* Elements with `id` in the template are noted and marshaled into an
* the `$` hash in an instance.
*
* Example
*
* &lt;template>
* &lt;div id="foo">&lt;/div>
* &lt;/template>
* &lt;script>
* Polymer({
* task: function() {
* this.$.foo.style.color = 'red';
* }
* });
* &lt;/script>
*
* Other expressions that are noted include:
*
* Double-mustache annotations in text content. The annotation must be the only
* content in the tag, compound expressions are not (currently) supported.
*
* <[tag]>{{path.to.host.property}}<[tag]>
*
* Double-mustache annotations in an attribute.
*
* <[tag] someAttribute="{{path.to.host.property}}"><[tag]>
*
* Only immediate host properties can automatically trigger side-effects.
* Setting `host.path` in the example above triggers the binding, setting
* `host.path.to.host.property` does not.
*
* `on-` style event declarations.
*
* <[tag] on-<event-name>="{{hostMethodName}}"><[tag]>
*
* Note: **the `annotations` feature does not actually implement the behaviors
* associated with these expressions, it only captures the data**.
*
* Other optional features contain actual data implementations.
*
* @class standard feature: annotations
*/
/*
Scans a template to produce an annotation map that stores expression metadata
and information that associates the metadata to nodes in a template instance.
Supported annotations are:
* id attributes
* binding annotations in text nodes
* double-mustache expressions: {{expression}}
* double-bracket expressions: [[expression]]
* binding annotations in attributes
* attribute-bind expressions: name="{{expression}} || [[expression]]"
* property-bind expressions: name*="{{expression}} || [[expression]]"
* property-bind expressions: name:="expression"
* event annotations
* event delegation directives: on-<eventName>="expression"
Generated data-structure:
[
{
id: '<id>',
events: [
{
mode: ['auto'|''],
name: '<name>'
value: '<expression>'
}, ...
],
bindings: [
{
kind: ['text'|'attribute'|'property'],
mode: ['auto'|''],
name: '<name>'
value: '<expression>'
}, ...
],
// TODO(sjmiles): confusingly, this is annotation-parent, not node-parent
parent: <reference to parent annotation>,
index: <integer index in parent's childNodes collection>
},
...
]
TODO(sjmiles): this module should produce either syntactic metadata
(e.g. double-mustache, double-bracket, star-attr), or semantic metadata
(e.g. manual-bind, auto-bind, property-bind). Right now it's half and half.
*/
// construct `$` map (from id annotations)
function applyIdToMap(inst, map, dom, note) {
if (note.id) {
map[note.id] = inst._findTemplateAnnotatedNode(dom, note);
}
}
// install event listeners (from event annotations)
function applyEventListener(inst, dom, note, host) {
if (note.events && note.events.length) {
var node = inst._findTemplateAnnotatedNode(dom, note);
for (var j=0, e$=note.events, e; (j<e$.length) && (e=e$[j]); j++) {
inst._addMethodEventListenerToNode(node, e.name, e.value, host);
}
}
}
// push configuration references at configure time
function applyTemplateContent(inst, dom, note) {
if (note.templateContent) {
var node = inst._findTemplateAnnotatedNode(dom, note);
node._content = note.templateContent;
}
}
Polymer.TemplateStamp = Polymer.Utils.dedupingMixin(function(superClass) {
const mixin = Polymer.Annotations(Polymer.EventListeners(superClass));
return class TemplateStamp extends mixin {
constructor() {
super();
this.$ = null;
}
_stampTemplate(template) {
// Polyfill support: bootstrap the template if it has not already been
if (template && !template.content &&
window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
HTMLTemplateElement.decorate(template);
}
var notes = this._parseTemplateAnnotations(template);
var dom = document.importNode(template._content || template.content, true);
// NOTE: ShadyDom optimization indicating there is an insertion point
dom.__noInsertionPoint = !notes._hasInsertionPoint;
this.$ = {};
for (var i=0, l=notes.length, note; (i<l) && (note=notes[i]); i++) {
applyIdToMap(this, this.$, dom, note);
applyTemplateContent(this, dom, note);
applyEventListener(this, dom, note, this);
}
return dom;
}
}
});
})();
</script>

View File

@ -24,8 +24,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<script> <script>
var suites = [ var suites = [
'unit/bind.html', 'unit/property-effects.html',
'unit/notify-path.html', 'unit/path-effects.html',
'unit/shady.html', 'unit/shady.html',
'unit/shady-events.html', 'unit/shady-events.html',
'unit/shady-content.html', 'unit/shady-content.html',

View File

@ -13,7 +13,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<meta charset="utf-8"> <meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../src/utils/async.html"> <link rel="import" href="../../src/lib/async.html">
</head> </head>
<body> <body>

View File

@ -13,7 +13,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<meta charset="utf-8"> <meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../src/utils/case-map.html"> <link rel="import" href="../../src/lib/case-map.html">
</head> </head>
<body> <body>

View File

@ -299,12 +299,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
var xBar, xFoo, stylesBuilt; var xBar, xFoo, stylesBuilt;
suiteSetup(function() { suiteSetup(function() {
var customStyle = document.querySelector('style[is="custom-style"]');
stylesBuilt = Polymer.StyleUtil.getCssBuildType(customStyle);
xBar = document.querySelector('x-bar'); xBar = document.querySelector('x-bar');
xFoo = document.querySelector('x-foo'); xFoo = document.querySelector('x-foo');
}); });
test('root styles applied', function() { test('root styles applied', function() {

View File

@ -113,6 +113,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}); });
}); });
test('flush debouncer', function(done) {
var callback = sinon.spy();
var job = Polymer.Debouncer.debounce(null, Polymer.Async.microTask, callback);
setTimeout(function() {
job.flush();
assert.isTrue(callback.calledOnce, 'callback should be called once');
done();
});
});
test('different debouncers and multiple micro tasks', function(done) { test('different debouncers and multiple micro tasks', function(done) {
var callback = sinon.spy(); var callback = sinon.spy();
var job1 = Polymer.Debouncer.debounce(null, Polymer.Async.microTask, callback); var job1 = Polymer.Debouncer.debounce(null, Polymer.Async.microTask, callback);

View File

@ -15,7 +15,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html"> <link rel="import" href="../../polymer.html">
<link rel="import" href="dom-repeat-elements.html"> <link rel="import" href="dom-repeat-elements.html">
<link rel="import" href="../../src/utils/array-splice.html">
<style> <style>
/* makes painting faster when testing on IOS simulator */ /* makes painting faster when testing on IOS simulator */
x-repeat-chunked { x-repeat-chunked {

View File

@ -13,7 +13,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<meta charset="utf-8"> <meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../src/utils/utils.html"> <link rel="import" href="../../src/lib/utils.html">
<body> <body>
<x-test></x-test> <x-test></x-test>

View File

@ -36,7 +36,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
</dom-module> </dom-module>
<script> <script>
HTMLImports.whenReady(() => { HTMLImports.whenReady(() => {
class XMixin extends Polymer.Logging(Polymer.Element) { class XMixin extends Polymer.LegacyElement {
static get is() { return 'x-mixin' } static get is() { return 'x-mixin' }
static get config() { static get config() {
return { return {

View File

@ -14,7 +14,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html"> <link rel="import" href="../../polymer.html">
<link rel="import" href="notify-path-elements.html"> <link rel="import" href="path-effects-elements.html">
<body> <body>
<script> <script>
@ -957,7 +957,7 @@ suite('path API', function() {
}); });
suite('corner cases', function() { suite('corner cases', function() {
test('malformed observer has nice message on failure', function() { test('malformed observer has nice message on failure', function() {
var thrown = false; var thrown = false;
var verifyError = function(e) { var verifyError = function(e) {

View File

@ -13,7 +13,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<meta charset="utf-8"> <meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../src/utils/path.html"> <link rel="import" href="../../src/lib/path.html">
</head> </head>
<body> <body>

View File

@ -13,7 +13,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<meta charset="utf-8"> <meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer-legacy.html"> <link rel="import" href="../../polymer.html">
<body> <body>
<dom-module id="my-element"> <dom-module id="my-element">

View File

@ -14,7 +14,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script> <script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html"> <link rel="import" href="../../polymer.html">
<link rel="import" href="bind-elements.html"> <link rel="import" href="property-effects-elements.html">
<body> <body>
<dom-repeat id="class-repeat" items='["class1", "class2"]'> <dom-repeat id="class-repeat" items='["class1", "class2"]'>
<template> <template>

View File

@ -458,7 +458,7 @@ suite('scoped-styling-apply', function() {
var stylesBuilt; var stylesBuilt;
suiteSetup(function() { suiteSetup(function() {
stylesBuilt = Polymer.StyleUtil.cssBuildTypeForModule('x-scope'); stylesBuilt = false;
}); });
test('variable mixins calculated correctly and inherit', function() { test('variable mixins calculated correctly and inherit', function() {