From 83ad8f1d9af12f7af13c6b0f6cba15a1aca7ddd1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Mar 2015 10:22:53 +0100 Subject: [PATCH] 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