From 795722e0dc55a6f18a278f594a12bc4ec42d8ebe Mon Sep 17 00:00:00 2001 From: Aleksandar Manukov Date: Sat, 15 Dec 2018 17:25:11 +0200 Subject: [PATCH 1/3] Add bootstrap-colorpicker@2.5.3 --- .../bootstrap-colorpicker@2.5.3-tests.ts | 0 types/bootstrap-colorpicker@2.5.3/index.d.ts | 267 ++++++++++++++++++ .../bootstrap-colorpicker@2.5.3/tsconfig.json | 22 ++ types/bootstrap-colorpicker@2.5.3/tslint.json | 1 + 4 files changed, 290 insertions(+) create mode 100644 types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts create mode 100644 types/bootstrap-colorpicker@2.5.3/index.d.ts create mode 100644 types/bootstrap-colorpicker@2.5.3/tsconfig.json create mode 100644 types/bootstrap-colorpicker@2.5.3/tslint.json diff --git a/types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts b/types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/types/bootstrap-colorpicker@2.5.3/index.d.ts b/types/bootstrap-colorpicker@2.5.3/index.d.ts new file mode 100644 index 0000000000..222b939b89 --- /dev/null +++ b/types/bootstrap-colorpicker@2.5.3/index.d.ts @@ -0,0 +1,267 @@ +// Type definitions for bootstrap-colorpicker 2.5.3 +// Project: https://github.com/farbelous/bootstrap-colorpicker/tree/v2.x +// Definitions by: Aleksandar Manukov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +type ColorPickerAlignOptions = 'right' | 'left'; + +type ColorPickerEvents = 'create' | + 'showPicker' | + 'hidePicker' | + 'changeColor' | + 'disable' | + 'enable' | + 'destroy' + +/** + * You can set colorpicker options either as a plugin parameter or data-* attributes + */ +interface ColorPickerOptions { + /** + * If not false, forces the color format to be hex, rgb or rgba, otherwise the format is automatically detected. + * + * Default: false + */ + format: string; + + /** + * If not false, sets the color to this value. + * + * Default: false + */ + color: string; + + /** + * If not false, the picker will be contained inside this element, otherwise it will be appended to the document body. + * + * Default: false + */ + container: string | JQuery; + + /** + * Children selector for the component or element that trigger the colorpicker and which background color will change (needs an inner element). + * + * Default: '.add-on, .input-group-addon' + */ + component: string | JQuery; + + /** + * Children selector for the input that will store the picker selected value. + * + * Default: 'input' + */ + input: string | JQuery; + + /** + * If true, put a '#' (number sign) before hex strings. + * + * Default: true + */ + hexNumberSignPrefix: boolean; + + /** + * If true, the hue and alpha channel bars will be rendered horizontally, above the saturation selector. + * + * Default: false + */ + horizontal: boolean; + + /** + * If true, forces to show the colorpicker as an inline element. + * + * Default: false + */ + inline: boolean; + + /** + * Vertical sliders configuration (read source code if you really need to tweak this). + */ + sliders: object; + + /** + * Horizontal sliders configuration (read source code if you really need to tweak this). + */ + slidersHorz: object; + + /** + * Customizes the default colorpicker HTML template. + */ + template: string; + + /** + * By default, the colorpicker is aligned to the right of the input. If you need to switch it to the left, set align to 'left'. + * + * Default: 'right' + */ + align: ColorPickerAlignOptions; + + /** + * Adds this class to the colorpicker widget. + * + * Default: null + */ + customClass: string; + + /** + * List of pre selected colors (hex format). If you choose one of these colors, the alias is returned instead of the hex code. + * + * Default: null + */ + colorSelectors: object; + + /** + * Fallback color string that will be applied when the color failed to be parsed. If null, it will keep the current color if any. + * + * Default: null + */ + fallbackColor: string; + + /** + * Fallback color format (e.g. when not specified or for alias mode, when selecting non aliased colors) + * + * Default: hex + */ + fallbackFormat: string; +} + +interface Color { + colors: {}; + fallbackFormat: string; + fallbackValue: string; + hexNumberSignPrefix: boolean; + origFormat: string; + predefinedColors: {}; + value: { + h: number; + s: number; + b: number; + a: number; + } + + /** + * Set a new color. The value is parsed and tries to do a quess on the format. + */ + setColor(value: string): void; + + /** + * Set the HUE with a value between 0 and 1. + */ + setHue(value: number): void; + + /** + * Set the saturation with a value between 0 and 1. + */ + setSaturation(value: number): void; + + /** + * Set the brightness with a value between 0 and 1. + */ + setBrightness(value: number): void; + + /** + * Set the transparency with a value between 0 and 1. + */ + setAlpha(value: number): void; + + /** + * Returns a hash with red, green, blue and alpha. + */ + toRGB(): string; + + /** + * Returns a string with HEX format for the current color. + */ + toHex(): string; + + /** + * Returns a hash with HSLA values. + */ + toHSL(): string; +} + +interface ColorPicker { + color: Color; + component: boolean; + container: boolean; + disabled: boolean; + element: JQuery; + format: string; + input: JQuery; + options: ColorPickerOptions; + picker: JQuery; +} + +interface ColorPickerEventObject { + +} + +interface JQuery { + /** + * Initializes an colorpicker. + */ + colorpicker(): JQuery; + + /** + * Initializes an colorpicker. + */ + colorpicker(options: ColorPickerOptions): JQuery; + + /** + * Gets the value from the input or the data attribute (if has no input), otherwise returns the default value, which defaults to #000000 if not specified. + */ + colorpicker(methodName: 'getValue', defaultValue: string): string; + + /** + * Set a new value for the color picker (also updates everything). Triggers 'changeColor' event. + */ + colorpicker(methodName: 'setValue', value: any): any; + + /** + * Show the color picker + */ + colorpicker(methodName: 'show'): void; + + /** + * Hide the color picker + */ + colorpicker(methodName: 'hide'): void; + + /** + * Updates the color picker's position relative to the element + */ + colorpicker(methodName: 'reposition'): void; + + /** + * Refreshes the widget colors (this is done automatically) + */ + colorpicker(methodName: 'update'): void; + + /** + * Enable the color picker. + */ + colorpicker(methodName: 'enable'): void; + + /** + * Disable the color picker. + */ + colorpicker(methodName: 'disable'): void; + + /** + * Destroys the colorpicker widget and unbind all .colorpicker events from the element and component + */ + colorpicker(methodName: 'destroy'): void; + + /** + * Access to the colorpicker API directly + */ + data(methodName: 'colorpicker'): ColorPicker; + + off(events: ColorPickerEvents, selector?: string, handler?: (event: ColorPickerEventObject) => any): JQuery; + off(events: ColorPickerEvents, handler: (event: ColorPickerEventObject) => any): JQuery; + + on(events: ColorPickerEvents, selector: string, data: any, handler?: (event: ColorPickerEventObject) => any): JQuery; + on(events: ColorPickerEvents, selector: string, handler: (event: ColorPickerEventObject) => any): JQuery; + on(events: ColorPickerEvents, handler: (event: ColorPickerEventObject) => any): JQuery; +} \ No newline at end of file diff --git a/types/bootstrap-colorpicker@2.5.3/tsconfig.json b/types/bootstrap-colorpicker@2.5.3/tsconfig.json new file mode 100644 index 0000000000..61299349f7 --- /dev/null +++ b/types/bootstrap-colorpicker@2.5.3/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bootstrap-colorpicker@2.5.3-tests.ts" + ] +} diff --git a/types/bootstrap-colorpicker@2.5.3/tslint.json b/types/bootstrap-colorpicker@2.5.3/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/bootstrap-colorpicker@2.5.3/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From c8a1eeb459f2717f8482ffb2e77cba1be61dbac2 Mon Sep 17 00:00:00 2001 From: Aleksandar Manukov <34056917+aleksandar-manukov@users.noreply.github.com> Date: Sat, 15 Dec 2018 17:55:15 +0200 Subject: [PATCH 2/3] Rename bootstrap-colorpicker@2.5.3 to bootstrap-colorpicker@2.x --- .../bootstrap-colorpicker@2.x-tests.ts} | 0 .../index.d.ts | 0 .../tsconfig.json | 0 .../tslint.json | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename types/{bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts => bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts} (100%) rename types/{bootstrap-colorpicker@2.5.3 => bootstrap-colorpicker@2.x}/index.d.ts (100%) rename types/{bootstrap-colorpicker@2.5.3 => bootstrap-colorpicker@2.x}/tsconfig.json (100%) rename types/{bootstrap-colorpicker@2.5.3 => bootstrap-colorpicker@2.x}/tslint.json (100%) diff --git a/types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts b/types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/bootstrap-colorpicker@2.5.3-tests.ts rename to types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts diff --git a/types/bootstrap-colorpicker@2.5.3/index.d.ts b/types/bootstrap-colorpicker@2.x/index.d.ts similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/index.d.ts rename to types/bootstrap-colorpicker@2.x/index.d.ts diff --git a/types/bootstrap-colorpicker@2.5.3/tsconfig.json b/types/bootstrap-colorpicker@2.x/tsconfig.json similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/tsconfig.json rename to types/bootstrap-colorpicker@2.x/tsconfig.json diff --git a/types/bootstrap-colorpicker@2.5.3/tslint.json b/types/bootstrap-colorpicker@2.x/tslint.json similarity index 100% rename from types/bootstrap-colorpicker@2.5.3/tslint.json rename to types/bootstrap-colorpicker@2.x/tslint.json From e896537a9c5697f7f6e7da7a7673d2524f1f8c73 Mon Sep 17 00:00:00 2001 From: Aleksandar Manukov <34056917+aleksandar-manukov@users.noreply.github.com> Date: Wed, 16 Jan 2019 22:12:26 +0200 Subject: [PATCH 3/3] Add tests for bootstrap-colorpicker-v2 --- .../bootstrap-colorpicker-v2-tests.ts | 77 +++++++++++++++++++ .../index.d.ts | 59 +++++++------- .../tsconfig.json | 2 +- .../tslint.json | 0 .../bootstrap-colorpicker@2.x-tests.ts | 0 5 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 types/bootstrap-colorpicker-v2/bootstrap-colorpicker-v2-tests.ts rename types/{bootstrap-colorpicker@2.x => bootstrap-colorpicker-v2}/index.d.ts (88%) rename types/{bootstrap-colorpicker@2.x => bootstrap-colorpicker-v2}/tsconfig.json (90%) rename types/{bootstrap-colorpicker@2.x => bootstrap-colorpicker-v2}/tslint.json (100%) delete mode 100644 types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts diff --git a/types/bootstrap-colorpicker-v2/bootstrap-colorpicker-v2-tests.ts b/types/bootstrap-colorpicker-v2/bootstrap-colorpicker-v2-tests.ts new file mode 100644 index 0000000000..7869da99c9 --- /dev/null +++ b/types/bootstrap-colorpicker-v2/bootstrap-colorpicker-v2-tests.ts @@ -0,0 +1,77 @@ +$(() => { + $('#cp1').colorpicker(); + + $('#cp2').colorpicker(); + + $('#cp3').colorpicker({ + color: '#AA3399', + format: 'rgb' + }); + + $('#cp4').colorpicker().on('changeColor', (e) => { + $('body')[0].style.backgroundColor = e.color.toString('rgba'); + }); + + $('#cp5').colorpicker({ + color: "transparent", + format: "hex" + }); + + $('#cp6').colorpicker({ + color: "#88cc33", + horizontal: true + }); + + $('#cp7').colorpicker({ + color: '#ffaa00', + container: true, + inline: true + }); + + $('#cp8').colorpicker({ + colorSelectors: { + 'black': '#000000', + 'white': '#ffffff', + 'red': '#FF0000', + 'default': '#777777', + 'primary': '#337ab7', + 'success': '#5cb85c', + 'info': '#5bc0de', + 'warning': '#f0ad4e', + 'danger': '#d9534f' + } + }); + + $('#cp9').colorpicker({ + customClass: 'colorpicker-2x', + sliders: { + saturation: { + maxLeft: 200, + maxTop: 200 + }, + hue: { + maxTop: 200 + }, + alpha: { + maxTop: 200 + } + } + }); + + $(".disable-button").click((e) => { + e.preventDefault(); + + $("#cp10").colorpicker('disable'); + }); + + $(".enable-button").click((e) => { + e.preventDefault(); + + $("#cp10").colorpicker('enable'); + }); + + $('#cp10').colorpicker(); + + + $('#cp11').colorpicker(); +}); \ No newline at end of file diff --git a/types/bootstrap-colorpicker@2.x/index.d.ts b/types/bootstrap-colorpicker-v2/index.d.ts similarity index 88% rename from types/bootstrap-colorpicker@2.x/index.d.ts rename to types/bootstrap-colorpicker-v2/index.d.ts index 222b939b89..e04e8706f2 100644 --- a/types/bootstrap-colorpicker@2.x/index.d.ts +++ b/types/bootstrap-colorpicker-v2/index.d.ts @@ -5,13 +5,15 @@ /// +type ColorFormat = false | 'hex' | 'rgb' | 'rgba' + type ColorPickerAlignOptions = 'right' | 'left'; -type ColorPickerEvents = 'create' | - 'showPicker' | - 'hidePicker' | - 'changeColor' | - 'disable' | +type ColorPickerEvents = 'create' | + 'showPicker' | + 'hidePicker' | + 'changeColor' | + 'disable' | 'enable' | 'destroy' @@ -24,106 +26,106 @@ interface ColorPickerOptions { * * Default: false */ - format: string; + format?: ColorFormat; /** * If not false, sets the color to this value. * * Default: false */ - color: string; + color?: string; /** * If not false, the picker will be contained inside this element, otherwise it will be appended to the document body. * * Default: false */ - container: string | JQuery; + container?: boolean; /** * Children selector for the component or element that trigger the colorpicker and which background color will change (needs an inner element). * * Default: '.add-on, .input-group-addon' */ - component: string | JQuery; + component?: string | JQuery; /** * Children selector for the input that will store the picker selected value. * * Default: 'input' */ - input: string | JQuery; + input?: string | JQuery; /** * If true, put a '#' (number sign) before hex strings. * * Default: true */ - hexNumberSignPrefix: boolean; + hexNumberSignPrefix?: boolean; /** * If true, the hue and alpha channel bars will be rendered horizontally, above the saturation selector. * * Default: false */ - horizontal: boolean; + horizontal?: boolean; /** * If true, forces to show the colorpicker as an inline element. * * Default: false */ - inline: boolean; + inline?: boolean; /** * Vertical sliders configuration (read source code if you really need to tweak this). */ - sliders: object; + sliders?: object; /** * Horizontal sliders configuration (read source code if you really need to tweak this). */ - slidersHorz: object; + slidersHorz?: object; /** * Customizes the default colorpicker HTML template. */ - template: string; + template?: string; /** * By default, the colorpicker is aligned to the right of the input. If you need to switch it to the left, set align to 'left'. * * Default: 'right' */ - align: ColorPickerAlignOptions; + align?: ColorPickerAlignOptions; /** * Adds this class to the colorpicker widget. * * Default: null */ - customClass: string; + customClass?: string; /** * List of pre selected colors (hex format). If you choose one of these colors, the alias is returned instead of the hex code. * * Default: null */ - colorSelectors: object; + colorSelectors?: object; /** * Fallback color string that will be applied when the color failed to be parsed. If null, it will keep the current color if any. * * Default: null */ - fallbackColor: string; + fallbackColor?: string; /** * Fallback color format (e.g. when not specified or for alias mode, when selecting non aliased colors) * * Default: hex */ - fallbackFormat: string; + fallbackFormat?: string; } interface Color { @@ -133,8 +135,8 @@ interface Color { hexNumberSignPrefix: boolean; origFormat: string; predefinedColors: {}; - value: { - h: number; + value: { + h: number; s: number; b: number; a: number; @@ -179,6 +181,11 @@ interface Color { * Returns a hash with HSLA values. */ toHSL(): string; + + /** + * Returns current color as string in specified format. + */ + toString(format: ColorFormat): string; } interface ColorPicker { @@ -193,8 +200,8 @@ interface ColorPicker { picker: JQuery; } -interface ColorPickerEventObject { - +interface ColorPickerEventObject extends JQueryEventObject { + color: Color; } interface JQuery { @@ -202,7 +209,7 @@ interface JQuery { * Initializes an colorpicker. */ colorpicker(): JQuery; - + /** * Initializes an colorpicker. */ diff --git a/types/bootstrap-colorpicker@2.x/tsconfig.json b/types/bootstrap-colorpicker-v2/tsconfig.json similarity index 90% rename from types/bootstrap-colorpicker@2.x/tsconfig.json rename to types/bootstrap-colorpicker-v2/tsconfig.json index 61299349f7..e734e0a2ca 100644 --- a/types/bootstrap-colorpicker@2.x/tsconfig.json +++ b/types/bootstrap-colorpicker-v2/tsconfig.json @@ -17,6 +17,6 @@ }, "files": [ "index.d.ts", - "bootstrap-colorpicker@2.5.3-tests.ts" + "bootstrap-colorpicker-v2-tests.ts" ] } diff --git a/types/bootstrap-colorpicker@2.x/tslint.json b/types/bootstrap-colorpicker-v2/tslint.json similarity index 100% rename from types/bootstrap-colorpicker@2.x/tslint.json rename to types/bootstrap-colorpicker-v2/tslint.json diff --git a/types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts b/types/bootstrap-colorpicker@2.x/bootstrap-colorpicker@2.x-tests.ts deleted file mode 100644 index e69de29bb2..0000000000