From d21252db7de6b7cc1c1f5432f3ece29e19c7e956 Mon Sep 17 00:00:00 2001 From: Konstantin Rohde Date: Mon, 11 Jun 2018 12:24:03 +0200 Subject: [PATCH 1/5] Types for the Datatables.net Scroller Extension --- .../datatables.net-scroller-tests.ts | 13 +++ types/datatables.net-scroller/index.d.ts | 101 ++++++++++++++++++ types/datatables.net-scroller/tsconfig.json | 24 +++++ types/datatables.net-scroller/tslint.json | 1 + 4 files changed, 139 insertions(+) create mode 100644 types/datatables.net-scroller/datatables.net-scroller-tests.ts create mode 100644 types/datatables.net-scroller/index.d.ts create mode 100644 types/datatables.net-scroller/tsconfig.json create mode 100644 types/datatables.net-scroller/tslint.json diff --git a/types/datatables.net-scroller/datatables.net-scroller-tests.ts b/types/datatables.net-scroller/datatables.net-scroller-tests.ts new file mode 100644 index 0000000000..cb93306ba0 --- /dev/null +++ b/types/datatables.net-scroller/datatables.net-scroller-tests.ts @@ -0,0 +1,13 @@ +$(document).ready(() => { + const config: DataTables.Settings = { + // Scroller extension options + scroller: { + trace: true, + rowHeight: 30, + serverWait: 1000, + displayBuffer: 10, + boundaryScale: 0.6, + loadingIndicator: true + } + }; +}); diff --git a/types/datatables.net-scroller/index.d.ts b/types/datatables.net-scroller/index.d.ts new file mode 100644 index 0000000000..e6608903d6 --- /dev/null +++ b/types/datatables.net-scroller/index.d.ts @@ -0,0 +1,101 @@ +// Type definitions for datatables.net-scroller 1.4.3 +// Project: https://datatables.net/extensions/scroller/ +// Definitions by: Konstantin Rohde +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/// +/// + +declare namespace DataTables { + interface Settings { + /* + * Select extension options + */ + scroller?: boolean | ScrollerSettings; + } + + interface ScrollerSettings { + /* + * Indicate if Scroller show show trace information on the console or not. + */ + trace?: boolean; + + /* + * Scroller will attempt to automatically calculate the height of rows for it's internal + * calculations. However the height that is used can be overridden using this parameter. + */ + rowHeight?: number | string; + + /* + * When using server-side processing, Scroller will wait a small amount of time to allow + * the scrolling to finish before requesting more data from the server. + */ + serverWait?: number; + + /* + * The display buffer is what Scroller uses to calculate how many rows it should pre-fetch + * for scrolling. + */ + displayBuffer?: number; + + /* + * Scroller uses the boundary scaling factor to decide when to redraw the table - which it + * typically does before you reach the end of the currently loaded data set (in order to + * allow the data to look continuous to a user scrolling through the data). + */ + boundaryScale?: number; + + /* + * Show (or not) the loading element in the background of the table. Note that you should + * include the dataTables.scroller.css file for this to be displayed correctly. + */ + loadingIndicator?: boolean; + } + + interface Api { + scroller: { + /* + * Calculate and store information about how many rows are to be displayed + * in the scrolling viewport, based on current dimensions in the browser's + * rendering. + */ + measure(redraw?: boolean): Api; + /* + * Get information about current displayed record range. + */ + page(): PageInfo; + }; + scroller(): ScrollerApi; + } + + interface ScrollerApi extends Api { + /* + * Calculate the pixel position from the top of the scrolling container for + * a given row + */ + rowToPixels(rowIdx: number, intParse?: boolean, virtual?: boolean): number; + /* + * Calculate the row number that will be found at the given pixel position + * (y-scroll). + */ + pixelsToRow(pixels: number, intParse?: boolean, virtual?: boolean): number; + scrollToRow(rowIdx: number, animate?: boolean): Api; + } + + /* + * start: {int}, // the 0-indexed record at the top of the viewport + * end: {int}, // the 0-indexed record at the bottom of the viewport + */ + interface PageInfo { + start: number; + end: number; + } + + interface RowMethods { + /** + * Scroll to a row + */ + scrollTo(animate?: boolean): Api; + } +} diff --git a/types/datatables.net-scroller/tsconfig.json b/types/datatables.net-scroller/tsconfig.json new file mode 100644 index 0000000000..41b8182a6e --- /dev/null +++ b/types/datatables.net-scroller/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "datatables.net-scroller-tests.ts" + ] +} \ No newline at end of file diff --git a/types/datatables.net-scroller/tslint.json b/types/datatables.net-scroller/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/datatables.net-scroller/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 4fdf91b10a5e63019969f33faa9359c71b5175af Mon Sep 17 00:00:00 2001 From: Konstantin Rohde Date: Mon, 11 Jun 2018 12:42:35 +0200 Subject: [PATCH 2/5] Reformatted for dtslint --- types/datatables.net-scroller/index.d.ts | 73 +++++++++++++----------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/types/datatables.net-scroller/index.d.ts b/types/datatables.net-scroller/index.d.ts index e6608903d6..e0b9e54d9a 100644 --- a/types/datatables.net-scroller/index.d.ts +++ b/types/datatables.net-scroller/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for datatables.net-scroller 1.4.3 +// Type definitions for datatables.net-scroller 1.4 // Project: https://datatables.net/extensions/scroller/ // Definitions by: Konstantin Rohde // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -35,14 +35,14 @@ declare namespace DataTables { /* * The display buffer is what Scroller uses to calculate how many rows it should pre-fetch - * for scrolling. + * for scrolling. */ displayBuffer?: number; /* * Scroller uses the boundary scaling factor to decide when to redraw the table - which it * typically does before you reach the end of the currently loaded data set (in order to - * allow the data to look continuous to a user scrolling through the data). + * allow the data to look continuous to a user scrolling through the data). */ boundaryScale?: number; @@ -54,33 +54,38 @@ declare namespace DataTables { } interface Api { - scroller: { - /* - * Calculate and store information about how many rows are to be displayed - * in the scrolling viewport, based on current dimensions in the browser's - * rendering. - */ - measure(redraw?: boolean): Api; - /* - * Get information about current displayed record range. - */ - page(): PageInfo; - }; - scroller(): ScrollerApi; + scroller: ScrollerMethodsModel; } - interface ScrollerApi extends Api { - /* - * Calculate the pixel position from the top of the scrolling container for - * a given row - */ - rowToPixels(rowIdx: number, intParse?: boolean, virtual?: boolean): number; - /* - * Calculate the row number that will be found at the given pixel position - * (y-scroll). - */ - pixelsToRow(pixels: number, intParse?: boolean, virtual?: boolean): number; - scrollToRow(rowIdx: number, animate?: boolean): Api; + interface ScrollerMethodsModel { + /* + * Calculate and store information about how many rows are to be displayed + * in the scrolling viewport, based on current dimensions in the browser's + * rendering. + */ + measure(redraw?: boolean): Api; + /* + * Get information about current displayed record range. + */ + page(): PageInfo; + /* + * Get Scroller Api + */ + scroller(): ScrollerMethods; + } + + interface ScrollerMethods extends Api { + /* + * Calculate the pixel position from the top of the scrolling container for + * a given row + */ + rowToPixels(rowIdx: number, intParse?: boolean, virtual?: boolean): number; + /* + * Calculate the row number that will be found at the given pixel position + * (y-scroll). + */ + pixelsToRow(pixels: number, intParse?: boolean, virtual?: boolean): number; + scrollToRow(rowIdx: number, animate?: boolean): Api; } /* @@ -88,14 +93,14 @@ declare namespace DataTables { * end: {int}, // the 0-indexed record at the bottom of the viewport */ interface PageInfo { - start: number; - end: number; + start: number; + end: number; } interface RowMethods { - /** - * Scroll to a row - */ - scrollTo(animate?: boolean): Api; + /** + * Scroll to a row + */ + scrollTo(animate?: boolean): Api; } } From 11c510ffedf81966bd6e72e16a5b369eabaaf1ff Mon Sep 17 00:00:00 2001 From: Konstantin Rohde Date: Mon, 11 Jun 2018 12:55:31 +0200 Subject: [PATCH 3/5] Neu erstellt mit dts-gen --- types/datatables.net-scroller/index.d.ts | 3 +-- types/datatables.net-scroller/tsconfig.json | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/types/datatables.net-scroller/index.d.ts b/types/datatables.net-scroller/index.d.ts index e0b9e54d9a..8004952d12 100644 --- a/types/datatables.net-scroller/index.d.ts +++ b/types/datatables.net-scroller/index.d.ts @@ -1,8 +1,7 @@ // Type definitions for datatables.net-scroller 1.4 -// Project: https://datatables.net/extensions/scroller/ +// Project: https://datatables.net // Definitions by: Konstantin Rohde // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 /// /// diff --git a/types/datatables.net-scroller/tsconfig.json b/types/datatables.net-scroller/tsconfig.json index 41b8182a6e..cb89487bce 100644 --- a/types/datatables.net-scroller/tsconfig.json +++ b/types/datatables.net-scroller/tsconfig.json @@ -2,13 +2,11 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6", - "dom" + "es6" ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, - "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" @@ -21,4 +19,4 @@ "index.d.ts", "datatables.net-scroller-tests.ts" ] -} \ No newline at end of file +} From 93e09c6b5e8e268f2ed8a02a78829cca9a1362f0 Mon Sep 17 00:00:00 2001 From: Konstantin Rohde Date: Mon, 11 Jun 2018 12:58:02 +0200 Subject: [PATCH 4/5] Another dtslint fix. --- types/datatables.net-scroller/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/datatables.net-scroller/tsconfig.json b/types/datatables.net-scroller/tsconfig.json index cb89487bce..29e1854557 100644 --- a/types/datatables.net-scroller/tsconfig.json +++ b/types/datatables.net-scroller/tsconfig.json @@ -2,11 +2,13 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 4891dc0d009a9c1946db1a8f237d77ba18f481c4 Mon Sep 17 00:00:00 2001 From: Konstantin Rohde Date: Mon, 11 Jun 2018 13:53:16 +0200 Subject: [PATCH 5/5] Added Typescript version --- types/datatables.net-scroller/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/datatables.net-scroller/index.d.ts b/types/datatables.net-scroller/index.d.ts index 8004952d12..fe97507712 100644 --- a/types/datatables.net-scroller/index.d.ts +++ b/types/datatables.net-scroller/index.d.ts @@ -2,6 +2,7 @@ // Project: https://datatables.net // Definitions by: Konstantin Rohde // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 /// ///