From 83ad8f1d9af12f7af13c6b0f6cba15a1aca7ddd1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Mar 2015 10:22:53 +0100 Subject: [PATCH 1/4] addded polymer definition files --- polymer/polymer-tests.ts | 79 ++++++++++++++++++++++++++ polymer/polymer.app-router.d.ts | 8 +++ polymer/polymer.core-drawer-panel.d.ts | 70 +++++++++++++++++++++++ polymer/polymer.d.ts | 42 ++++++++++++++ polymer/polymer.paper-toast.d.ts | 61 ++++++++++++++++++++ 5 files changed, 260 insertions(+) create mode 100644 polymer/polymer-tests.ts create mode 100644 polymer/polymer.app-router.d.ts create mode 100644 polymer/polymer.core-drawer-panel.d.ts create mode 100644 polymer/polymer.d.ts create mode 100644 polymer/polymer.paper-toast.d.ts diff --git a/polymer/polymer-tests.ts b/polymer/polymer-tests.ts new file mode 100644 index 000000000..e24445aca --- /dev/null +++ b/polymer/polymer-tests.ts @@ -0,0 +1,79 @@ +/// + +class AbstractPolymerElement implements PolymerElement { + $: { [id: string]: HTMLElement }; //polymer object for elements that have an ID + + // inargs is the [args] for the callback.. need to update function def + async(inMethod: () => void, inArgs?: Array, inTimeout?: number): void { } + job(jobName: string, inMethod: () => void, inTimeout?: number): void { } + fire(eventName: string, details?: any, targetNode?: any, bubbles?: boolean, cancelable?: boolean): void { } + asyncFire(eventName: string, details?: any, targetNode?: any, bubbles?: boolean, cancelable?: boolean): void { } + + cancelUnbindAll(): void { } + + // these are mix in API's.. hacky way to deal with them at the moment. + resizableAttachedHandler; + resizableDetachedHandler; +} + +class AbstractWebComponent extends AbstractPolymerElement { + + public name: string; + + constructor(name: string) { + super(); + this.name = name; + } + + protected get(): HTMLElement { + return this; + } +} + +function registerWebComponent(webComponentClass: Function, ...mixins): void { + + // we need a flat object, without prototype in order to polymer to work on our components + var flattenedComponent = {}; + var poly_func = ["async", "job", "fire", "asyncFire", "cancelUnbindAll"]; + if (mixins) { + // apply mixins + mixins.forEach(mixin => { + for (var i in mixin) { + if (mixin.hasOwnProperty(i)) { + webComponentClass.prototype[i] = mixin[i]; + } + } + }); + } + var webComponent: AbstractWebComponent = new (webComponentClass)(); + for (var i in webComponent) { + if (!_.contains(poly_func, i)) { + flattenedComponent[i] = webComponent[i]; + } + } + + console.debug('registering web component', webComponent, flattenedComponent); + Polymer(webComponent.name, flattenedComponent); +} + +class Spinner extends AbstractWebComponent { + private pendingRequestsCount: number; + + constructor() { + super('test-spinner'); + } + + public ready(): void { + this.pendingRequestsCount = 0; + this.updateUI(); + } + + private updateUI(): void { + var spinnerHidden: boolean = this.pendingRequestsCount == 0; + if (spinnerHidden) { + this.get().setAttribute('hidden', 'true'); + } else { + this.get().removeAttribute('hidden'); + } + } +} \ No newline at end of file diff --git a/polymer/polymer.app-router.d.ts b/polymer/polymer.app-router.d.ts new file mode 100644 index 000000000..1643c58a6 --- /dev/null +++ b/polymer/polymer.app-router.d.ts @@ -0,0 +1,8 @@ +declare module PolymerComponents { + module App { + export interface Router extends HTMLElement { + init(): void; + go(path: string, options?: { replace?: boolean }): void; + } + } +} \ No newline at end of file diff --git a/polymer/polymer.core-drawer-panel.d.ts b/polymer/polymer.core-drawer-panel.d.ts new file mode 100644 index 000000000..2bad7b633 --- /dev/null +++ b/polymer/polymer.core-drawer-panel.d.ts @@ -0,0 +1,70 @@ +// Type definitions for polymer's paper-toast +// Project: https://github.com/Polymer/core-drawer-panel +// Definitions by: Louis Grignon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module PolymerComponents { + export module Core { + export interface DrawerPanel extends HTMLElement { + /** + * Width of the drawer panel. default: '256px' + */ + drawerWidth: string; + + /** + * Max-width when the panel changes to narrow layout. default: '640px' + */ + responsiveWidth: string; + + /** + * The panel that is being selected. drawer for the drawer panel and main for the main panel. default: null + */ + selected: string; + + /** + * The panel to be selected when core-drawer-panel changes to narrow layout. default: 'main' + */ + defaultSelected: string; + + /** + * Returns true if the panel is in narrow layout. This is useful if you need to show/hide elements based on the layout. default: false + */ + narrow: boolean; + + /** + * If true, position the drawer to the right. default: false + */ + rightDrawer: boolean; + + /** + * If true, swipe to open/close the drawer is disabled. default: false + */ + disableSwipe: boolean; + + /** + * If true, ignore responsiveWidth setting and force the narrow layout. default: false + */ + forceNarrow: boolean; + + /** + * If true, swipe from the edge is disabled. default: false + */ + disableEdgeSwipe: boolean; + + /** + * Toggles the panel open and closed. + */ + togglePanel(): void; + + /** + * Opens the drawer. + */ + openDrawer(): void; + + /** + * Closes the drawer. + */ + closeDrawer(): void; + } + } +} \ No newline at end of file diff --git a/polymer/polymer.d.ts b/polymer/polymer.d.ts new file mode 100644 index 000000000..f501d8655 --- /dev/null +++ b/polymer/polymer.d.ts @@ -0,0 +1,42 @@ +// Type definitions for polymer +// Project: https://github.com/polymer +// Definitions by: Louis Grignon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface PolymerElement { + + // definition + publish?: Object; + computed?: Object; + // object mapping variable names to functions name + observe?: Object; + + // life time API + created? (): void; + ready? (): void; + attached? (): void; + domReady? (): void; + detached? (): void; + attributeChanged? (attrName: string, oldVal: any, newVal: any): void; +} + +interface Polymer { + + importElements(node: Node, callback: Function); + import(url: string, callback?: () => void): void; + + mixin(target: any, ...obj1): any; + waitingFor(): Array; + // should be an "integer" for milliseconds + forceReady(timeout: number): void; + + (tag_name: string, prototype: PolymerElement): void; + (tag_name: string, prototype: any): void; + (prototype: PolymerElement): void; + (): void; + // hacks for mixins + CoreResizer: any; + CoreResizable: any; +} + +declare var Polymer: Polymer; diff --git a/polymer/polymer.paper-toast.d.ts b/polymer/polymer.paper-toast.d.ts new file mode 100644 index 000000000..fbf8cd7a6 --- /dev/null +++ b/polymer/polymer.paper-toast.d.ts @@ -0,0 +1,61 @@ +// Type definitions for polymer's paper-toast +// Project: https://github.com/Polymer/paper-toast +// Definitions by: Louis Grignon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module PolymerComponents { + export module Paper { + export interface Toast extends HTMLElement { + /** + * The text shows in a toast. + * default: '' + */ + text: string; + + /** + * The duration in milliseconds to show the toast. + * default: 3000 + */ + duration: number; + + /** + * Set opened to true to show the toast and to false to hide it. + * default: false + */ + opened: boolean; + + /** + * Min-width when the toast changes to narrow layout. In narrow layout, the toast fits at the bottom of the screen when opened. + * default: '480px' + */ + responsiveWidth: string; + + /** + * If true, the toast can't be swiped. + * default: false + */ + swipeDisabled: boolean; + + /** + * By default, the toast will close automatically if the user taps outside it or presses the escape key. Disable this behavior by setting the autoCloseDisabled property to true. + * default: false + */ + autoCloseDisabled: boolean; + + /** + * Show the toast for the specified duration + */ + show(): void; + + /** + * Dismiss the toast and hide it. + */ + dismiss(): void; + + /** + * Toggle the opened state of the toast. + */ + toggle(): void; + } + } +} \ No newline at end of file From 063a6ccc292bedc15c6210e8fdc0bcfbaa6211b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Mar 2015 10:44:54 +0100 Subject: [PATCH 2/4] fixed definition files for polymer (description on app router and any types) --- polymer/polymer-tests.ts | 12 ++++-------- polymer/polymer.app-router.d.ts | 5 +++++ polymer/polymer.d.ts | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/polymer/polymer-tests.ts b/polymer/polymer-tests.ts index e24445aca..80227cab6 100644 --- a/polymer/polymer-tests.ts +++ b/polymer/polymer-tests.ts @@ -10,10 +10,6 @@ class AbstractPolymerElement implements PolymerElement { asyncFire(eventName: string, details?: any, targetNode?: any, bubbles?: boolean, cancelable?: boolean): void { } cancelUnbindAll(): void { } - - // these are mix in API's.. hacky way to deal with them at the moment. - resizableAttachedHandler; - resizableDetachedHandler; } class AbstractWebComponent extends AbstractPolymerElement { @@ -30,11 +26,10 @@ class AbstractWebComponent extends AbstractPolymerElement { } } -function registerWebComponent(webComponentClass: Function, ...mixins): void { +function registerWebComponent(webComponentClass: Function, ...mixins: any[]): void { // we need a flat object, without prototype in order to polymer to work on our components - var flattenedComponent = {}; - var poly_func = ["async", "job", "fire", "asyncFire", "cancelUnbindAll"]; + var flattenedComponent: any = {}; if (mixins) { // apply mixins mixins.forEach(mixin => { @@ -47,7 +42,8 @@ function registerWebComponent(webComponentClass: Function, ...mixins): void { } var webComponent: AbstractWebComponent = new (webComponentClass)(); for (var i in webComponent) { - if (!_.contains(poly_func, i)) { + // do not include polymer functions + if (i != "async" && i != "job" && i != "fire" && i != "asyncFire" && i != "cancelUnbindAll") { flattenedComponent[i] = webComponent[i]; } } diff --git a/polymer/polymer.app-router.d.ts b/polymer/polymer.app-router.d.ts index 1643c58a6..633479ba2 100644 --- a/polymer/polymer.app-router.d.ts +++ b/polymer/polymer.app-router.d.ts @@ -1,3 +1,8 @@ +// Type definitions for app-router +// Project: https://github.com/erikringsmuth/app-router +// Definitions by: Louis Grignon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + declare module PolymerComponents { module App { export interface Router extends HTMLElement { diff --git a/polymer/polymer.d.ts b/polymer/polymer.d.ts index f501d8655..dfb812f8c 100644 --- a/polymer/polymer.d.ts +++ b/polymer/polymer.d.ts @@ -22,16 +22,16 @@ interface PolymerElement { interface Polymer { - importElements(node: Node, callback: Function); + importElements(node: Node, callback: Function): void; import(url: string, callback?: () => void): void; - mixin(target: any, ...obj1): any; + mixin(target: any, ...mixins: any[]): any; waitingFor(): Array; // should be an "integer" for milliseconds forceReady(timeout: number): void; - (tag_name: string, prototype: PolymerElement): void; - (tag_name: string, prototype: any): void; + (tagName: string, prototype: PolymerElement): void; + (tagName: string, prototype: any): void; (prototype: PolymerElement): void; (): void; // hacks for mixins From d2ff5898b80582dcf671448775ef96555eb5f138 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Mar 2015 10:48:18 +0100 Subject: [PATCH 3/4] fixed any index --- polymer/polymer-tests.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polymer/polymer-tests.ts b/polymer/polymer-tests.ts index 80227cab6..70c5bce0a 100644 --- a/polymer/polymer-tests.ts +++ b/polymer/polymer-tests.ts @@ -44,7 +44,8 @@ function registerWebComponent(webComponentClass: Function, ...mixins: any[]): vo for (var i in webComponent) { // do not include polymer functions if (i != "async" && i != "job" && i != "fire" && i != "asyncFire" && i != "cancelUnbindAll") { - flattenedComponent[i] = webComponent[i]; + var attribute: any = webComponent[i]; + flattenedComponent[i] = attribute; } } From 502c7582f72ddfc6ad16762b24483a8cad3f3d82 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Mar 2015 10:51:55 +0100 Subject: [PATCH 4/4] more implied any --- polymer/polymer-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polymer/polymer-tests.ts b/polymer/polymer-tests.ts index 70c5bce0a..a606692fd 100644 --- a/polymer/polymer-tests.ts +++ b/polymer/polymer-tests.ts @@ -44,7 +44,7 @@ function registerWebComponent(webComponentClass: Function, ...mixins: any[]): vo for (var i in webComponent) { // do not include polymer functions if (i != "async" && i != "job" && i != "fire" && i != "asyncFire" && i != "cancelUnbindAll") { - var attribute: any = webComponent[i]; + var attribute: any = (webComponent)[i]; flattenedComponent[i] = attribute; } }