From ab71290650b4077c498503315396bece131ae488 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 28 May 2015 10:50:54 +0800 Subject: [PATCH 01/20] moment: Include some methods which were added in 2.9.0 --- moment/moment-node.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/moment/moment-node.d.ts b/moment/moment-node.d.ts index 13f1b9362..0a89b7066 100644 --- a/moment/moment-node.d.ts +++ b/moment/moment-node.d.ts @@ -69,6 +69,7 @@ declare module moment { subtract(d: Duration): Duration; toISOString(): string; + toJSON(): string; } @@ -276,6 +277,12 @@ declare module moment { isSame(b: Date, granularity: string): boolean; isSame(b: number[], granularity: string): boolean; + isBetween(a: Moment, b: Moment, granularity?: string): boolean; + isBetween(a: string, b: string, granularity?: string): boolean; + isBetween(a: number, b: number, granularity?: string): boolean; + isBetween(a: Date, b: Date, granularity?: string): boolean; + isBetween(a: number[], b: number[], granularity?: string): boolean; + // Deprecated as of 2.8.0. lang(language: string): Moment; lang(reset: boolean): Moment; @@ -412,6 +419,7 @@ declare module moment { invalid(parsingFlags?: Object): Moment; isMoment(): boolean; isMoment(m: any): boolean; + isDate(m: any): boolean; isDuration(): boolean; isDuration(d: any): boolean; From dbbc90296b72294f8099c19e724c37447dca43f3 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 28 May 2015 10:51:22 +0800 Subject: [PATCH 02/20] moment: Tests for 2.9.0 methods --- moment/moment-external-tests.ts | 7 +++++++ moment/moment-tests.ts | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/moment/moment-external-tests.ts b/moment/moment-external-tests.ts index c5855c12c..b76752b11 100644 --- a/moment/moment-external-tests.ts +++ b/moment/moment-external-tests.ts @@ -196,10 +196,17 @@ moment.isMoment(); moment.isMoment(new Date()); moment.isMoment(moment()); +moment.isDate(new Date()); +moment.isDate(/regexp/); + moment.isDuration(); moment.isDuration(new Date()); moment.isDuration(moment.duration()); +moment().isBetween(moment(), moment()); +moment().isBetween(new Date(), new Date()); +moment().isBetween([1,1,2000], [1,1,2001], "year"); + moment.localeData('fr'); moment(1316116057189).fromNow(); diff --git a/moment/moment-tests.ts b/moment/moment-tests.ts index 16490d2e1..04c075352 100644 --- a/moment/moment-tests.ts +++ b/moment/moment-tests.ts @@ -196,10 +196,17 @@ moment.isMoment(); moment.isMoment(new Date()); moment.isMoment(moment()); +moment.isDate(new Date()); +moment.isDate(/regexp/); + moment.isDuration(); moment.isDuration(new Date()); moment.isDuration(moment.duration()); +moment().isBetween(moment(), moment()); +moment().isBetween(new Date(), new Date()); +moment().isBetween([1,1,2000], [1,1,2001], "year"); + moment.localeData('fr'); moment(1316116057189).fromNow(); @@ -228,6 +235,8 @@ moment.duration(500).seconds(); moment.duration(500).asSeconds(); moment.duration().minutes(); moment.duration().asMinutes(); +moment.duration().toISOString(); +moment.duration().toJSON(); var adur = moment.duration(3, 'd'); var bdur = moment.duration(2, 'd'); From 8064aa89b0ccf592a507ccd8f5e0389818abb64b Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 2 Jun 2015 11:30:14 +0800 Subject: [PATCH 03/20] moment: Use type union for methods with moment-like parameters --- moment/moment-node.d.ts | 59 ++++++----------------------------------- 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/moment/moment-node.d.ts b/moment/moment-node.d.ts index 0a89b7066..eaacb8855 100644 --- a/moment/moment-node.d.ts +++ b/moment/moment-node.d.ts @@ -216,11 +216,8 @@ declare module moment { dayOfYear(): number; dayOfYear(d: number): Moment; - from(f: Moment): string; - from(f: Moment, suffix: boolean): string; - from(d: Date): string; - from(s: string): string; - from(date: number[]): string; + from(f: Moment|string|number|Date|number[], suffix?: boolean): string; + to(f: Moment|string|number|Date|number[], suffix?: boolean): string; diff(b: Moment): number; diff(b: Moment, unitOfTime: string): number; @@ -243,45 +240,13 @@ declare module moment { isDST(): boolean; isBefore(): boolean; - isBefore(b: Moment): boolean; - isBefore(b: string): boolean; - isBefore(b: Number): boolean; - isBefore(b: Date): boolean; - isBefore(b: number[]): boolean; - isBefore(b: Moment, granularity: string): boolean; - isBefore(b: String, granularity: string): boolean; - isBefore(b: Number, granularity: string): boolean; - isBefore(b: Date, granularity: string): boolean; - isBefore(b: number[], granularity: string): boolean; + isBefore(b: Moment|string|number|Date|number[], granularity?: string): boolean; isAfter(): boolean; - isAfter(b: Moment): boolean; - isAfter(b: string): boolean; - isAfter(b: Number): boolean; - isAfter(b: Date): boolean; - isAfter(b: number[]): boolean; - isAfter(b: Moment, granularity: string): boolean; - isAfter(b: String, granularity: string): boolean; - isAfter(b: Number, granularity: string): boolean; - isAfter(b: Date, granularity: string): boolean; - isAfter(b: number[], granularity: string): boolean; + isAfter(b: Moment|string|number|Date|number[], granularity?: string): boolean; - isSame(b: Moment): boolean; - isSame(b: string): boolean; - isSame(b: Number): boolean; - isSame(b: Date): boolean; - isSame(b: number[]): boolean; - isSame(b: Moment, granularity: string): boolean; - isSame(b: String, granularity: string): boolean; - isSame(b: Number, granularity: string): boolean; - isSame(b: Date, granularity: string): boolean; - isSame(b: number[], granularity: string): boolean; - - isBetween(a: Moment, b: Moment, granularity?: string): boolean; - isBetween(a: string, b: string, granularity?: string): boolean; - isBetween(a: number, b: number, granularity?: string): boolean; - isBetween(a: Date, b: Date, granularity?: string): boolean; - isBetween(a: number[], b: number[], granularity?: string): boolean; + isSame(b: Moment|string|number|Date|number[], granularity?: string): boolean; + isBetween(a: Moment|string|number|Date|number[], b: Moment|string|number|Date|number[], granularity?: string): boolean; // Deprecated as of 2.8.0. lang(language: string): Moment; @@ -297,20 +262,12 @@ declare module moment { localeData(): MomentLanguage; // Deprecated as of 2.7.0. - max(date: Date): Moment; - max(date: number): Moment; - max(date: any[]): Moment; - max(date: string): Moment; + max(date: Moment|string|number|Date|any[]): Moment; max(date: string, format: string): Moment; - max(clone: Moment): Moment; // Deprecated as of 2.7.0. - min(date: Date): Moment; - min(date: number): Moment; - min(date: any[]): Moment; - min(date: string): Moment; + min(date: Moment|string|number|Date|any[]): Moment; min(date: string, format: string): Moment; - min(clone: Moment): Moment; get(unit: string): number; set(unit: string, value: number): Moment; From 8f9ff607f0a79e5a976682d00ce156781f9efd19 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sat, 6 Jun 2015 16:26:00 +0800 Subject: [PATCH 04/20] moment: Use type alias for moment-like parameters --- moment/moment-node.d.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/moment/moment-node.d.ts b/moment/moment-node.d.ts index eaacb8855..f491833f9 100644 --- a/moment/moment-node.d.ts +++ b/moment/moment-node.d.ts @@ -216,8 +216,8 @@ declare module moment { dayOfYear(): number; dayOfYear(d: number): Moment; - from(f: Moment|string|number|Date|number[], suffix?: boolean): string; - to(f: Moment|string|number|Date|number[], suffix?: boolean): string; + from(f: MomentLike, suffix?: boolean): string; + to(f: MomentLike, suffix?: boolean): string; diff(b: Moment): number; diff(b: Moment, unitOfTime: string): number; @@ -240,13 +240,13 @@ declare module moment { isDST(): boolean; isBefore(): boolean; - isBefore(b: Moment|string|number|Date|number[], granularity?: string): boolean; + isBefore(b: MomentLike, granularity?: string): boolean; isAfter(): boolean; - isAfter(b: Moment|string|number|Date|number[], granularity?: string): boolean; + isAfter(b: MomentLike, granularity?: string): boolean; - isSame(b: Moment|string|number|Date|number[], granularity?: string): boolean; - isBetween(a: Moment|string|number|Date|number[], b: Moment|string|number|Date|number[], granularity?: string): boolean; + isSame(b: MomentLike, granularity?: string): boolean; + isBetween(a: MomentLike, b: MomentLike, granularity?: string): boolean; // Deprecated as of 2.8.0. lang(language: string): Moment; @@ -262,11 +262,11 @@ declare module moment { localeData(): MomentLanguage; // Deprecated as of 2.7.0. - max(date: Moment|string|number|Date|any[]): Moment; + max(date: MomentLike|any[]): Moment; max(date: string, format: string): Moment; // Deprecated as of 2.7.0. - min(date: Moment|string|number|Date|any[]): Moment; + min(date: MomentLike|any[]): Moment; min(date: string, format: string): Moment; get(unit: string): number; @@ -439,6 +439,9 @@ declare module moment { } + // Moment.js automatically converts datetime parameters from a number of types + type MomentLike = Moment | string | number | Date | number[]; + } declare module 'moment' { From 6f0bcac0caf998f1e943d43b7f9bf240c68ba13e Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 23 Jun 2015 13:00:22 +0800 Subject: [PATCH 05/20] Revert "moment: Use type alias for moment-like parameters" This reverts commit 8f9ff607f0a79e5a976682d00ce156781f9efd19 which fails to compile on typescript@1.4.1 (however it compiles with typescript@1.5.0-beta). --- moment/moment-node.d.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/moment/moment-node.d.ts b/moment/moment-node.d.ts index f491833f9..eaacb8855 100644 --- a/moment/moment-node.d.ts +++ b/moment/moment-node.d.ts @@ -216,8 +216,8 @@ declare module moment { dayOfYear(): number; dayOfYear(d: number): Moment; - from(f: MomentLike, suffix?: boolean): string; - to(f: MomentLike, suffix?: boolean): string; + from(f: Moment|string|number|Date|number[], suffix?: boolean): string; + to(f: Moment|string|number|Date|number[], suffix?: boolean): string; diff(b: Moment): number; diff(b: Moment, unitOfTime: string): number; @@ -240,13 +240,13 @@ declare module moment { isDST(): boolean; isBefore(): boolean; - isBefore(b: MomentLike, granularity?: string): boolean; + isBefore(b: Moment|string|number|Date|number[], granularity?: string): boolean; isAfter(): boolean; - isAfter(b: MomentLike, granularity?: string): boolean; + isAfter(b: Moment|string|number|Date|number[], granularity?: string): boolean; - isSame(b: MomentLike, granularity?: string): boolean; - isBetween(a: MomentLike, b: MomentLike, granularity?: string): boolean; + isSame(b: Moment|string|number|Date|number[], granularity?: string): boolean; + isBetween(a: Moment|string|number|Date|number[], b: Moment|string|number|Date|number[], granularity?: string): boolean; // Deprecated as of 2.8.0. lang(language: string): Moment; @@ -262,11 +262,11 @@ declare module moment { localeData(): MomentLanguage; // Deprecated as of 2.7.0. - max(date: MomentLike|any[]): Moment; + max(date: Moment|string|number|Date|any[]): Moment; max(date: string, format: string): Moment; // Deprecated as of 2.7.0. - min(date: MomentLike|any[]): Moment; + min(date: Moment|string|number|Date|any[]): Moment; min(date: string, format: string): Moment; get(unit: string): number; @@ -439,9 +439,6 @@ declare module moment { } - // Moment.js automatically converts datetime parameters from a number of types - type MomentLike = Moment | string | number | Date | number[]; - } declare module 'moment' { From aaa447bd7e4b4dbfc75e6ea6c393a86c6d567bdc Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Fri, 17 Jul 2015 00:51:16 +0900 Subject: [PATCH 06/20] i18next: Add init() and setLng() with a two-arg callback --- i18next/i18next.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/i18next/i18next.d.ts b/i18next/i18next.d.ts index 3d24c9b96..e20cb4c93 100644 --- a/i18next/i18next.d.ts +++ b/i18next/i18next.d.ts @@ -87,6 +87,7 @@ interface I18nextStatic { }; init(callback?: (t: (key: string, options?: any) => string) => void ): JQueryDeferred; init(options?: I18nextOptions, callback?: (t: (key: string, options?: any) => string) => void ): JQueryDeferred; + init(options?: I18nextOptions, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred; lng(): string; loadNamespace(namespace: string, callback?: () => void ): void; loadNamespaces(namespaces: string[], callback?: () => void ): void; @@ -104,6 +105,7 @@ interface I18nextStatic { preload(languages: string[], callback?: (t: (key: string, options?: any) => string) => void ): void; setDefaultNamespace(namespace: string): void; setLng(language: string, callback?: (t: (key: string, options?: any) => string) => void ): void; + setLng(language: string, callback?: (err: any, t: (key: string, options?: any) => string) => void ): void; sync: { load: (languages: string[], options: I18nextOptions, callback: (err: Error, store: IResourceStore) => void ) => void; postMissing: (language: string, namespace: string, key: string, defaultValue: any, languages: string[]) => void; From e34f20e4f137fccb25e705d6147e836f76248d34 Mon Sep 17 00:00:00 2001 From: Sam Saint-Pettersen Date: Fri, 17 Jul 2015 12:04:53 +0100 Subject: [PATCH 07/20] Type definitions for to-title-case (https://http://individed.com/code/to-title-case) --- to-title-case/to-title-case-tests.ts | 10 ++++++++++ to-title-case/to-title-case.d.ts | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 to-title-case/to-title-case-tests.ts create mode 100644 to-title-case/to-title-case.d.ts diff --git a/to-title-case/to-title-case-tests.ts b/to-title-case/to-title-case-tests.ts new file mode 100644 index 000000000..2dc1fd9f5 --- /dev/null +++ b/to-title-case/to-title-case-tests.ts @@ -0,0 +1,10 @@ +/// +/// + +import fs = require('fs'); + +fs.readFile('to-title-case.min.js', 'utf-8', function(err: any, code: string) { + eval(code); + var lowerCase: string = 'this title is in lowercase and will be title case'; + console.log(lowerCase.toTitleCase()); // Now in title case. +}); diff --git a/to-title-case/to-title-case.d.ts b/to-title-case/to-title-case.d.ts new file mode 100644 index 000000000..2faa2d8d0 --- /dev/null +++ b/to-title-case/to-title-case.d.ts @@ -0,0 +1,8 @@ +// Type definitions for to-title-case +// Project: https://github.com/gouch/to-title-case +// Definitions by: Sam Saint-Pettersen +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface String { + toTitleCase(): string; +} From 33e2636b03c15e59ecbd5ab29289a1cf6a4b929b Mon Sep 17 00:00:00 2001 From: Emil Ekberg Date: Fri, 17 Jul 2015 19:17:35 +0200 Subject: [PATCH 08/20] webfontloader definitions added --- webfontloader/webfontloader.d.ts | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 webfontloader/webfontloader.d.ts diff --git a/webfontloader/webfontloader.d.ts b/webfontloader/webfontloader.d.ts new file mode 100644 index 000000000..d8e354cf7 --- /dev/null +++ b/webfontloader/webfontloader.d.ts @@ -0,0 +1,59 @@ +// Type definitions for typekit-webfontloader 1.6.4 +// Project: https://github.com/typekit/webfontloader +// Definitions by: doskallemaskin +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare class WebFont { + static load(config:WebFont.Config); +} +declare module WebFont { + export interface Config { + /** Setting this to false will disable html classes (defaults to true) */ + classes?:boolean; + /** Settings this to false will disable callbacks/events (defaults to true) */ + events?:boolean; + /** Time (in ms) until the fontinactive callback will be triggered (defaults to 5000) */ + timeout?:number; + /** This event is triggered when all fonts have been requested. */ + loading?():void; + /** This event is triggered when the fonts have rendered. */ + active?():void; + /** This event is triggered when the browser does not support linked fonts or if none of the fonts could be loaded. */ + inactive?():void; + /** This event is triggered once for each font that's loaded. */ + fontloading?(familyName: string, fvd):void; + /** This event is triggered once for each font that renders. */ + fontactive?(familyName: string, fvd):void; + /** This event is triggered if the font can't be loaded. */ + fontinactive?(familyName: string, fvd):void; + + /** Child window or iframes to manage fonts for */ + context?:Array; + + custom?:Custom; + google?:Google; + typekit?:Typekit; + fontdeck?:Fontdeck; + monotype?:Monotype; + } + export interface Google { + families?:Array; + } + export interface Typekit { + id?:Array; + } + export interface Custom { + families?:Array; + urls?:Array; + testStrings?:{[fontFamily:string]:string}; + + } + export interface Fontdeck { + id?:string; + } + export interface Monotype { + projectId?:string; + version?:number; + } + +} \ No newline at end of file From 6bac4335fd76133aca0a1c01d33cfd30f6d1a039 Mon Sep 17 00:00:00 2001 From: Kwang Yul Seo Date: Sat, 18 Jul 2015 15:53:11 +0900 Subject: [PATCH 09/20] Improve types of serveStatic's option parameter. * index accepts a new index string or an array of string. * maxAges accepts a string accepted by the ms module. --- serve-static/serve-static.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serve-static/serve-static.d.ts b/serve-static/serve-static.d.ts index f7d7e502f..cbf9406d7 100644 --- a/serve-static/serve-static.d.ts +++ b/serve-static/serve-static.d.ts @@ -49,7 +49,7 @@ declare module "serve-static" { * By default this module will send "index.html" files in response to a request on a directory. * To disable this set false or to supply a new index pass a string or an array in preferred order. */ - index?: boolean; + index?: boolean|string|string[]; /** * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value. @@ -59,7 +59,7 @@ declare module "serve-static" { /** * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module. */ - maxAge?: number; + maxAge?: number|string; /** * Redirect to trailing "/" when the pathname is a dir. Defaults to true. From c941b6e4c7793fb13ff557308574014d4ec8f3b6 Mon Sep 17 00:00:00 2001 From: Florent POUJOL Date: Sat, 18 Jul 2015 23:41:39 +0200 Subject: [PATCH 10/20] Add PhotonUI v1.0.0 definitions. --- photonui/photonui.d.ts | 420 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 420 insertions(+) create mode 100644 photonui/photonui.d.ts diff --git a/photonui/photonui.d.ts b/photonui/photonui.d.ts new file mode 100644 index 000000000..b505909ac --- /dev/null +++ b/photonui/photonui.d.ts @@ -0,0 +1,420 @@ +// Type definitions for PhotonUI 1.0.0 +// Project: https://github.com/wanadev/PhotonUI +// Definitions by: Florent Poujol +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +module photonui { + class Base { + constructor(params?: any); + destroy(); + registerCallback(id: string, wEvent: string, callback: Function, thisArg: any); + removeCallback(id: string); + } + + class Widget extends Base { + absolutePosition: { x: number; y: number; }; // readonly + contextMenu: PopupWindow; + contextMenuName: string; + html: HTMLElement; // readonly + layoutOptions: { [key: string]: any }; + name: string; + offsetWidth: number; // readonly + offsetHeight: number; // readonly + parent: Widget; + parentName: string; + tooltip: string; + visible: boolean; + + show(); + hide(); + unparent(); + addClass(className: string); + removeClass(className: string); + + static getWidget(name: string): Widget; + static domInsert(widget: Widget, element: HTMLElement); + } + + // Methods + function domInsert(widget: Widget, element: HTMLElement); + function getWidget(name: string): Widget; + + //Widgets + class FileManager extends Base { + acceptedExts: string[]; + acceptedMimes: string[]; + dropZone: HTMLElement; + multiselect: boolean; + + open(); + } + + class Translation extends Base { + locale: string; + + addCatalogs(catalogs: any); // Stone.js catalogs + guessUserLanguage(): string; + gettext(string: string, replacements: any): string; + lazyGettext(string: string, replacements: any): string; + enableDomScan(enable: boolean); + updateDomTranslation(); + } + + class AccelManager extends Base { + addAccel(id: string, keys: string, callback: Function, safe: boolean); + removeAccel(id: string); + } + + class MouseManager extends Base { + constructor(element?: Widget|HTMLElement, params?: any) ; + + element: HTMLElement; + threshold: number; + + action: string; // readonly + btnLeft: boolean; // readonly + btnMiddle: boolean; // readonly + btnRight: boolean; // readonly + button: string; // readonly + pageX: number; // readonly + pageY: number; // readonly + x: number; // readonly + y: number; // readonly + deltaX: number; // readonly + deltaY: number; // readonly + } + + // ----------------------------------- + + class BaseIcon extends Widget {} + + class FAIcon extends BaseIcon { + constructor(params?: any); + constructor(name: string, params?: any); + + color: string; + iconName: string; + size: string; + } + + class SpriteIcon extends BaseIcon { + constructor(params?: any); + constructor(name: string, params?: any); + + icon: string; + iconName: string; + spriteSheetName: string; + } + + // ----------------------------------- + + class Image extends Widget { + width: number; + height: number; + url: string; + } + + class SpriteSheet extends Base { + name: string; + imageUrl: string; + size: string; + icons: { [iconName: string]: number[] }; + + addIcon(iconName: string, x: number, y: number); + removeIcon(iconName: string); + getIconPosition(iconName: string): { x: number; y: number; }; + getIconCSS(iconName: string): string; + + static getSpriteSheet(name: string): SpriteSheet; + } + + class Canvas extends Widget { + canvas: HTMLElement; + interactiveMode: HTMLElement; + width: number; + height: number; + getContext(contextId: string): any; + setContext(contextId: string); + supportsContext(contextId: string): boolean; + toBlod(imageFormat: string): any; // returns Blob + toBlodHD(imageFormat: string): any; // returns Blob + toDataUrl(imageFormat: string): string; + toDataUrlHD(imageFormat: string): string; + transferControlToProxy(); + } + + class Label extends Widget { + constructor(params?: any); + constructor(name: string, params?: any); + + forInput: Field|CheckBox; + forInputName: string; + text: string; + textAlign: string; + } + + class Text extends Widget { + rawHtml: string; + text: string; + } + + class ProgressBar extends Widget { + orientation: string; + pulsate: boolean; + textVisible: boolean; + value: number; + } + + class Separator extends Widget { + orientation: string; + } + + class Button extends Widget { + appearance: string; // normal | flat + buttonColor: string; + + leftIconName: string; + leftIcon: BaseIcon; + leftIconVisible: boolean; + + rightIconName: string; + rightIcon: BaseIcon; + rightIconVisible: boolean; + + text: string; + textVisible: boolean; + } + + class ColorButton extends Widget { + color: Color; + dialogOnly: boolean; + value: string; + } + + class CheckBox extends Widget { + value: boolean; + } + class Switch extends CheckBox {} + class ToggleButton extends CheckBox {} + + // ----------------------------------- + + class Color extends Base { + hexString: string; + rgbString: string; // readonly + rgbaString: string; // readonly + + red: number; + green: number; + blue: number; + alpha: number; + + hue: number; + saturation: number; + brightness: number; + + setRBG(red: number, green: number, blue: number); + getRBG(): number[]; + setRBGA(red: number, green: number, blue: number, alpha: number); + getRBGA(): number[]; + setHSB(hue: number, saturation: number, brightness: number); + } + + class ColorPalette extends Widget { + color: Color; + palette: Array; + value: string; + + static palette: Array; + } + + class ColorPicker extends Widget { + color: Color; + value: string; + } + + // ----------------------------------- + + class Field extends Widget { + placeholder: string; + value: boolean; + } + + class NumericField extends Field { + min: number; + max: number; + step: number; + decimalDigits: number; + decimalSymbol: string; + } + + class Slider extends NumericField { + fieldVisible: boolean; + } + + class TextAreaField extends Field { + cols: number; + rows: number; + } + + class TextField extends Field { + type: string; // text, password, email, search, tel, url + } + + // ----------------------------------- + + class Select extends Widget { + children: Widgets[]; + childrenNames: string[]; + iconVisible: boolean; + placeholder: string; + popupWidth: number; + popupHeight: number; + popupMaxWidth: number; + popupMinWidth: number; + popupMaxHeight: number; + popupMinHeight: number; + popupOffsetWidth: number; // readonly + popupOffsetHeight: number; // readonly + popupPadding: number; + value: any; // string (maybe) + + addChild(widget: Widget, layoutOptions?: any); + } + + class FontSelect extends Select { + fonts: string[]; + + addFont(fontName: string); + } + + // ----------------------------------- + + class Container extends Widget { + child: Widget; + childName: string; + containerNode: HTMLElement; // readonly + horizontalChildExpansion: boolean; + verticalChildExpansion: boolean; + + removeChild(widget: Widget); + } + + class Layout extends Container { + children: Widget[]; + childrenNames: string[]; + + addChild(widget: Widget, layoutOptions?: { [key: string]: any }); + empty(); + } + + class BoxLayout extends Layout { + horizontalPadding: number; + verticalPadding: number; + orientation: string; + spacing: number; + } + + class FluidLayout extends Layout { + horizontalPadding: number; + verticalPadding: number; + } + + class GridLayout extends Layout { + horizontalPadding: number; + verticalPadding: number; + horizontalSpacing: number; + verticalSpacing: number; + } + + class Menu extends Layout { + iconVisible: boolean; + } + + class MenuItem extends Menu { + active: boolean; + icon: BaseIcon; + iconName: string; + text: string; + value: any; // string (maybe) + } + + class SubMenuItem extends MenuItem { + menu: Menu; + menuName: string; + } + + // ----------------------------------- + + class Viewport extends Container { + width: number; + minWidth: number; + maxWidth: number; + height: number; + minHeight: number; + maxHeight: number; + padding: number; + horizontalScrollbar: boolean; + verticalScrollbar: boolean; + } + + // ----------------------------------- + + class BaseWindow extends Container { + width: number; + minWidth: number; + maxWidth: number; + height: number; + minHeight: number; + maxHeight: number; + padding: number; + position: { x: number; y: number }; + x: number; + y: number; + + center(); + } + + class PopupWindow extends BaseWindow { + popupXY(x: number, y: number); + popupWidget(widget: Widget); + } + + class PopupMenu extends PopupWindow {} + + class Window extends BaseWindow { + closeButtonVisible: boolean; + modal: boolean; + movable: boolean; + title: string; + + moveToFront(); + moveToBack(); + } + + class Dialog extends Window { + buttons: Widget[]; + buttonNames: string[]; + + addButton(widget: widget, layoutOptions: any); + removeButton(widget: widget); + } + + class ColorPickerDialog extends Dialog { + color: Color; + } + + // ----------------------------------- + + class TabItem extends Container { + tabHtml: HTMLElement; // readonly + title: string; + } + + class TabLayout extends Layout { + activeTab: Widget; + activeTabName: string; + padding: number; + tabsPosition: string; // top, bottom, left, right + } +} From e6ca97a0aa5cb933ee87ade1fb6fba3269cba8c3 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 18 Jul 2015 09:02:27 +0500 Subject: [PATCH 11/20] lodash: added _.valuesIn() method --- lodash/lodash-tests.ts | 12 ++++++++++++ lodash/lodash.d.ts | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 3a1c51f18..5536e2d32 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1091,6 +1091,18 @@ result = <{ a: number; b: number; c: number; }>_.transform(<{ [index: string]: n result = _.values({ 'one': 1, 'two': 2, 'three': 3 }); +// _.valueIn +class TestValueIn { + public a = 1; + public b = 2; + public c: number; +} +TestValueIn.prototype.c = 3; +result = _.valuesIn(new TestValueIn()); +// → [1, 2, 3] +result = _(new TestValueIn()).valuesIn().value(); +// → [1, 2, 3] + /********** * Utilities * ***********/ diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index fcf468577..66d5bbd4f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -6291,6 +6291,23 @@ declare module _ { values(object?: any): any[]; } + //_.valuesIn + interface LoDashStatic { + /** + * Creates an array of the own and inherited enumerable property values of object. + * @param object The object to query. + * @return Returns the array of property values. + **/ + valuesIn(object?: any): T[]; + } + + interface LoDashObjectWrapper { + /** + * @see _.valuesIn + **/ + valuesIn(): LoDashObjectWrapper; + } + /********** * String * **********/ From decb3023ca8aa95e313934a7500f37308947ce1b Mon Sep 17 00:00:00 2001 From: Florent Poujol Date: Sun, 19 Jul 2015 14:48:41 +0200 Subject: [PATCH 12/20] Add tests. --- photonui/photonui-tests.ts | 908 +++++++++++++++++++++++++++++++++++++ photonui/photonui.d.ts | 59 ++- 2 files changed, 945 insertions(+), 22 deletions(-) create mode 100644 photonui/photonui-tests.ts diff --git a/photonui/photonui-tests.ts b/photonui/photonui-tests.ts new file mode 100644 index 000000000..c86399bd9 --- /dev/null +++ b/photonui/photonui-tests.ts @@ -0,0 +1,908 @@ +/// + +// All exemple scripts from PhotonUI documentation: + +// Accel Manager +// We add a field to test accels +var field = new photonui.TextField({ + value: "Text Field" +}); +photonui.domInsert(field, "demo"); + +// ... And a label to display things +var label = new photonui.Label({text: ""}); +photonui.domInsert(label, "demo"); + +// We create the accel +var accel = new photonui.AccelManager(); + +// "Ctrl+A" / "Command+A" accelerator that is disabled if +// a field is focused +accel.addAccel("accel1", "ctrl + a", function() { + label.text += "'Ctrl + A' accelerator\n"; +}); +accel.addAccel("accel1-mac", "command + a", function() { + label.text += "'Command + A' accelerator\n"; +}); + +// "Ctrl+R" accelerator that works even if the field is focused +accel.addAccel("accel3", "ctrl + r", function() { + label.text += "'Ctrl + R' accelerator\n"; +}, false); + +// A more complexe sequence (hold "Ctrl+X", and then press "C") +accel.addAccel("accel4", "ctrl + x > c", function() { + label.text += "'Ctrl + X > C' accelerator\n"; +}); + +// BoxLayout +var box = new photonui.BoxLayout({ + orientation: "vertical", // "vertical" or "horizontal" + spacing: 5, // spacing between widgets + children: [ + new photonui.Button(), + new photonui.Button(), + new photonui.Button() + ] +}); + +photonui.domInsert(box, "demo"); + +// Button +var btn = new photonui.Button({ + text: "My Button", + leftIcon: new photonui.FAIcon("fa-send"), + callbacks: { + click: function(widget, event) { + alert("Someone clicked on " + widget.text); + } + } +}); + +photonui.domInsert(btn, "demo"); + +// canvas +var canvas = new photonui.Canvas({ + width: 200, + height: 150 +}); + +photonui.domInsert(canvas, "demo"); + +var ctx = canvas.getContext("2d"); + +ctx.lineWidth = 3; +ctx.strokeStyle = "#DB624F"; + +ctx.beginPath(); +ctx.moveTo(10, 10); +ctx.lineTo(40, 140); +ctx.lineTo(50, 30); +ctx.lineTo(190, 100); +ctx.stroke(); + +// Checkbox +var check = new photonui.CheckBox({ + value: true +}); + +photonui.domInsert(check, "demo"); + +// Color +var color = new photonui.Color("red"); + +console.log(color.hexString); +// "#FF0000" +var color = new photonui.Color("red"); + +console.log(color.hexString); +// "#FF0000" + +console.log(color.rgbString); +// "rgb(255, 0, 0)" + +console.log(color.rgbaString); +// "rgb(255, 0, 0, 1)" + +console.log(color.getRGB()); +// Array [ 255, 0, 0 ] + +console.log(color.getRGBA()); +// Array [ 255, 0, 0, 255 ] + +console.log(color.red, color.green, color.blue); +// 255 0 0 + +console.log(color.hue, color.saturation, color.brightness); +// 0 100 100 + +color.brightness = 50; +console.log(color.hexString); +// "#7F0000" + +color.hue = 204; +console.log(color.hexString); +// #004C7F + +// ColorButton +var btn2 = new photonui.ColorButton({ + value: "#4EC8DB", + callbacks: { + "value-changed": function(widget, value) { + var header = document.getElementsByTagName("header")[0]; + header.style.backgroundColor = value; + } + } +}); + +photonui.domInsert(btn2, "demo"); + +// colorpalette +var palette = new photonui.ColorPalette({ + callbacks: { + "value-changed": function(widget, value) { + var header = document.getElementsByTagName("header")[0]; + header.style.backgroundColor = value; + } + } +}); + +photonui.domInsert(palette, "demo"); + +var palette = new photonui.ColorPalette({ + palette: [ + ["#D32F2F", "#F44336", "#E91E63", "#9C27B0", "#673AB7"], + ["#3F51B5", "#2196F3", "#03A9F4", "#00BCD4", "#009688"], + ["#4CAF50", "#8BC34A", "#CDDC39", "#FFEB3B", "#FFC107"], + ["#FF9800", "#FF5722", "#795548", "#9E9E9E", "#607D8B"] + ], + callbacks: { + "value-changed": function(widget, value) { + var header = document.getElementsByTagName("header")[0]; + header.style.backgroundColor = value; + } + } +}); + +photonui.domInsert(palette, "demo"); + +// ColorPicker +var colorPicker = new photonui.ColorPicker({ + value: "#4EC8DB", + callbacks: { + "value-changed": function(widget, value) { + var header = document.getElementsByTagName("header")[0]; + header.style.backgroundColor = value; + } + } +}); + +photonui.domInsert(colorPicker, "demo"); + +// ColorPickerDialog +var dlg = new photonui.ColorPickerDialog({ + value: "#4EC8DB", + callbacks: { + "value-changed": function(widget, value) { + var header = document.getElementsByTagName("header")[0]; + header.style.backgroundColor = value; + } + } +}); + +// Add a button to show up the dialog +var btn = new photonui.Button({ + text: "Display the dialog", + callbacks: { + click: dlg.show.bind(dlg) + } +}); + +photonui.domInsert(btn, "demo"); + +// Dialog +var pos = photonui.Helpers.getAbsolutePosition("demo"); + +new photonui.Dialog({ + title: "My Dialog", + visible: true, + x: pos.x, y: pos.y, + child: new photonui.Label("Hello, I'm a dialog"), + padding: 10, + buttons: [ + new photonui.Button() + ], + callbacks: { + "close-button-clicked": function(widget) { + widget.destroy(); + } + } +}); + +// FAIcon +var icon = new photonui.FAIcon({ + iconName: "fa-camera", + size: "fa-3x", // "", "fa-lg", "fa-2x", "fa-3x", "fa-4x", "fa5x" + color: "#DB624F" +}); + +photonui.domInsert(icon, "demo"); + +// FileManager +// File manager that accepts PNG, JPEG, BMP and SVG files +var fm = new photonui.FileManager({ + acceptedMimes: ["image/png", "image/jpeg"], + acceptedExts: ["bmp", "svg"], + dropZone: document, // Enable file d&d + multiselect: true, // Allow to select more than one file + callbacks: { + "file-open": function(widget, file, x, y) { + // x and y are defined only with d&d + if (x !== undefined) { + alert(file.name + " dropped at ("+x+", "+y+")"); + } + else { + alert(file.name + " opened"); + } + } + } +}); + +// Button to show the "file open" dialog +var btn = new photonui.Button({ + text: "Open", + callbacks: { + click: function(widget, event) { + fm.open(); + } + } +}); + +photonui.domInsert(btn, "demo"); + +// FluidLayout +var fl = new photonui.FluidLayout({ + children: [ + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button() + ] +}); + +photonui.domInsert(fl, "demo"); + +// FontSelect +var select = new photonui.FontSelect({ + value: "item1", + fonts: [ + "Arial", + "Arial Black", + "Cantarell", + "Courier New", + "Impact", + "Time New Roman", + "Titillium Web", + "Verdana" + ], + callbacks: { + "value-changed": function(widget, value) { + alert("Value changed: " + value); + } + } +}); + +photonui.domInsert(select, "demo"); + +// GridLayout +var grid = new photonui.GridLayout({ + horizontalPadding: 0, + verticalPadding: 0, + horizontalSpacing: 5, + verticalSpacing: 5, + children: [ + new photonui.Button({ + text: "Widget 1", + layoutOptions: { + x: 0, y: 0, + cols: 1, rows: 1 + } + }), + new photonui.Button({ + text: "Widget 2", + layoutOptions: { + x: 1, y: 0, + cols: 1, rows: 1 + } + }), + new photonui.Button({ + text: "Widget 3", + layoutOptions: { + x: 2, y: 0, + cols: 1, rows: 2 + } + }), + new photonui.Button({ + text: "Widget 4", + layoutOptions: { + x: 0, y: 1, + cols: 2, rows: 1 + } + }) + ] +}); + +photonui.domInsert(grid, "demo"); + +// Image +var img = new photonui.Image({ + url: "../../images/favicon.png" +}); + +photonui.domInsert(img, "demo"); + +// Label +var label = new photonui.Label({ + text: "My Label", + textAlign: "left" +}); + +photonui.domInsert(label, "demo"); + +// Menu +var menu = new photonui.Menu({ + iconVisible: true, + children: [ + new photonui.MenuItem({ + text: "Menu Item 1", + icon: new photonui.FAIcon("fa-paper-plane") + }), + new photonui.MenuItem({ + text: "Menu Item 2", + icon: new photonui.FAIcon("fa-gears") + }), + new photonui.MenuItem({ + text: "Menu Item 3", + icon: new photonui.FAIcon("fa-paw") + }) + ] +}); + +photonui.domInsert(menu, "demo"); + +// MenuItem +var menu = new photonui.Menu({ + iconVisible: true, + children: [ + new photonui.MenuItem({ + text: "Menu Item 1", + icon: new photonui.FAIcon("fa-paper-plane"), + callbacks: { + click: function(widget, event) { + alert("You clicked on me!"); + } + } + }), + new photonui.MenuItem({ + text: "Menu Item 2", + icon: new photonui.FAIcon("fa-gears") + }), + new photonui.MenuItem({ + text: "Menu Item 3", + icon: new photonui.FAIcon("fa-paw") + }) + ] +}); + +photonui.domInsert(menu, "demo"); + +// Mouse Manager +var img = new photonui.Image({ + url: "../../images/favicon.png" +}); + +var mouse = new photonui.MouseManager({ + element: img, + callbacks: { + "click": function(manager, mstate) { + alert("You clicked on the image at " + + mstate.x + ", " + mstate.y); + } + } +}); + +photonui.domInsert(img, "demo"); + +// Numeric Filed +var field2 = new photonui.NumericField({ + placeholder: "placeholder", + decimalDigits: 2, + min: -10, max: 10, + step: 0.5, // When scrolling over the field + decimalSymbol: ".", // "." or "," + value: 5.5 +}); + +photonui.domInsert(field2, "demo"); + +// PopupMenu +var pos = photonui.Helpers.getAbsolutePosition("demo"); + +var popup = new photonui.PopupMenu({ + children: [ + new photonui.MenuItem({ + text: "Menu Item 1", + icon: new photonui.FAIcon("fa-paper-plane"), + callbacks: { + click: function(widget, event) { + alert("You clicked on me!"); + } + } + }), + new photonui.MenuItem({ + text: "Menu Item 2", + icon: new photonui.FAIcon("fa-gears") + }), + new photonui.MenuItem({ + text: "Menu Item 3", + icon: new photonui.FAIcon("fa-paw") + }) + ] +}); + +popup.popupXY(pos.x, pos.y); + +// PopupWindow +var pos = photonui.Helpers.getAbsolutePosition("demo"); + +var popup = new photonui.PopupWindow({ + padding: 10, + width: 200, + height: 200, + child: new photonui.Label({ + text: "Click anywhere to close" + }) +}); + +popup.popupXY(pos.x, pos.y); + +// ProgressBar +var pb = new photonui.ProgressBar({ + textVisible: true, + value: 0.42 +}); + +photonui.domInsert(pb, "demo"); + +// Select +var select2 = new photonui.Select({ + value: "item1", + children: [ + new photonui.MenuItem({value: "item1", text: "Item 1"}), + new photonui.MenuItem({value: "item2", text: "Item 2"}), + new photonui.MenuItem({value: "item3", text: "Item 3"}) + ], + callbacks: { + "value-changed": function(widget, value) { + alert("Value changed: " + value); + } + } +}); + +photonui.domInsert(select2, "demo"); + +// Separator +var separator = new photonui.Separator(); + +photonui.domInsert(separator, "demo"); + +// Slider +var box = new photonui.BoxLayout({ + children: [ + new photonui.Slider({ + fieldVisible: false, + min: 0, max: 100, + step: 5, + value: 50 + }), + new photonui.Slider({ + fieldVisible: true, + min: -100, max: 100, + step: 10, + value: -50 + }), + new photonui.Slider({ + fieldVisible: true, + min: 0, max: 1, + decimalDigits: 2, + decimalSymbol: ".", + step: 0.05, + value: 0.5 + }) + ] +}); + +photonui.domInsert(box, "demo"); + +// SpriteIcon +// Create the spritesheet +var spriteSheet = new photonui.SpriteSheet({ + name: "default", + imageUrl: "./spritesheet.png", + size: 16, + icons: { + "remove": [ 0, 0], + "add": [16, 0], + "grayHeart": [32, 0], + "redHeart": [48, 0], + "battery1": [ 0, 16], + "battery2": [16, 16], + "battery3": [32, 16], + "battery4": [48, 16] + } +}); + +// Create an icon from the spritesheet +var icon2 = new photonui.SpriteIcon("default/redHeart"); + +photonui.domInsert(icon2, "demo"); + +// SubMenuItem +var menu = new photonui.Menu({ + iconVisible: true, + children: [ + new photonui.SubMenuItem({ + text: "Submenu Item", + menuName: "submenu1", + icon: new photonui.FAIcon("fa-paw") + }), + new photonui.Menu({ + visible: true, // false to hide it by default + name: "submenu1", + iconVisible: true, + children: [ + new photonui.MenuItem({ + text: "Submenu Item 1", + icon: new photonui.FAIcon("fa-gamepad") + }), + new photonui.MenuItem({ + text: "Sumbenu Item 2", + icon: new photonui.FAIcon("fa-flask") + }) + ] + }) + ] +}); + +photonui.domInsert(menu, "demo"); + +// Switch +var sw = new photonui.Switch({ + value: true +}); + +photonui.domInsert(sw, "demo"); + +// TabItem +var tabs = new photonui.TabLayout({ + tabsPosition: "top", // "top", "bottom", "left" or "right" + children: [ + new photonui.TabItem({ + title: "Tab 1", + child: new photonui.Label("Widget inside the first tab") + }), + new photonui.TabItem({ + title: "Tab 2", + child: new photonui.Button() + }), + new photonui.TabItem({ + title: "Tab 3" + }) + ] +}); + +photonui.domInsert(tabs, "demo"); +document.getElementById("demo") + .className += " photonui-container-expand-child"; + +// TabLayout +var tabs = new photonui.TabLayout({ + tabsPosition: "top", // "top", "bottom", "left" or "right" + children: [ + new photonui.TabItem({ + title: "Tab 1", + child: new photonui.Label("Widget inside the first tab") + }), + new photonui.TabItem({ + title: "Tab 2", + child: new photonui.Button() + }), + new photonui.TabItem({ + title: "Tab 3" + }) + ] +}); + +photonui.domInsert(tabs, "demo"); +document.getElementById("demo") + .className += " photonui-container-expand-child"; + +// Text +var text = new photonui.Text({ + rawHtml: "Lorem ipsum dolor sit amet..." +}); + +photonui.domInsert(text, "demo"); + +// TextAreaField +var field3 = new photonui.TextAreaField({ + placeholder: "placeholder", + value: "This is a\nTextArea" +}); + +photonui.domInsert(field3, "demo"); + +// TextField +var field = new photonui.TextField({ + placeholder: "placeholder", + value: "Text" +}); + +photonui.domInsert(field, "demo"); + +var grid = new photonui.GridLayout({ + verticalSpacing: 5, + horizontalSpacing: 5, + children: [ + new photonui.Label({ + text: "Username:", + forInputName: "username-field", + layoutOptions: { + gridX: 0, + gridY: 0 + } + }), + new photonui.TextField({ + name: "username-field", + placeholder: "Username", + value: "Anakin", + layoutOptions: { + gridX: 1, + gridY: 0 + } + }), + new photonui.Label({ + text: "Password:", + forInputName: "password-field", + layoutOptions: { + gridX: 0, + gridY: 1 + } + }), + new photonui.TextField({ + name: "password-field", + type: "password", + placeholder: "password", + value: "D4RK51D3", + layoutOptions: { + gridX: 1, + gridY: 1 + } + }), + new photonui.Button({ + text: "Login", + leftIcon: new photonui.FAIcon("fa-sign-in"), + callbacks: { + click: function(widget, event) { + var usernameField = photonui.getWidget("username-field"); + var passwordField = photonui.getWidget("password-field"); + alert( + "Username: " + (usernameField).value + + ", Password: " + (passwordField).value + ); + } + }, + layoutOptions: { + gridX: 0, + gridY: 2, + gridWidth: 2 + } + }) + ] +}); + +photonui.domInsert(grid, "demo"); + +// ToggleButton +var toggle = new photonui.ToggleButton({ + value: false, + text: "Toggle Button" +}); + +photonui.domInsert(toggle, "demo"); + +var toggle2 = new photonui.ToggleButton({ + value: false, + text: "Value: off", + buttonColor: "red", + callbacks: { + "value-changed": function(widget, value) { + widget.text = "Value: " + ((value) ? "on" : "off"); + widget.buttonColor = (value) ? "green" : "red"; + } + } +}); + +photonui.domInsert(toggle2, "demo"); + +// Translation +var translation = new photonui.Translation(); + +translation.addCatalogs({ + "fr": { + "messages": { + "Hello World": ["Bonjour le monde"] + } + } +}); + +translation.locale = "fr"; // Change the locale to test + +var label = new photonui.Label({ + text: _("Hello World"), + text2: translation.lazyGettext("Hello World") +}); + +photonui.domInsert(label, "demo"); + +var tr = new photonui.Translation(); +tr.addCatalogs({ + "fr": { + "plural-forms": "nplurals=2; plural=(n > 1);", + "messages": { + "Hello World": ["Bonjour le monde"], + 'Browser language is "{lang}".': ["La langue du navigateur est « {lang} »."], + "Close": ["Fermer"] + } + }, + "it": { + "plural-forms": "nplurals=2; plural=(n != 1);", + "messages": { + "Hello World": ["Buongiorno il mondo"], + 'Browser language is "{lang}".': ['La lingua del browser è "{lang}".'], + "Close": ["Chiudere"] + } + } +}); +tr.locale = tr.guessUserLanguage(); // Browser language + +// Language selector +var layout = new photonui.BoxLayout({ + orientation: "vertical", + children: [ + new photonui.Label({ + text: _('Browser language is "{lang}".', { + lang: tr.guessUserLanguage() + }) + }), + new photonui.Select({ + name: "lang", + placeholder: "Choose a language...", + value: tr.locale, + children: [ + new photonui.MenuItem({value: "en", text: "English"}), + new photonui.MenuItem({value: "fr", text: "Français"}), + new photonui.MenuItem({value: "it", text: "Italiano"}), + ], + callbacks: { + "value-changed": function(widget, value) { + tr.locale = value; + } + } + }) + ] +}); +photonui.domInsert(layout, "demo"); + +// A window +var pos = photonui.Helpers.getAbsolutePosition("demo"); +var win = new photonui.Window({ + visible: true, + title: _("Hello World"), + x: pos.x, y: pos.y + 100, + width: 250, + padding: 20, + child: new photonui.Button({ + text: _("Close"), + callbacks: { + "click": function() { win.hide(); } + } + }), + callbacks: { + "close-button-clicked": function(widget) { widget.hide(); } + } +}); + +// Viewport +var viewport = new photonui.Viewport({ + width: 300, + height: 200, + padding: 5, + horizontalScrollbar: false, // true, false or null (= auto) + verticalScrollbar: null, // true, false or null (= auto) + child: new photonui.BoxLayout({ + children: [ + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button(), + new photonui.Button() + ] + }) +}); + +photonui.domInsert(viewport, "demo"); + +// Window +var pos = photonui.Helpers.getAbsolutePosition("demo"); + +new photonui.Window({ + title: "My Window", + visible: true, + x: pos.x, y: pos.y, + width: 300, height: 100, + callbacks: { + "close-button-clicked": function(widget) { + widget.destroy(); + }, + "position-changed": function(widget, x, y) { + widget.title = "My Window (x: " + x + ", y: " + y + ")"; + } + } +}); + +// Get the position of the #demo area to display windows +// in the right place +var pos = photonui.Helpers.getAbsolutePosition("demo"); + +// Create a window with a button to center it (x axis) on the page +var win1 = new photonui.Window({ + title: "Window 1", + visible: true, + padding: 10, + x: pos.x + 20, y: pos.y + 50, + child: new photonui.Button({ + text: "Center Me", + callbacks: { + click: function(widget, event) { + win1.center(); + win1.y = pos.y; + } + } + }), + callbacks: { + "close-button-clicked": function(widget) { + widget.destroy(); + } + } +}); + +// Create a second window without "close" button +var win2 = new photonui.Window({ + title: "Window 2", + visible: true, + height: 100, + closeButtonVisible: false, + x: pos.x, y: pos.y +}); + +// Focus the first window +win1.show(); diff --git a/photonui/photonui.d.ts b/photonui/photonui.d.ts index b505909ac..dda3620cf 100644 --- a/photonui/photonui.d.ts +++ b/photonui/photonui.d.ts @@ -3,9 +3,18 @@ // Definitions by: Florent Poujol // Definitions: https://github.com/borisyankov/DefinitelyTyped -module photonui { +declare module photonui { + // Base + module Helpers { + function escapeHtml(string: string); + function uuid4(): string; + function cleanNode(node: HTMLElement); + function getAbsolutePosition(element: HTMLElement|string): { x: number, y: number }; + function numberToCssSize(value: number, defaultValue?: number, nullValue?: string): string; + } + class Base { - constructor(params?: any); + constructor(params?: { [key: string]: any }); destroy(); registerCallback(id: string, wEvent: string, callback: Function, thisArg: any); removeCallback(id: string); @@ -32,11 +41,11 @@ module photonui { removeClass(className: string); static getWidget(name: string): Widget; - static domInsert(widget: Widget, element: HTMLElement); + static domInsert(widget: Widget, element?: HTMLElement|string); } // Methods - function domInsert(widget: Widget, element: HTMLElement); + function domInsert(widget: Widget, element?: HTMLElement|string); function getWidget(name: string): Widget; //Widgets @@ -52,21 +61,22 @@ module photonui { class Translation extends Base { locale: string; - addCatalogs(catalogs: any); // Stone.js catalogs + addCatalogs(catalogs: { [key: string]: any }); guessUserLanguage(): string; - gettext(string: string, replacements: any): string; - lazyGettext(string: string, replacements: any): string; + gettext(string: string, replacements?: { [key: string]: string }): string; + lazyGettext(string: string, replacements?: { [key: string]: string }): string; enableDomScan(enable: boolean); updateDomTranslation(); } class AccelManager extends Base { - addAccel(id: string, keys: string, callback: Function, safe: boolean); + addAccel(id: string, keys: string, callback: Function, safe?: boolean); removeAccel(id: string); } class MouseManager extends Base { - constructor(element?: Widget|HTMLElement, params?: any) ; + constructor(params?: { [key: string]: any }); + constructor(element?: Widget|HTMLElement, params?: { [key: string]: any }); element: HTMLElement; threshold: number; @@ -89,8 +99,8 @@ module photonui { class BaseIcon extends Widget {} class FAIcon extends BaseIcon { - constructor(params?: any); - constructor(name: string, params?: any); + constructor(params?: { [key: string]: any }); + constructor(name: string, params?: { [key: string]: any }); color: string; iconName: string; @@ -98,8 +108,8 @@ module photonui { } class SpriteIcon extends BaseIcon { - constructor(params?: any); - constructor(name: string, params?: any); + constructor(params?: { [key: string]: any }); + constructor(name: string, params?: { [key: string]: any }); icon: string; iconName: string; @@ -144,8 +154,8 @@ module photonui { } class Label extends Widget { - constructor(params?: any); - constructor(name: string, params?: any); + constructor(params?: { [key: string]: any }); + constructor(name: string, params?: { [key: string]: any }); forInput: Field|CheckBox; forInputName: string; @@ -200,6 +210,9 @@ module photonui { // ----------------------------------- class Color extends Base { + constructor(color: string); + constructor(params?: { [key: string]: any }); + hexString: string; rgbString: string; // readonly rgbaString: string; // readonly @@ -213,10 +226,10 @@ module photonui { saturation: number; brightness: number; - setRBG(red: number, green: number, blue: number); - getRBG(): number[]; - setRBGA(red: number, green: number, blue: number, alpha: number); - getRBGA(): number[]; + setRGB(red: number, green: number, blue: number); + getRGB(): number[]; + setRGBA(red: number, green: number, blue: number, alpha: number); + getRGBA(): number[]; setHSB(hue: number, saturation: number, brightness: number); } @@ -264,7 +277,7 @@ module photonui { // ----------------------------------- class Select extends Widget { - children: Widgets[]; + children: Widget[]; childrenNames: string[]; iconVisible: boolean; placeholder: string; @@ -396,8 +409,8 @@ module photonui { buttons: Widget[]; buttonNames: string[]; - addButton(widget: widget, layoutOptions: any); - removeButton(widget: widget); + addButton(widget: Widget, layoutOptions: any); + removeButton(widget: Widget); } class ColorPickerDialog extends Dialog { @@ -418,3 +431,5 @@ module photonui { tabsPosition: string; // top, bottom, left, right } } + +declare function _(string: string, replacements?: { [key: string]: string }): string; // alias of Translation.lazyGettext() From 9b4dfcf8d8f234b8e1cf97e0a95d51e90d39c67e Mon Sep 17 00:00:00 2001 From: Shogo Iwano Date: Sun, 19 Jul 2015 21:56:28 +0900 Subject: [PATCH 13/20] Add path-exists definitions --- path-exists/path-exists-tests.ts | 8 ++++++++ path-exists/path-exists.d.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 path-exists/path-exists-tests.ts create mode 100644 path-exists/path-exists.d.ts diff --git a/path-exists/path-exists-tests.ts b/path-exists/path-exists-tests.ts new file mode 100644 index 000000000..bb9bdc321 --- /dev/null +++ b/path-exists/path-exists-tests.ts @@ -0,0 +1,8 @@ +/// + +import pathExists = require("path-exists"); + +pathExists("test/path-exists.d.ts", (error, exists) => { + console.log(exists); +}); +console.log(pathExists.sync("test/__path-exists.d.ts")); diff --git a/path-exists/path-exists.d.ts b/path-exists/path-exists.d.ts new file mode 100644 index 000000000..266ab66e5 --- /dev/null +++ b/path-exists/path-exists.d.ts @@ -0,0 +1,14 @@ +// Type definitions for path-exists 1.0.0 +// Project: https://github.com/sindresorhus/path-exists +// Definitions by: Shogo Iwano +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "path-exists" { + interface PathExists { + (path: string, callback: (error: Error, exists: boolean) => void): void; + sync(path: string): boolean; + } + + var pathExists: PathExists; + export = pathExists; +} From 8b4142e21e03dcde37537bedbbaa909e35a56e9a Mon Sep 17 00:00:00 2001 From: Florent Poujol Date: Sun, 19 Jul 2015 15:22:32 +0200 Subject: [PATCH 14/20] Remove all implicit any. --- photonui/photonui-tests.ts | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/photonui/photonui-tests.ts b/photonui/photonui-tests.ts index c86399bd9..3242d3a92 100644 --- a/photonui/photonui-tests.ts +++ b/photonui/photonui-tests.ts @@ -53,7 +53,7 @@ var btn = new photonui.Button({ text: "My Button", leftIcon: new photonui.FAIcon("fa-send"), callbacks: { - click: function(widget, event) { + click: function(widget: any, event: any) { alert("Someone clicked on " + widget.text); } } @@ -128,7 +128,7 @@ console.log(color.hexString); var btn2 = new photonui.ColorButton({ value: "#4EC8DB", callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { var header = document.getElementsByTagName("header")[0]; header.style.backgroundColor = value; } @@ -140,7 +140,7 @@ photonui.domInsert(btn2, "demo"); // colorpalette var palette = new photonui.ColorPalette({ callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { var header = document.getElementsByTagName("header")[0]; header.style.backgroundColor = value; } @@ -157,7 +157,7 @@ var palette = new photonui.ColorPalette({ ["#FF9800", "#FF5722", "#795548", "#9E9E9E", "#607D8B"] ], callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { var header = document.getElementsByTagName("header")[0]; header.style.backgroundColor = value; } @@ -170,7 +170,7 @@ photonui.domInsert(palette, "demo"); var colorPicker = new photonui.ColorPicker({ value: "#4EC8DB", callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { var header = document.getElementsByTagName("header")[0]; header.style.backgroundColor = value; } @@ -183,7 +183,7 @@ photonui.domInsert(colorPicker, "demo"); var dlg = new photonui.ColorPickerDialog({ value: "#4EC8DB", callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { var header = document.getElementsByTagName("header")[0]; header.style.backgroundColor = value; } @@ -213,7 +213,7 @@ new photonui.Dialog({ new photonui.Button() ], callbacks: { - "close-button-clicked": function(widget) { + "close-button-clicked": function(widget: any) { widget.destroy(); } } @@ -236,7 +236,7 @@ var fm = new photonui.FileManager({ dropZone: document, // Enable file d&d multiselect: true, // Allow to select more than one file callbacks: { - "file-open": function(widget, file, x, y) { + "file-open": function(widget: any, file: any, x: number, y: number) { // x and y are defined only with d&d if (x !== undefined) { alert(file.name + " dropped at ("+x+", "+y+")"); @@ -252,7 +252,7 @@ var fm = new photonui.FileManager({ var btn = new photonui.Button({ text: "Open", callbacks: { - click: function(widget, event) { + click: function(widget: any, event: any) { fm.open(); } } @@ -289,7 +289,7 @@ var select = new photonui.FontSelect({ "Verdana" ], callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { alert("Value changed: " + value); } } @@ -381,7 +381,7 @@ var menu = new photonui.Menu({ text: "Menu Item 1", icon: new photonui.FAIcon("fa-paper-plane"), callbacks: { - click: function(widget, event) { + click: function(widget: any, event: any) { alert("You clicked on me!"); } } @@ -407,7 +407,7 @@ var img = new photonui.Image({ var mouse = new photonui.MouseManager({ element: img, callbacks: { - "click": function(manager, mstate) { + "click": function(manager: any, mstate: any) { alert("You clicked on the image at " + mstate.x + ", " + mstate.y); } @@ -437,7 +437,7 @@ var popup = new photonui.PopupMenu({ text: "Menu Item 1", icon: new photonui.FAIcon("fa-paper-plane"), callbacks: { - click: function(widget, event) { + click: function(widget: any, event: any) { alert("You clicked on me!"); } } @@ -486,7 +486,7 @@ var select2 = new photonui.Select({ new photonui.MenuItem({value: "item3", text: "Item 3"}) ], callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { alert("Value changed: " + value); } } @@ -696,7 +696,7 @@ var grid = new photonui.GridLayout({ text: "Login", leftIcon: new photonui.FAIcon("fa-sign-in"), callbacks: { - click: function(widget, event) { + click: function(widget: any, event: any) { var usernameField = photonui.getWidget("username-field"); var passwordField = photonui.getWidget("password-field"); alert( @@ -729,7 +729,7 @@ var toggle2 = new photonui.ToggleButton({ text: "Value: off", buttonColor: "red", callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { widget.text = "Value: " + ((value) ? "on" : "off"); widget.buttonColor = (value) ? "green" : "red"; } @@ -798,7 +798,7 @@ var layout = new photonui.BoxLayout({ new photonui.MenuItem({value: "it", text: "Italiano"}), ], callbacks: { - "value-changed": function(widget, value) { + "value-changed": function(widget: any, value: any) { tr.locale = value; } } @@ -822,7 +822,7 @@ var win = new photonui.Window({ } }), callbacks: { - "close-button-clicked": function(widget) { widget.hide(); } + "close-button-clicked": function(widget: any) { widget.hide(); } } }); @@ -860,10 +860,10 @@ new photonui.Window({ x: pos.x, y: pos.y, width: 300, height: 100, callbacks: { - "close-button-clicked": function(widget) { + "close-button-clicked": function(widget: any) { widget.destroy(); }, - "position-changed": function(widget, x, y) { + "position-changed": function(widget: any, x: number, y: number) { widget.title = "My Window (x: " + x + ", y: " + y + ")"; } } @@ -882,14 +882,14 @@ var win1 = new photonui.Window({ child: new photonui.Button({ text: "Center Me", callbacks: { - click: function(widget, event) { + click: function(widget: any, event: any) { win1.center(); win1.y = pos.y; } } }), callbacks: { - "close-button-clicked": function(widget) { + "close-button-clicked": function(widget: any) { widget.destroy(); } } From 33628658d2c83ea246bb030238dfa85576027fda Mon Sep 17 00:00:00 2001 From: Florent Poujol Date: Sun, 19 Jul 2015 15:23:15 +0200 Subject: [PATCH 15/20] Fix indentation. Remove add all explicit void return type. --- photonui/photonui.d.ts | 840 ++++++++++++++++++++--------------------- 1 file changed, 420 insertions(+), 420 deletions(-) diff --git a/photonui/photonui.d.ts b/photonui/photonui.d.ts index dda3620cf..973b241bd 100644 --- a/photonui/photonui.d.ts +++ b/photonui/photonui.d.ts @@ -1,435 +1,435 @@ -// Type definitions for PhotonUI 1.0.0 +// Type definitions for PhotonUI v1.0.0 // Project: https://github.com/wanadev/PhotonUI // Definitions by: Florent Poujol // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module photonui { - // Base - module Helpers { - function escapeHtml(string: string); - function uuid4(): string; - function cleanNode(node: HTMLElement); - function getAbsolutePosition(element: HTMLElement|string): { x: number, y: number }; - function numberToCssSize(value: number, defaultValue?: number, nullValue?: string): string; - } + // Base + module Helpers { + function escapeHtml(string: string): void; + function uuid4(): string; + function cleanNode(node: HTMLElement): void; + function getAbsolutePosition(element: HTMLElement|string): { x: number; y: number }; + function numberToCssSize(value: number, defaultValue?: number, nullValue?: string): string; + } - class Base { - constructor(params?: { [key: string]: any }); - destroy(); - registerCallback(id: string, wEvent: string, callback: Function, thisArg: any); - removeCallback(id: string); - } + class Base { + constructor(params?: { [key: string]: any }); + destroy(): void; + registerCallback(id: string, wEvent: string, callback: Function, thisArg: any): void; + removeCallback(id: string): void; + } - class Widget extends Base { - absolutePosition: { x: number; y: number; }; // readonly - contextMenu: PopupWindow; - contextMenuName: string; - html: HTMLElement; // readonly - layoutOptions: { [key: string]: any }; - name: string; - offsetWidth: number; // readonly - offsetHeight: number; // readonly - parent: Widget; - parentName: string; - tooltip: string; - visible: boolean; + class Widget extends Base { + absolutePosition: { x: number; y: number; }; // readonly + contextMenu: PopupWindow; + contextMenuName: string; + html: HTMLElement; // readonly + layoutOptions: { [key: string]: any }; + name: string; + offsetWidth: number; // readonly + offsetHeight: number; // readonly + parent: Widget; + parentName: string; + tooltip: string; + visible: boolean; - show(); - hide(); - unparent(); - addClass(className: string); - removeClass(className: string); + show(): void; + hide(): void; + unparent(): void; + addClass(className: string): void; + removeClass(className: string): void; - static getWidget(name: string): Widget; - static domInsert(widget: Widget, element?: HTMLElement|string); - } + static getWidget(name: string): Widget; + static domInsert(widget: Widget, element?: HTMLElement|string): void; + } - // Methods - function domInsert(widget: Widget, element?: HTMLElement|string); - function getWidget(name: string): Widget; + // Methods + function domInsert(widget: Widget, element?: HTMLElement|string): void; + function getWidget(name: string): Widget; - //Widgets - class FileManager extends Base { - acceptedExts: string[]; - acceptedMimes: string[]; - dropZone: HTMLElement; - multiselect: boolean; + //Widgets + class FileManager extends Base { + acceptedExts: string[]; + acceptedMimes: string[]; + dropZone: HTMLElement; + multiselect: boolean; + + open(): void; + } + + class Translation extends Base { + locale: string; + + addCatalogs(catalogs: { [key: string]: any }): void; + guessUserLanguage(): string; + gettext(string: string, replacements?: { [key: string]: string }): string; + lazyGettext(string: string, replacements?: { [key: string]: string }): string; + enableDomScan(enable: boolean): void; + updateDomTranslation(): void; + } + + class AccelManager extends Base { + addAccel(id: string, keys: string, callback: Function, safe?: boolean): void; + removeAccel(id: string): void; + } + + class MouseManager extends Base { + constructor(params?: { [key: string]: any }); + constructor(element?: Widget|HTMLElement, params?: { [key: string]: any }); + + element: HTMLElement; + threshold: number; + + action: string; // readonly + btnLeft: boolean; // readonly + btnMiddle: boolean; // readonly + btnRight: boolean; // readonly + button: string; // readonly + pageX: number; // readonly + pageY: number; // readonly + x: number; // readonly + y: number; // readonly + deltaX: number; // readonly + deltaY: number; // readonly + } + + // ----------------------------------- + + class BaseIcon extends Widget {} + + class FAIcon extends BaseIcon { + constructor(params?: { [key: string]: any }); + constructor(name: string, params?: { [key: string]: any }); + + color: string; + iconName: string; + size: string; + } + + class SpriteIcon extends BaseIcon { + constructor(params?: { [key: string]: any }); + constructor(name: string, params?: { [key: string]: any }); + + icon: string; + iconName: string; + spriteSheetName: string; + } + + // ----------------------------------- + + class Image extends Widget { + width: number; + height: number; + url: string; + } + + class SpriteSheet extends Base { + name: string; + imageUrl: string; + size: string; + icons: { [iconName: string]: number[] }; + + addIcon(iconName: string, x: number, y: number): void; + removeIcon(iconName: string): void; + getIconPosition(iconName: string): { x: number; y: number; }; + getIconCSS(iconName: string): string; + + static getSpriteSheet(name: string): SpriteSheet; + } + + class Canvas extends Widget { + canvas: HTMLElement; + interactiveMode: HTMLElement; + width: number; + height: number; + getContext(contextId: string): any; + setContext(contextId: string): void; + supportsContext(contextId: string): boolean; + toBlod(imageFormat: string): any; // returns Blob + toBlodHD(imageFormat: string): any; // returns Blob + toDataUrl(imageFormat: string): string; + toDataUrlHD(imageFormat: string): string; + transferControlToProxy(): void; + } + + class Label extends Widget { + constructor(params?: { [key: string]: any }); + constructor(name: string, params?: { [key: string]: any }); + + forInput: Field|CheckBox; + forInputName: string; + text: string; + textAlign: string; + } + + class Text extends Widget { + rawHtml: string; + text: string; + } + + class ProgressBar extends Widget { + orientation: string; + pulsate: boolean; + textVisible: boolean; + value: number; + } + + class Separator extends Widget { + orientation: string; + } + + class Button extends Widget { + appearance: string; // normal | flat + buttonColor: string; + + leftIconName: string; + leftIcon: BaseIcon; + leftIconVisible: boolean; + + rightIconName: string; + rightIcon: BaseIcon; + rightIconVisible: boolean; + + text: string; + textVisible: boolean; + } + + class ColorButton extends Widget { + color: Color; + dialogOnly: boolean; + value: string; + } + + class CheckBox extends Widget { + value: boolean; + } + class Switch extends CheckBox {} + class ToggleButton extends CheckBox {} + + // ----------------------------------- + + class Color extends Base { + constructor(color: string); + constructor(params?: { [key: string]: any }); + + hexString: string; + rgbString: string; // readonly + rgbaString: string; // readonly + + red: number; + green: number; + blue: number; + alpha: number; + + hue: number; + saturation: number; + brightness: number; + + setRGB(red: number, green: number, blue: number): void; + getRGB(): number[]; + setRGBA(red: number, green: number, blue: number, alpha: number): void; + getRGBA(): number[]; + setHSB(hue: number, saturation: number, brightness: number): void; + } + + class ColorPalette extends Widget { + color: Color; + palette: Array; + value: string; + + static palette: Array; + } + + class ColorPicker extends Widget { + color: Color; + value: string; + } + + // ----------------------------------- + + class Field extends Widget { + placeholder: string; + value: boolean; + } + + class NumericField extends Field { + min: number; + max: number; + step: number; + decimalDigits: number; + decimalSymbol: string; + } + + class Slider extends NumericField { + fieldVisible: boolean; + } + + class TextAreaField extends Field { + cols: number; + rows: number; + } + + class TextField extends Field { + type: string; // text, password, email, search, tel, url + } + + // ----------------------------------- + + class Select extends Widget { + children: Widget[]; + childrenNames: string[]; + iconVisible: boolean; + placeholder: string; + popupWidth: number; + popupHeight: number; + popupMaxWidth: number; + popupMinWidth: number; + popupMaxHeight: number; + popupMinHeight: number; + popupOffsetWidth: number; // readonly + popupOffsetHeight: number; // readonly + popupPadding: number; + value: any; // string (maybe) + + addChild(widget: Widget, layoutOptions?: any): void; + } + + class FontSelect extends Select { + fonts: string[]; + + addFont(fontName: string): void; + } + + // ----------------------------------- + + class Container extends Widget { + child: Widget; + childName: string; + containerNode: HTMLElement; // readonly + horizontalChildExpansion: boolean; + verticalChildExpansion: boolean; + + removeChild(widget: Widget): void; + } + + class Layout extends Container { + children: Widget[]; + childrenNames: string[]; + + addChild(widget: Widget, layoutOptions?: { [key: string]: any }): void; + empty(): void; + } + + class BoxLayout extends Layout { + horizontalPadding: number; + verticalPadding: number; + orientation: string; + spacing: number; + } + + class FluidLayout extends Layout { + horizontalPadding: number; + verticalPadding: number; + } + + class GridLayout extends Layout { + horizontalPadding: number; + verticalPadding: number; + horizontalSpacing: number; + verticalSpacing: number; + } + + class Menu extends Layout { + iconVisible: boolean; + } + + class MenuItem extends Menu { + active: boolean; + icon: BaseIcon; + iconName: string; + text: string; + value: any; // string (maybe) + } + + class SubMenuItem extends MenuItem { + menu: Menu; + menuName: string; + } + + // ----------------------------------- + + class Viewport extends Container { + width: number; + minWidth: number; + maxWidth: number; + height: number; + minHeight: number; + maxHeight: number; + padding: number; + horizontalScrollbar: boolean; + verticalScrollbar: boolean; + } + + // ----------------------------------- - open(); - } - - class Translation extends Base { - locale: string; - - addCatalogs(catalogs: { [key: string]: any }); - guessUserLanguage(): string; - gettext(string: string, replacements?: { [key: string]: string }): string; - lazyGettext(string: string, replacements?: { [key: string]: string }): string; - enableDomScan(enable: boolean); - updateDomTranslation(); - } - - class AccelManager extends Base { - addAccel(id: string, keys: string, callback: Function, safe?: boolean); - removeAccel(id: string); - } - - class MouseManager extends Base { - constructor(params?: { [key: string]: any }); - constructor(element?: Widget|HTMLElement, params?: { [key: string]: any }); - - element: HTMLElement; - threshold: number; - - action: string; // readonly - btnLeft: boolean; // readonly - btnMiddle: boolean; // readonly - btnRight: boolean; // readonly - button: string; // readonly - pageX: number; // readonly - pageY: number; // readonly - x: number; // readonly - y: number; // readonly - deltaX: number; // readonly - deltaY: number; // readonly - } - - // ----------------------------------- - - class BaseIcon extends Widget {} - - class FAIcon extends BaseIcon { - constructor(params?: { [key: string]: any }); - constructor(name: string, params?: { [key: string]: any }); - - color: string; - iconName: string; - size: string; - } - - class SpriteIcon extends BaseIcon { - constructor(params?: { [key: string]: any }); - constructor(name: string, params?: { [key: string]: any }); - - icon: string; - iconName: string; - spriteSheetName: string; - } - - // ----------------------------------- - - class Image extends Widget { - width: number; - height: number; - url: string; - } - - class SpriteSheet extends Base { - name: string; - imageUrl: string; - size: string; - icons: { [iconName: string]: number[] }; - - addIcon(iconName: string, x: number, y: number); - removeIcon(iconName: string); - getIconPosition(iconName: string): { x: number; y: number; }; - getIconCSS(iconName: string): string; - - static getSpriteSheet(name: string): SpriteSheet; - } - - class Canvas extends Widget { - canvas: HTMLElement; - interactiveMode: HTMLElement; - width: number; - height: number; - getContext(contextId: string): any; - setContext(contextId: string); - supportsContext(contextId: string): boolean; - toBlod(imageFormat: string): any; // returns Blob - toBlodHD(imageFormat: string): any; // returns Blob - toDataUrl(imageFormat: string): string; - toDataUrlHD(imageFormat: string): string; - transferControlToProxy(); - } - - class Label extends Widget { - constructor(params?: { [key: string]: any }); - constructor(name: string, params?: { [key: string]: any }); - - forInput: Field|CheckBox; - forInputName: string; - text: string; - textAlign: string; - } - - class Text extends Widget { - rawHtml: string; - text: string; - } - - class ProgressBar extends Widget { - orientation: string; - pulsate: boolean; - textVisible: boolean; - value: number; - } - - class Separator extends Widget { - orientation: string; - } - - class Button extends Widget { - appearance: string; // normal | flat - buttonColor: string; - - leftIconName: string; - leftIcon: BaseIcon; - leftIconVisible: boolean; - - rightIconName: string; - rightIcon: BaseIcon; - rightIconVisible: boolean; - - text: string; - textVisible: boolean; - } - - class ColorButton extends Widget { - color: Color; - dialogOnly: boolean; - value: string; - } - - class CheckBox extends Widget { - value: boolean; - } - class Switch extends CheckBox {} - class ToggleButton extends CheckBox {} - - // ----------------------------------- - - class Color extends Base { - constructor(color: string); - constructor(params?: { [key: string]: any }); - - hexString: string; - rgbString: string; // readonly - rgbaString: string; // readonly - - red: number; - green: number; - blue: number; - alpha: number; - - hue: number; - saturation: number; - brightness: number; - - setRGB(red: number, green: number, blue: number); - getRGB(): number[]; - setRGBA(red: number, green: number, blue: number, alpha: number); - getRGBA(): number[]; - setHSB(hue: number, saturation: number, brightness: number); - } - - class ColorPalette extends Widget { - color: Color; - palette: Array; - value: string; - - static palette: Array; - } - - class ColorPicker extends Widget { - color: Color; - value: string; - } - - // ----------------------------------- - - class Field extends Widget { - placeholder: string; - value: boolean; - } - - class NumericField extends Field { - min: number; - max: number; - step: number; - decimalDigits: number; - decimalSymbol: string; - } - - class Slider extends NumericField { - fieldVisible: boolean; - } - - class TextAreaField extends Field { - cols: number; - rows: number; - } - - class TextField extends Field { - type: string; // text, password, email, search, tel, url - } - - // ----------------------------------- - - class Select extends Widget { - children: Widget[]; - childrenNames: string[]; - iconVisible: boolean; - placeholder: string; - popupWidth: number; - popupHeight: number; - popupMaxWidth: number; - popupMinWidth: number; - popupMaxHeight: number; - popupMinHeight: number; - popupOffsetWidth: number; // readonly - popupOffsetHeight: number; // readonly - popupPadding: number; - value: any; // string (maybe) - - addChild(widget: Widget, layoutOptions?: any); - } - - class FontSelect extends Select { - fonts: string[]; - - addFont(fontName: string); - } - - // ----------------------------------- - - class Container extends Widget { - child: Widget; - childName: string; - containerNode: HTMLElement; // readonly - horizontalChildExpansion: boolean; - verticalChildExpansion: boolean; - - removeChild(widget: Widget); - } - - class Layout extends Container { - children: Widget[]; - childrenNames: string[]; - - addChild(widget: Widget, layoutOptions?: { [key: string]: any }); - empty(); - } - - class BoxLayout extends Layout { - horizontalPadding: number; - verticalPadding: number; - orientation: string; - spacing: number; - } - - class FluidLayout extends Layout { - horizontalPadding: number; - verticalPadding: number; - } - - class GridLayout extends Layout { - horizontalPadding: number; - verticalPadding: number; - horizontalSpacing: number; - verticalSpacing: number; - } - - class Menu extends Layout { - iconVisible: boolean; - } - - class MenuItem extends Menu { - active: boolean; - icon: BaseIcon; - iconName: string; - text: string; - value: any; // string (maybe) - } - - class SubMenuItem extends MenuItem { - menu: Menu; - menuName: string; - } - - // ----------------------------------- - - class Viewport extends Container { - width: number; - minWidth: number; - maxWidth: number; - height: number; - minHeight: number; - maxHeight: number; - padding: number; - horizontalScrollbar: boolean; - verticalScrollbar: boolean; - } - - // ----------------------------------- - - class BaseWindow extends Container { - width: number; - minWidth: number; - maxWidth: number; - height: number; - minHeight: number; - maxHeight: number; - padding: number; - position: { x: number; y: number }; - x: number; - y: number; - - center(); - } - - class PopupWindow extends BaseWindow { - popupXY(x: number, y: number); - popupWidget(widget: Widget); - } - - class PopupMenu extends PopupWindow {} - - class Window extends BaseWindow { - closeButtonVisible: boolean; - modal: boolean; - movable: boolean; - title: string; - - moveToFront(); - moveToBack(); - } - - class Dialog extends Window { - buttons: Widget[]; - buttonNames: string[]; - - addButton(widget: Widget, layoutOptions: any); - removeButton(widget: Widget); - } - - class ColorPickerDialog extends Dialog { - color: Color; - } - - // ----------------------------------- - - class TabItem extends Container { - tabHtml: HTMLElement; // readonly - title: string; - } - - class TabLayout extends Layout { - activeTab: Widget; - activeTabName: string; - padding: number; - tabsPosition: string; // top, bottom, left, right - } + class BaseWindow extends Container { + width: number; + minWidth: number; + maxWidth: number; + height: number; + minHeight: number; + maxHeight: number; + padding: number; + position: { x: number; y: number }; + x: number; + y: number; + + center(): void; + } + + class PopupWindow extends BaseWindow { + popupXY(x: number, y: number): void; + popupWidget(widget: Widget): void; + } + + class PopupMenu extends PopupWindow {} + + class Window extends BaseWindow { + closeButtonVisible: boolean; + modal: boolean; + movable: boolean; + title: string; + + moveToFront(): void; + moveToBack(): void; + } + + class Dialog extends Window { + buttons: Widget[]; + buttonNames: string[]; + + addButton(widget: Widget, layoutOptions: any): void; + removeButton(widget: Widget): void; + } + + class ColorPickerDialog extends Dialog { + color: Color; + } + + // ----------------------------------- + + class TabItem extends Container { + tabHtml: HTMLElement; // readonly + title: string; + } + + class TabLayout extends Layout { + activeTab: Widget; + activeTabName: string; + padding: number; + tabsPosition: string; // top, bottom, left, right + } } declare function _(string: string, replacements?: { [key: string]: string }): string; // alias of Translation.lazyGettext() From 0bae9f2cb769947045340f4a3c6ba9a370365b7b Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 19 Jul 2015 22:24:02 +0900 Subject: [PATCH 16/20] i18next: Modify 'callback' to take two arguments. --- i18next/i18next.d.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/i18next/i18next.d.ts b/i18next/i18next.d.ts index e20cb4c93..060335af0 100644 --- a/i18next/i18next.d.ts +++ b/i18next/i18next.d.ts @@ -85,8 +85,7 @@ interface I18nextStatic { toLanguages(language: string): string[]; regexEscape(str: string): string; }; - init(callback?: (t: (key: string, options?: any) => string) => void ): JQueryDeferred; - init(options?: I18nextOptions, callback?: (t: (key: string, options?: any) => string) => void ): JQueryDeferred; + init(callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred; init(options?: I18nextOptions, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred; lng(): string; loadNamespace(namespace: string, callback?: () => void ): void; @@ -101,10 +100,9 @@ interface I18nextStatic { rules: any; setCurrentLng: (language: string) => void; }; - preload(language: string, callback?: (t: (key: string, options?: any) => string) => void ): void; - preload(languages: string[], callback?: (t: (key: string, options?: any) => string) => void ): void; + preload(language: string, callback?: (err: any, t: (key: string, options?: any) => string) => void ): void; + preload(languages: string[], callback?: (err: any, t: (key: string, options?: any) => string) => void ): void; setDefaultNamespace(namespace: string): void; - setLng(language: string, callback?: (t: (key: string, options?: any) => string) => void ): void; setLng(language: string, callback?: (err: any, t: (key: string, options?: any) => string) => void ): void; sync: { load: (languages: string[], options: I18nextOptions, callback: (err: Error, store: IResourceStore) => void ) => void; From 6b72968ffbf38d54675d22c857c66d581c372f83 Mon Sep 17 00:00:00 2001 From: Emil Ekberg Date: Sun, 19 Jul 2015 15:36:23 +0200 Subject: [PATCH 17/20] Added test cases --- webfontloader/webfontloader-tests.ts | 18 ++++++++++++++++++ webfontloader/webfontloader-tests.ts.tscparams | 1 + webfontloader/webfontloader.d.ts | 14 +++++++------- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 webfontloader/webfontloader-tests.ts create mode 100644 webfontloader/webfontloader-tests.ts.tscparams diff --git a/webfontloader/webfontloader-tests.ts b/webfontloader/webfontloader-tests.ts new file mode 100644 index 000000000..5f27ea959 --- /dev/null +++ b/webfontloader/webfontloader-tests.ts @@ -0,0 +1,18 @@ +/// +import webfontloader = require("webfontloader"); + +var config: webfontloader.Config = { + classes: false, + events: false, + loading: function() {}, + active: function() {}, + inactive: function() {}, + fontloading: function(familyName:string, fvd:string) {}, + fontactive: function(familyName:string, fvd:string) {}, + fontinactive: function(familyName:string, fvd:string) {}, + google: { + families: ['Droid Sans'] + }, + timeout: 2000 +} +webfontloader.load(config); \ No newline at end of file diff --git a/webfontloader/webfontloader-tests.ts.tscparams b/webfontloader/webfontloader-tests.ts.tscparams new file mode 100644 index 000000000..4169d3605 --- /dev/null +++ b/webfontloader/webfontloader-tests.ts.tscparams @@ -0,0 +1 @@ +--noImplicitAny --module commonjs --target es5 \ No newline at end of file diff --git a/webfontloader/webfontloader.d.ts b/webfontloader/webfontloader.d.ts index d8e354cf7..6da62cf07 100644 --- a/webfontloader/webfontloader.d.ts +++ b/webfontloader/webfontloader.d.ts @@ -3,10 +3,8 @@ // Definitions by: doskallemaskin // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare class WebFont { - static load(config:WebFont.Config); -} declare module WebFont { + export function load(config:WebFont.Config):void; export interface Config { /** Setting this to false will disable html classes (defaults to true) */ classes?:boolean; @@ -21,11 +19,11 @@ declare module WebFont { /** This event is triggered when the browser does not support linked fonts or if none of the fonts could be loaded. */ inactive?():void; /** This event is triggered once for each font that's loaded. */ - fontloading?(familyName: string, fvd):void; + fontloading?(familyName:string, fvd:string):void; /** This event is triggered once for each font that renders. */ - fontactive?(familyName: string, fvd):void; + fontactive?(familyName:string, fvd:string):void; /** This event is triggered if the font can't be loaded. */ - fontinactive?(familyName: string, fvd):void; + fontinactive?(familyName:string, fvd:string):void; /** Child window or iframes to manage fonts for */ context?:Array; @@ -46,7 +44,6 @@ declare module WebFont { families?:Array; urls?:Array; testStrings?:{[fontFamily:string]:string}; - } export interface Fontdeck { id?:string; @@ -56,4 +53,7 @@ declare module WebFont { version?:number; } +} +declare module "webfontloader" { + export = WebFont; } \ No newline at end of file From 7536f06587e518ff6301b74bd0d097d6e9b10fef Mon Sep 17 00:00:00 2001 From: Sam Saint-Pettersen Date: Sun, 19 Jul 2015 14:42:18 +0100 Subject: [PATCH 18/20] Type definitions and testsfor to-title-case-gouch --- .../to-title-case-gouch-tests.ts | 2 +- .../to-title-case-gouch.d.ts | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename to-title-case/to-title-case-tests.ts => to-title-case-gouch/to-title-case-gouch-tests.ts (77%) rename to-title-case/to-title-case.d.ts => to-title-case-gouch/to-title-case-gouch.d.ts (100%) diff --git a/to-title-case/to-title-case-tests.ts b/to-title-case-gouch/to-title-case-gouch-tests.ts similarity index 77% rename from to-title-case/to-title-case-tests.ts rename to to-title-case-gouch/to-title-case-gouch-tests.ts index 2dc1fd9f5..80f824289 100644 --- a/to-title-case/to-title-case-tests.ts +++ b/to-title-case-gouch/to-title-case-gouch-tests.ts @@ -3,7 +3,7 @@ import fs = require('fs'); -fs.readFile('to-title-case.min.js', 'utf-8', function(err: any, code: string) { +fs.readFile('to-title-case.js', 'utf-8', function(err: any, code: string) { eval(code); var lowerCase: string = 'this title is in lowercase and will be title case'; console.log(lowerCase.toTitleCase()); // Now in title case. diff --git a/to-title-case/to-title-case.d.ts b/to-title-case-gouch/to-title-case-gouch.d.ts similarity index 100% rename from to-title-case/to-title-case.d.ts rename to to-title-case-gouch/to-title-case-gouch.d.ts From a99412d02a48afdda97ce3f95e38ce5f567d1e56 Mon Sep 17 00:00:00 2001 From: Sam Saint-Pettersen Date: Sun, 19 Jul 2015 14:47:28 +0100 Subject: [PATCH 19/20] Update to-title-case-gouch-tests.ts --- to-title-case-gouch/to-title-case-gouch-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/to-title-case-gouch/to-title-case-gouch-tests.ts b/to-title-case-gouch/to-title-case-gouch-tests.ts index 80f824289..68e0a616b 100644 --- a/to-title-case-gouch/to-title-case-gouch-tests.ts +++ b/to-title-case-gouch/to-title-case-gouch-tests.ts @@ -1,5 +1,5 @@ /// -/// +/// import fs = require('fs'); From 0c9d64f93d51c53c309bab82c3c34dc048aeec06 Mon Sep 17 00:00:00 2001 From: Emil Ekberg Date: Sun, 19 Jul 2015 15:48:05 +0200 Subject: [PATCH 20/20] Added test cases --- webfontloader/webfontloader-tests.ts | 14 +++++++++++++- webfontloader/webfontloader.d.ts | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/webfontloader/webfontloader-tests.ts b/webfontloader/webfontloader-tests.ts index 5f27ea959..92711d706 100644 --- a/webfontloader/webfontloader-tests.ts +++ b/webfontloader/webfontloader-tests.ts @@ -11,7 +11,19 @@ var config: webfontloader.Config = { fontactive: function(familyName:string, fvd:string) {}, fontinactive: function(familyName:string, fvd:string) {}, google: { - families: ['Droid Sans'] + families: ['Droid Sans', 'Droid Serif:bold'], + text: 'abcdedfghijklmopqrstuvwxyz!' + }, + custom: { + families: ['My Font', 'My Other Font:n4,i4,n7'], + urls: ['/fonts.css'] + }, + fontdeck: { + id: 'xxxx' + }, + monotype: { + projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', + version: 12345 }, timeout: 2000 } diff --git a/webfontloader/webfontloader.d.ts b/webfontloader/webfontloader.d.ts index 6da62cf07..0afadfd3b 100644 --- a/webfontloader/webfontloader.d.ts +++ b/webfontloader/webfontloader.d.ts @@ -36,6 +36,7 @@ declare module WebFont { } export interface Google { families?:Array; + text: string; } export interface Typekit { id?:Array;