Skip to content

Commit 8901f20

Browse files
committed
Release 1.0.0
1 parent 692cefc commit 8901f20

File tree

3 files changed

+295
-0
lines changed

3 files changed

+295
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* DO NOT EDIT
3+
*
4+
* This file was automatically generated by
5+
* https://github.com/Polymer/gen-typescript-declarations
6+
*
7+
* To modify these typings, edit the source file(s):
8+
* mixins/declarative-event-listeners.html
9+
*/
10+
11+
declare namespace Polymer {
12+
13+
14+
/**
15+
* Element class mixin that provides API for adding declarative event
16+
* listeners nodes.
17+
*
18+
* The API is designed to be compatible with override points implemented
19+
* in `Polymer.TemplateStamp` such that declarative event listeners in
20+
* templates will support gesture events when this mixin is applied along with
21+
* `Polymer.TemplateStamp`.
22+
*/
23+
function DeclarativeEventListeners<T extends new (...args: any[]) => {}>(base: T): T & DeclarativeEventListenersConstructor;
24+
25+
interface DeclarativeEventListenersConstructor {
26+
new(...args: any[]): DeclarativeEventListeners;
27+
}
28+
29+
interface DeclarativeEventListeners {
30+
ready(): any;
31+
}
32+
}

polymer-decorators.d.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// DO NOT EDIT
2+
// This file is automatically generated by `npm run build`.
3+
4+
declare namespace Polymer {
5+
namespace decorators {
6+
/**
7+
* @license
8+
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
9+
* This code may only be used under the BSD style license found at
10+
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
11+
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
12+
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
13+
* Google as part of the polymer project is also subject to an additional IP
14+
* rights grant found at http://polymer.github.io/PATENTS.txt
15+
*/
16+
/**
17+
* A TypeScript class decorator factory that defines a custom element with name
18+
* `tagname` and the decorated class. If `tagname` is not provided, the static
19+
* `is` property of the class is used.
20+
*/
21+
function customElement(tagname?: string): (clazz: any) => void;
22+
/**
23+
* Options for the @property decorator.
24+
* See https://www.polymer-project.org/2.0/docs/devguide/properties.
25+
*/
26+
interface PropertyOptions {
27+
/**
28+
* This field can be omitted if the Metadata Reflection API is configured.
29+
*/
30+
type?: BooleanConstructor | DateConstructor | NumberConstructor | StringConstructor | ArrayConstructor | ObjectConstructor;
31+
notify?: boolean;
32+
reflectToAttribute?: boolean;
33+
readOnly?: boolean;
34+
computed?: string;
35+
observer?: string | ((val: any, old: any) => void);
36+
}
37+
/**
38+
* A TypeScript property decorator factory that defines this as a Polymer
39+
* property.
40+
*
41+
* This function must be invoked to return a decorator.
42+
*/
43+
function property(options?: PropertyOptions): (proto: any, propName: string) => any;
44+
/**
45+
* A TypeScript property decorator factory that causes the decorated method to
46+
* be called when a property changes.
47+
*
48+
* This function must be invoked to return a decorator.
49+
*/
50+
function observe(...targets: string[]): (proto: any, propName: string) => any;
51+
/**
52+
* A TypeScript accessor decorator factory that causes the decorated getter to
53+
* be called when a set of dependencies change. The arguments of this decorator
54+
* should be paths of the data dependencies as described
55+
* [here](https://www.polymer-project.org/2.0/docs/devguide/observers#define-a-computed-property)
56+
* The decorated getter should not have an associated setter.
57+
*
58+
* This function must be invoked to return a decorator.
59+
*/
60+
function computed<T = any>(...targets: (keyof T)[]): (proto: any, propName: string, descriptor: PropertyDescriptor) => void;
61+
/**
62+
* A TypeScript property decorator factory that converts a class property into
63+
* a getter that executes a querySelector on the element's shadow root.
64+
*
65+
* By annotating the property with the correct type, element's can have
66+
* type-checked access to internal elements.
67+
*
68+
* This function must be invoked to return a decorator.
69+
*/
70+
const query: (selector: string) => (proto: any, propName: string) => any;
71+
/**
72+
* A TypeScript property decorator factory that converts a class property into
73+
* a getter that executes a querySelectorAll on the element's shadow root.
74+
*
75+
* By annotating the property with the correct type, element's can have
76+
* type-checked access to internal elements. The type should be NodeList
77+
* with the correct type argument.
78+
*
79+
* This function must be invoked to return a decorator.
80+
*/
81+
const queryAll: (selector: string) => (proto: any, propName: string) => any;
82+
/**
83+
* A TypeScript property decorator factory that causes the decorated method to
84+
* be called when a imperative event is fired on the targeted element. `target`
85+
* can be either a single element by id or element.
86+
*
87+
* You must apply the supplied DeclarativeEventListeners mixin to your element
88+
* class for this decorator to function.
89+
*
90+
* https://www.polymer-project.org/2.0/docs/devguide/events#imperative-listeners
91+
*
92+
* @param eventName A string representing the event type to listen for
93+
* @param target A single element by id or EventTarget to target
94+
*/
95+
const listen: (eventName: string, target: string | EventTarget) => (proto: any, methodName: string) => void;
96+
97+
}
98+
}

polymer-decorators.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
this.Polymer = this.Polymer || {};
2+
this.Polymer.decorators = (function (exports) {
3+
'use strict';
4+
5+
/**
6+
* @license
7+
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
8+
* This code may only be used under the BSD style license found at
9+
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
10+
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
11+
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
12+
* Google as part of the polymer project is also subject to an additional IP
13+
* rights grant found at http://polymer.github.io/PATENTS.txt
14+
*/
15+
/// <reference types="reflect-metadata" />
16+
/**
17+
* A TypeScript class decorator factory that defines a custom element with name
18+
* `tagname` and the decorated class. If `tagname` is not provided, the static
19+
* `is` property of the class is used.
20+
*/
21+
function customElement(tagname) {
22+
// TODO Investigate narrowing down the type of clazz.
23+
return (clazz) => {
24+
// TODO(justinfagnani): we could also use the kebab-cased class name
25+
if (clazz.is) {
26+
tagname = clazz.is;
27+
}
28+
else {
29+
clazz.is = tagname;
30+
}
31+
window.customElements.define(tagname, clazz);
32+
};
33+
}
34+
function createProperty(proto, name, options) {
35+
const notify = options && options.notify || false;
36+
const reflectToAttribute = options && options.reflectToAttribute || false;
37+
const readOnly = options && options.readOnly || false;
38+
const computed = options && options.computed || '';
39+
const observer = options && options.observer || '';
40+
let type;
41+
if (options && options.hasOwnProperty('type')) {
42+
type = options.type;
43+
}
44+
else if (window.Reflect && Reflect.hasMetadata && Reflect.getMetadata &&
45+
Reflect.hasMetadata('design:type', proto, name)) {
46+
type = Reflect.getMetadata('design:type', proto, name);
47+
}
48+
else {
49+
console.error('A type could not be found for ${propName}. ' +
50+
'Set a type or configure Metadata Reflection API support.');
51+
}
52+
if (!proto.constructor.hasOwnProperty('properties')) {
53+
Object.defineProperty(proto.constructor, 'properties', { value: {} });
54+
}
55+
const finalOpts = { type, notify, reflectToAttribute, readOnly, computed, observer };
56+
proto.constructor.properties[name] = finalOpts;
57+
}
58+
/**
59+
* A TypeScript property decorator factory that defines this as a Polymer
60+
* property.
61+
*
62+
* This function must be invoked to return a decorator.
63+
*/
64+
function property(options) {
65+
return (proto, propName) => {
66+
createProperty(proto, propName, options);
67+
};
68+
}
69+
/**
70+
* A TypeScript property decorator factory that causes the decorated method to
71+
* be called when a property changes.
72+
*
73+
* This function must be invoked to return a decorator.
74+
*/
75+
function observe(...targets) {
76+
return (proto, propName) => {
77+
if (!proto.constructor.hasOwnProperty('observers')) {
78+
proto.constructor.observers = [];
79+
}
80+
proto.constructor.observers.push(`${propName}(${targets.join(',')})`);
81+
};
82+
}
83+
/**
84+
* A TypeScript accessor decorator factory that causes the decorated getter to
85+
* be called when a set of dependencies change. The arguments of this decorator
86+
* should be paths of the data dependencies as described
87+
* [here](https://www.polymer-project.org/2.0/docs/devguide/observers#define-a-computed-property)
88+
* The decorated getter should not have an associated setter.
89+
*
90+
* This function must be invoked to return a decorator.
91+
*/
92+
function computed(...targets) {
93+
return (proto, propName, descriptor) => {
94+
const fnName = `__compute${propName}`;
95+
Object.defineProperty(proto, fnName, { value: descriptor.get });
96+
descriptor.get = undefined;
97+
createProperty(proto, propName, { computed: `${fnName}(${targets.join(',')})` });
98+
};
99+
}
100+
/**
101+
* A TypeScript property decorator factory that converts a class property into
102+
* a getter that executes a querySelector on the element's shadow root.
103+
*
104+
* By annotating the property with the correct type, element's can have
105+
* type-checked access to internal elements.
106+
*
107+
* This function must be invoked to return a decorator.
108+
*/
109+
const query = _query((target, selector) => target.querySelector(selector));
110+
/**
111+
* A TypeScript property decorator factory that converts a class property into
112+
* a getter that executes a querySelectorAll on the element's shadow root.
113+
*
114+
* By annotating the property with the correct type, element's can have
115+
* type-checked access to internal elements. The type should be NodeList
116+
* with the correct type argument.
117+
*
118+
* This function must be invoked to return a decorator.
119+
*/
120+
const queryAll = _query((target, selector) => target.querySelectorAll(selector));
121+
/**
122+
* Creates a decorator function that accepts a selector, and replaces a
123+
* property with a getter than executes the selector with the given queryFn
124+
*
125+
* @param queryFn A function that executes a query with a selector
126+
*/
127+
function _query(queryFn) {
128+
return (selector) => (proto, propName) => {
129+
Object.defineProperty(proto, propName, {
130+
get() {
131+
return queryFn(this.shadowRoot, selector);
132+
},
133+
enumerable: true,
134+
configurable: true,
135+
});
136+
};
137+
}
138+
/**
139+
* A TypeScript property decorator factory that causes the decorated method to
140+
* be called when a imperative event is fired on the targeted element. `target`
141+
* can be either a single element by id or element.
142+
*
143+
* You must apply the supplied DeclarativeEventListeners mixin to your element
144+
* class for this decorator to function.
145+
*
146+
* https://www.polymer-project.org/2.0/docs/devguide/events#imperative-listeners
147+
*
148+
* @param eventName A string representing the event type to listen for
149+
* @param target A single element by id or EventTarget to target
150+
*/
151+
const listen = (eventName, target) => (proto, methodName) => {
152+
proto.constructor._addDeclarativeEventListener(target, eventName, proto[methodName]);
153+
};
154+
155+
exports.customElement = customElement;
156+
exports.property = property;
157+
exports.observe = observe;
158+
exports.computed = computed;
159+
exports.query = query;
160+
exports.queryAll = queryAll;
161+
exports.listen = listen;
162+
163+
return exports;
164+
165+
}({}));

0 commit comments

Comments
 (0)