@polymer/polymer
Advanced tools
Comparing version 3.0.0-pre.9 to 3.0.0-pre.10
@@ -1377,2 +1377,27 @@ /** | ||
*/ | ||
Polymer_ArraySelectorMixin.prototype.selectIndex = function(idx){}; | ||
Polymer_ArraySelectorMixin.prototype.selectIndex = function(idx){}; | ||
/** | ||
* @interface | ||
* @extends {Polymer_ElementMixin} | ||
*/ | ||
function Polymer_DisableUpgradeMixin(){} | ||
/** | ||
* @override | ||
*/ | ||
Polymer_DisableUpgradeMixin.prototype._initializeProperties = function(){}; | ||
/** | ||
* @override | ||
*/ | ||
Polymer_DisableUpgradeMixin.prototype._enableProperties = function(){}; | ||
/** | ||
* @override | ||
*/ | ||
Polymer_DisableUpgradeMixin.prototype.attributeChangedCallback = function(name, old, value){}; | ||
/** | ||
* @override | ||
*/ | ||
Polymer_DisableUpgradeMixin.prototype.connectedCallback = function(){}; | ||
/** | ||
* @override | ||
*/ | ||
Polymer_DisableUpgradeMixin.prototype.disconnectedCallback = function(){}; |
/** | ||
* @license | ||
* Copyright (c) 2017 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 | ||
* 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 | ||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
@@ -10,0 +10,0 @@ |
import { Element } from '../../polymer-element.js'; | ||
import { Templatize } from '../utils/templatize.js'; | ||
import { templatize } from '../utils/templatize.js'; | ||
import { Debouncer } from '../utils/debounce.js'; | ||
@@ -169,3 +169,3 @@ import { enqueueDebouncer, flush } from '../utils/flush.js'; | ||
if (!this.__ctor) { | ||
let template = this.querySelector('template'); | ||
let template = /** @type {HTMLTemplateElement} */(this.querySelector('template')); | ||
if (!template) { | ||
@@ -184,3 +184,3 @@ // Wait until childList changes and template should be there by then | ||
} | ||
this.__ctor = Templatize.templatize(template, this, { | ||
this.__ctor = templatize(template, this, { | ||
// dom-if templatizer instances require `mutable: true`, as | ||
@@ -187,0 +187,0 @@ // `__syncHostProperties` relies on that behavior to sync objects |
import { Element } from '../../polymer-element.js'; | ||
import { TemplateInstanceBase as TemplateInstanceBase$0, Templatize } from '../utils/templatize.js'; | ||
import { TemplateInstanceBase as TemplateInstanceBase$0, templatize, modelForElement as modelForElement$0 } from '../utils/templatize.js'; | ||
import { Debouncer } from '../utils/debounce.js'; | ||
@@ -326,3 +326,3 @@ import { enqueueDebouncer, flush } from '../utils/flush.js'; | ||
if (!this.__ctor) { | ||
let template = this.template = this.querySelector('template'); | ||
let template = this.template = /** @type {HTMLTemplateElement} */(this.querySelector('template')); | ||
if (!template) { | ||
@@ -346,3 +346,3 @@ // // Wait until childList changes and template should be there by then | ||
instanceProps[this.itemsIndexAs] = true; | ||
this.__ctor = Templatize.templatize(template, this, { | ||
this.__ctor = templatize(template, this, { | ||
mutableData: this.mutableData, | ||
@@ -715,3 +715,3 @@ parentModel: true, | ||
modelForElement(el) { | ||
return Templatize.modelForElement(this.template, el); | ||
return modelForElement$0(this.template, el); | ||
} | ||
@@ -718,0 +718,0 @@ |
@@ -50,3 +50,2 @@ import '../../../../@webcomponents/shadycss/entrypoints/apply-shim.js'; | ||
super(); | ||
this.root = this; | ||
/** @type {boolean} */ | ||
@@ -58,3 +57,2 @@ this.isAttached; | ||
this._debouncers; | ||
this.created(); | ||
// Ensure listeners are applied immediately so that they are | ||
@@ -153,2 +151,4 @@ // added before declarative event listeners. This allows an element to | ||
super._initializeProperties(); | ||
this.root = this; | ||
this.created(); | ||
} | ||
@@ -155,0 +155,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { TemplateInstanceBase as TemplateInstanceBase$0, Templatize } from '../utils/templatize.js'; | ||
import { TemplateInstanceBase as TemplateInstanceBase$0, templatize as templatize$0, modelForElement as modelForElement$0 } from '../utils/templatize.js'; | ||
@@ -34,3 +34,3 @@ let TemplateInstanceBase = TemplateInstanceBase$0; // eslint-disable-line | ||
this._templatizerTemplate = template; | ||
this.ctor = Templatize.templatize(template, this, { | ||
this.ctor = templatize$0(template, this, { | ||
mutableData: Boolean(mutableData), | ||
@@ -73,4 +73,4 @@ parentModel: this._parentModel, | ||
modelForElement(el) { | ||
return Templatize.modelForElement(this._templatizerTemplate, el); | ||
return modelForElement$0(this._templatizerTemplate, el); | ||
} | ||
}; |
@@ -53,4 +53,2 @@ import { dedupingMixin } from '../utils/mixin.js'; | ||
} | ||
/** @type {boolean} */ | ||
MutableData.prototype.mutableData = false; | ||
@@ -57,0 +55,0 @@ return MutableData; |
@@ -324,3 +324,3 @@ import '../utils/boot.js'; | ||
_shouldPropertiesChange(currentProps, changedProps, oldProps) { // eslint-disable-line no-unused-vars | ||
return changedProps; | ||
return Boolean(changedProps); | ||
} | ||
@@ -327,0 +327,0 @@ |
@@ -87,2 +87,50 @@ import './boot.js'; | ||
// keep track of any labels hit by the mouseCanceller | ||
/** @type {!Array<!HTMLLabelElement>} */ | ||
const clickedLabels = []; | ||
/** @type {!Object<boolean>} */ | ||
const labellable = { | ||
'button': true, | ||
'input': true, | ||
'keygen': true, | ||
'meter': true, | ||
'output': true, | ||
'textarea': true, | ||
'progress': true, | ||
'select': true | ||
}; | ||
/** | ||
* @param {HTMLElement} el Element to check labelling status | ||
* @return {boolean} element can have labels | ||
*/ | ||
function canBeLabelled(el) { | ||
return labellable[el.localName] || false; | ||
} | ||
/** | ||
* @param {HTMLElement} el Element that may be labelled. | ||
* @return {!Array<!HTMLLabelElement>} Relevant label for `el` | ||
*/ | ||
function matchingLabels(el) { | ||
let labels = [...(/** @type {HTMLInputElement} */((el).labels || []))]; | ||
// IE doesn't have `labels` and Safari doesn't populate `labels` | ||
// if element is in a shadowroot. | ||
// In this instance, finding the non-ancestor labels is enough, | ||
// as the mouseCancellor code will handle ancstor labels | ||
if (!labels.length) { | ||
labels = []; | ||
let root = el.getRootNode(); | ||
// if there is an id on `el`, check for all labels with a matching `for` attribute | ||
if (el.id) { | ||
let matching = root.querySelectorAll(`label[for = ${el.id}]`); | ||
for (let i = 0; i < matching.length; i++) { | ||
labels.push(/** @type {!HTMLLabelElement} */(matching[i])); | ||
} | ||
} | ||
} | ||
return labels; | ||
} | ||
// touch will make synthetic mouse events | ||
@@ -106,5 +154,17 @@ // `preventDefault` on touchend will cancel them, | ||
if (mouseEvent.type === 'click') { | ||
let clickFromLabel = false; | ||
let path = mouseEvent.composedPath && mouseEvent.composedPath(); | ||
if (path) { | ||
for (let i = 0; i < path.length; i++) { | ||
if (path[i].nodeType === Node.ELEMENT_NODE) { | ||
if (path[i].localName === 'label') { | ||
clickedLabels.push(path[i]); | ||
} else if (canBeLabelled(path[i])) { | ||
let ownerLabels = matchingLabels(path[i]); | ||
// check if one of the clicked labels is labelling this element | ||
for (let j = 0; j < ownerLabels.length; j++) { | ||
clickFromLabel = clickFromLabel || clickedLabels.indexOf(ownerLabels[j]) > -1; | ||
} | ||
} | ||
} | ||
if (path[i] === POINTERSTATE.mouse.target) { | ||
@@ -115,2 +175,7 @@ return; | ||
} | ||
// if one of the clicked labels was labelling the target element, | ||
// this is not a ghost click | ||
if (clickFromLabel) { | ||
return; | ||
} | ||
mouseEvent.preventDefault(); | ||
@@ -130,2 +195,4 @@ mouseEvent.stopPropagation(); | ||
if (setup) { | ||
// reset clickLabels array | ||
clickedLabels.length = 0; | ||
document.addEventListener(en, mouseCanceller, true); | ||
@@ -849,3 +916,3 @@ } else { | ||
let t = _findOriginalTarget((preventer || e)); | ||
if (!t) { | ||
if (!t || t.disabled) { | ||
return; | ||
@@ -852,0 +919,0 @@ } |
@@ -41,3 +41,9 @@ import { resolveCss } from './resolve-url.js'; | ||
const m = importModule(moduleId); | ||
if (m && m._styles === undefined) { | ||
if (!m) { | ||
console.warn('Could not find style data in module named', moduleId); | ||
return []; | ||
} | ||
if (m._styles === undefined) { | ||
const styles = []; | ||
@@ -52,8 +58,7 @@ // module imports: <link rel="import" type="css"> | ||
} | ||
m._styles = styles; | ||
} | ||
if (!m) { | ||
console.warn('Could not find style data in module named', moduleId); | ||
} | ||
return m ? m._styles : []; | ||
return m._styles; | ||
} | ||
@@ -60,0 +65,0 @@ |
@@ -235,4 +235,6 @@ import './boot.js'; | ||
* @param {Event} event Event to dispatch | ||
* @return {boolean} Always true. | ||
*/ | ||
dispatchEvent(event) { // eslint-disable-line no-unused-vars | ||
return true; | ||
} | ||
@@ -368,196 +370,53 @@ } | ||
/** | ||
* Module for preparing and stamping instances of templates that utilize | ||
* Polymer's data-binding and declarative event listener features. | ||
* | ||
* Example: | ||
* | ||
* // Get a template from somewhere, e.g. light DOM | ||
* let template = this.querySelector('template'); | ||
* // Prepare the template | ||
* let TemplateClass = Polymer.Templatize.templatize(template); | ||
* // Instance the template with an initial data model | ||
* let instance = new TemplateClass({myProp: 'initial'}); | ||
* // Insert the instance's DOM somewhere, e.g. element's shadow DOM | ||
* this.shadowRoot.appendChild(instance.root); | ||
* // Changing a property on the instance will propagate to bindings | ||
* // in the template | ||
* instance.myProp = 'new value'; | ||
* | ||
* The `options` dictionary passed to `templatize` allows for customizing | ||
* features of the generated template class, including how outer-scope host | ||
* properties should be forwarded into template instances, how any instance | ||
* properties added into the template's scope should be notified out to | ||
* the host, and whether the instance should be decorated as a "parent model" | ||
* of any event handlers. | ||
* | ||
* // Customize property forwarding and event model decoration | ||
* let TemplateClass = Polymer.Templatize.templatize(template, this, { | ||
* parentModel: true, | ||
* forwardHostProp(property, value) {...}, | ||
* instanceProps: {...}, | ||
* notifyInstanceProp(instance, property, value) {...}, | ||
* }); | ||
* | ||
* @namespace | ||
* @memberof Polymer | ||
* @summary Module for preparing and stamping instances of templates | ||
* utilizing Polymer templating features. | ||
*/ | ||
export function templatize(template, owner, options) { | ||
options = /** @type {!TemplatizeOptions} */(options || {}); | ||
if (template.__templatizeOwner) { | ||
throw new Error('A <template> can only be templatized once'); | ||
} | ||
template.__templatizeOwner = owner; | ||
const ctor = owner ? owner.constructor : TemplateInstanceBase; | ||
let templateInfo = ctor._parseTemplate(template); | ||
// Get memoized base class for the prototypical template, which | ||
// includes property effects for binding template & forwarding | ||
let baseClass = templateInfo.templatizeInstanceClass; | ||
if (!baseClass) { | ||
baseClass = createTemplatizerClass(template, templateInfo, options); | ||
templateInfo.templatizeInstanceClass = baseClass; | ||
} | ||
// Host property forwarding must be installed onto template instance | ||
addPropagateEffects(template, templateInfo, options); | ||
// Subclass base class and add reference for this specific template | ||
/** @private */ | ||
let klass = class TemplateInstance extends baseClass {}; | ||
klass.prototype._methodHost = findMethodHost(template); | ||
klass.prototype.__dataHost = template; | ||
klass.prototype.__templatizeOwner = owner; | ||
klass.prototype.__hostProps = templateInfo.hostProps; | ||
klass = /** @type {function(new:TemplateInstanceBase)} */(klass); //eslint-disable-line no-self-assign | ||
return klass; | ||
} | ||
const Templatize = { | ||
/** | ||
* Returns an anonymous `Polymer.PropertyEffects` class bound to the | ||
* `<template>` provided. Instancing the class will result in the | ||
* template being stamped into a document fragment stored as the instance's | ||
* `root` property, after which it can be appended to the DOM. | ||
* | ||
* Templates may utilize all Polymer data-binding features as well as | ||
* declarative event listeners. Event listeners and inline computing | ||
* functions in the template will be called on the host of the template. | ||
* | ||
* The constructor returned takes a single argument dictionary of initial | ||
* property values to propagate into template bindings. Additionally | ||
* host properties can be forwarded in, and instance properties can be | ||
* notified out by providing optional callbacks in the `options` dictionary. | ||
* | ||
* Valid configuration in `options` are as follows: | ||
* | ||
* - `forwardHostProp(property, value)`: Called when a property referenced | ||
* in the template changed on the template's host. As this library does | ||
* not retain references to templates instanced by the user, it is the | ||
* templatize owner's responsibility to forward host property changes into | ||
* user-stamped instances. The `instance.forwardHostProp(property, value)` | ||
* method on the generated class should be called to forward host | ||
* properties into the template to prevent unnecessary property-changed | ||
* notifications. Any properties referenced in the template that are not | ||
* defined in `instanceProps` will be notified up to the template's host | ||
* automatically. | ||
* - `instanceProps`: Dictionary of property names that will be added | ||
* to the instance by the templatize owner. These properties shadow any | ||
* host properties, and changes within the template to these properties | ||
* will result in `notifyInstanceProp` being called. | ||
* - `mutableData`: When `true`, the generated class will skip strict | ||
* dirty-checking for objects and arrays (always consider them to be | ||
* "dirty"). | ||
* - `notifyInstanceProp(instance, property, value)`: Called when | ||
* an instance property changes. Users may choose to call `notifyPath` | ||
* on e.g. the owner to notify the change. | ||
* - `parentModel`: When `true`, events handled by declarative event listeners | ||
* (`on-event="handler"`) will be decorated with a `model` property pointing | ||
* to the template instance that stamped it. It will also be returned | ||
* from `instance.parentModel` in cases where template instance nesting | ||
* causes an inner model to shadow an outer model. | ||
* | ||
* All callbacks are called bound to the `owner`. Any context | ||
* needed for the callbacks (such as references to `instances` stamped) | ||
* should be stored on the `owner` such that they can be retrieved via | ||
* `this`. | ||
* | ||
* When `options.forwardHostProp` is declared as an option, any properties | ||
* referenced in the template will be automatically forwarded from the host of | ||
* the `<template>` to instances, with the exception of any properties listed in | ||
* the `options.instanceProps` object. `instanceProps` are assumed to be | ||
* managed by the owner of the instances, either passed into the constructor | ||
* or set after the fact. Note, any properties passed into the constructor will | ||
* always be set to the instance (regardless of whether they would normally | ||
* be forwarded from the host). | ||
* | ||
* Note that `templatize()` can be run only once for a given `<template>`. | ||
* Further calls will result in an error. Also, there is a special | ||
* behavior if the template was duplicated through a mechanism such as | ||
* `<dom-repeat>` or `<test-fixture>`. In this case, all calls to | ||
* `templatize()` return the same class for all duplicates of a template. | ||
* The class returned from `templatize()` is generated only once using | ||
* the `options` from the first call. This means that any `options` | ||
* provided to subsequent calls will be ignored. Therefore, it is very | ||
* important not to close over any variables inside the callbacks. Also, | ||
* arrow functions must be avoided because they bind the outer `this`. | ||
* Inside the callbacks, any contextual information can be accessed | ||
* through `this`, which points to the `owner`. | ||
* | ||
* @memberof Polymer.Templatize | ||
* @param {!HTMLTemplateElement} template Template to templatize | ||
* @param {Polymer_PropertyEffects=} owner Owner of the template instances; | ||
* any optional callbacks will be bound to this owner. | ||
* @param {Object=} options Options dictionary (see summary for details) | ||
* @return {function(new:TemplateInstanceBase)} Generated class bound to the template | ||
* provided | ||
* @suppress {invalidCasts} | ||
*/ | ||
templatize(template, owner, options) { | ||
options = /** @type {!TemplatizeOptions} */(options || {}); | ||
if (template.__templatizeOwner) { | ||
throw new Error('A <template> can only be templatized once'); | ||
} | ||
template.__templatizeOwner = owner; | ||
const ctor = owner ? owner.constructor : TemplateInstanceBase; | ||
let templateInfo = ctor._parseTemplate(template); | ||
// Get memoized base class for the prototypical template, which | ||
// includes property effects for binding template & forwarding | ||
let baseClass = templateInfo.templatizeInstanceClass; | ||
if (!baseClass) { | ||
baseClass = createTemplatizerClass(template, templateInfo, options); | ||
templateInfo.templatizeInstanceClass = baseClass; | ||
} | ||
// Host property forwarding must be installed onto template instance | ||
addPropagateEffects(template, templateInfo, options); | ||
// Subclass base class and add reference for this specific template | ||
/** @private */ | ||
let klass = class TemplateInstance extends baseClass {}; | ||
klass.prototype._methodHost = findMethodHost(template); | ||
klass.prototype.__dataHost = template; | ||
klass.prototype.__templatizeOwner = owner; | ||
klass.prototype.__hostProps = templateInfo.hostProps; | ||
klass = /** @type {function(new:TemplateInstanceBase)} */(klass); //eslint-disable-line no-self-assign | ||
return klass; | ||
}, | ||
/** | ||
* Returns the template "model" associated with a given element, which | ||
* serves as the binding scope for the template instance the element is | ||
* contained in. A template model is an instance of | ||
* `TemplateInstanceBase`, and should be used to manipulate data | ||
* associated with this template instance. | ||
* | ||
* Example: | ||
* | ||
* let model = modelForElement(el); | ||
* if (model.index < 10) { | ||
* model.set('item.checked', true); | ||
* } | ||
* | ||
* @memberof Polymer.Templatize | ||
* @param {HTMLTemplateElement} template The model will be returned for | ||
* elements stamped from this template | ||
* @param {Node=} node Node for which to return a template model. | ||
* @return {TemplateInstanceBase} Template instance representing the | ||
* binding scope for the element | ||
*/ | ||
modelForElement(template, node) { | ||
let model; | ||
while (node) { | ||
// An element with a __templatizeInstance marks the top boundary | ||
// of a scope; walk up until we find one, and then ensure that | ||
// its __dataHost matches `this`, meaning this dom-repeat stamped it | ||
if ((model = node.__templatizeInstance)) { | ||
// Found an element stamped by another template; keep walking up | ||
// from its __dataHost | ||
if (model.__dataHost != template) { | ||
node = model.__dataHost; | ||
} else { | ||
return model; | ||
} | ||
export function modelForElement(template, node) { | ||
let model; | ||
while (node) { | ||
// An element with a __templatizeInstance marks the top boundary | ||
// of a scope; walk up until we find one, and then ensure that | ||
// its __dataHost matches `this`, meaning this dom-repeat stamped it | ||
if ((model = node.__templatizeInstance)) { | ||
// Found an element stamped by another template; keep walking up | ||
// from its __dataHost | ||
if (model.__dataHost != template) { | ||
node = model.__dataHost; | ||
} else { | ||
// Still in a template scope, keep going up until | ||
// a __templatizeInstance is found | ||
node = node.parentNode; | ||
return model; | ||
} | ||
} else { | ||
// Still in a template scope, keep going up until | ||
// a __templatizeInstance is found | ||
node = node.parentNode; | ||
} | ||
return null; | ||
} | ||
}; | ||
return null; | ||
} | ||
export { Templatize }; | ||
export { TemplateInstanceBase }; |
{ | ||
"name": "@polymer/polymer", | ||
"flat": true, | ||
"version": "3.0.0-pre.9", | ||
"version": "3.0.0-pre.10", | ||
"contributors": [ | ||
@@ -19,3 +19,3 @@ "The Polymer Authors (http://polymer.github.io/AUTHORS.txt)" | ||
"wct-browser-legacy": "0.0.1-pre.11", | ||
"@polymer/test-fixture": "^3.0.0-pre.8" | ||
"@polymer/test-fixture": "^3.0.0-pre.10" | ||
}, | ||
@@ -22,0 +22,0 @@ "resolutions": { |
/** | ||
* @license | ||
* Copyright (c) 2017 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 | ||
* 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 | ||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
@@ -10,0 +10,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1366967
68
12912