From 403eb473433dc8495457fd65f0b4a4bce955c0a9 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Fri, 4 Nov 2022 17:03:15 +0000 Subject: [PATCH] c25ea69f9241501b36193afffb91196928aab18f Sync to source repo @c25ea69f9241501b36193afffb91196928aab18f --- datatables.json | 5 +- js/buttons.bootstrap4.min.js | 3 + js/buttons.bootstrap4.min.mjs | 3 + types/types.d.ts | 613 +++++++++++++++++++++++++++++++++- 4 files changed, 618 insertions(+), 6 deletions(-) diff --git a/datatables.json b/datatables.json index a98d705..01714fa 100644 --- a/datatables.json +++ b/datatables.json @@ -14,5 +14,6 @@ "types/types.d.ts" ], "src-repo": "http://github.com/DataTables/Buttons", - "last-tag": "2.2.3" -} + "last-tag": "2.2.3", + "last-sync": "c25ea69f9241501b36193afffb91196928aab18f" +} \ No newline at end of file diff --git a/js/buttons.bootstrap4.min.js b/js/buttons.bootstrap4.min.js index 253525a..70f3ae3 100644 --- a/js/buttons.bootstrap4.min.js +++ b/js/buttons.bootstrap4.min.js @@ -1 +1,4 @@ +/*! Bootstrap integration for DataTables' Buttons + * ©2016 SpryMedia Ltd - datatables.net/license + */ !function(n){"function"==typeof define&&define.amd?define(["jquery","datatables.net-bs4","datatables.net-buttons"],function(t){return n(t,window,document)}):"object"==typeof exports?module.exports=function(t,e){return t=t||window,(e=e||("undefined"!=typeof window?require("jquery"):require("jquery")(t))).fn.dataTable||require("datatables.net-bs4")(t,e),e.fn.dataTable||require("datatables.net-buttons")(t,e),n(e,0,t.document)}:n(jQuery,window,document)}(function(n,t,e,o){"use strict";var a=n.fn.dataTable;return n.extend(!0,a.Buttons.defaults,{dom:{container:{className:"dt-buttons btn-group flex-wrap"},button:{className:"btn btn-secondary"},collection:{tag:"div",className:"dropdown-menu",closeButton:!1,button:{tag:"a",className:"dt-button dropdown-item",active:"active",disabled:"disabled"}},splitWrapper:{tag:"div",className:"dt-btn-split-wrapper btn-group",closeButton:!1},splitDropdown:{tag:"button",text:"",className:"btn btn-secondary dt-btn-split-drop dropdown-toggle dropdown-toggle-split",closeButton:!1,align:"split-left",splitAlignClass:"dt-button-split-left"},splitDropdownButton:{tag:"button",className:"dt-btn-split-drop-button btn btn-secondary",closeButton:!1}},buttonCreated:function(t,e){return t.buttons?n('
').append(e):e}}),a.ext.buttons.collection.className+=" dropdown-toggle",a.ext.buttons.collection.rightAlignClassName="dropdown-menu-right",a}); \ No newline at end of file diff --git a/js/buttons.bootstrap4.min.mjs b/js/buttons.bootstrap4.min.mjs index 3276ec1..b7301ab 100644 --- a/js/buttons.bootstrap4.min.mjs +++ b/js/buttons.bootstrap4.min.mjs @@ -1 +1,4 @@ +/*! Bootstrap integration for DataTables' Buttons + * ©2016 SpryMedia Ltd - datatables.net/license + */ import $ from"jquery";import DataTable from"datatables.net-bs4";import DataTable from"datatables.net-buttons";$.extend(!0,DataTable.Buttons.defaults,{dom:{container:{className:"dt-buttons btn-group flex-wrap"},button:{className:"btn btn-secondary"},collection:{tag:"div",className:"dropdown-menu",closeButton:!1,button:{tag:"a",className:"dt-button dropdown-item",active:"active",disabled:"disabled"}},splitWrapper:{tag:"div",className:"dt-btn-split-wrapper btn-group",closeButton:!1},splitDropdown:{tag:"button",text:"",className:"btn btn-secondary dt-btn-split-drop dropdown-toggle dropdown-toggle-split",closeButton:!1,align:"split-left",splitAlignClass:"dt-button-split-left"},splitDropdownButton:{tag:"button",className:"dt-btn-split-drop-button btn btn-secondary",closeButton:!1}},buttonCreated:function(t,a){return t.buttons?$('
').append(a):a}}),DataTable.ext.buttons.collection.className+=" dropdown-toggle",DataTable.ext.buttons.collection.rightAlignClassName="dropdown-menu-right";export default DataTable; \ No newline at end of file diff --git a/types/types.d.ts b/types/types.d.ts index 2178209..0e2805a 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -1,7 +1,612 @@ +// Type definitions for DataTables Buttons +// +// Project: https://datatables.net/extensions/buttons/, https://datatables.net +// Definitions by: +// SpryMedia +// Kiarash Ghiaseddin +// Sam Germano +// Jim Hartford -// Dist-DataTables-Buttons-Bootstrap4 integration with Bootstrap4 exports the DataTables API having -// set default values to complete the ingeration. -import Api from "datatables.net"; +/// -export default Api; +import DataTables, {Api} from 'datatables.net'; +export default DataTables; + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * DataTables' types integration + */ +declare module 'datatables.net' { + interface Config { + /** + * Buttons extension options + */ + buttons?: boolean | ConfigButtons | Array; + } + + interface ConfigLanguage { + /** + * Buttons language options + */ + buttons?: ConfigButtonsLanguage; + } + + interface Api { + /** + * Select a single button from the button instances attached to a DataTable. + * + * @param groupSelector Button group (instance) selector. Provides the ability to select a button from a specific instance of the Buttons class. + * @param buttonSelector Selector to obtain the button that should be acted upon. + */ + button: ApiButton; + + buttons: ApiButtons; + } + + interface ApiStatic { + /** + * Buttons class + */ + Buttons: { + /** + * Create a new Buttons instance for the target DataTable + */ + new (dt: Api, settings: boolean | ConfigButtons | Array); + + /** + * Buttons version + */ + version: string; + + /** + * Default configuration values + */ + defaults: ConfigButtons; + } + } + + interface ApiStaticExt { + buttons: ExtButtons; + } +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Options + */ + +interface ConfigButtons { + name?: string; + tabIndex?: number; + buttons: Array; + dom?: ConfigButtonDom; +} + +interface ConfigButtonsLanguage { + [key: string]: string | ConfigButtonsLanguage; +} + + +interface ApiButton { + (groupSelector?: number | string | Array, buttonSelector?: null | number | string | Node | JQuery | Array>): ApiButtonMethods; +} + +interface ApiButtonMethods extends Api { + /** + * Get the action function for the selected button. + * + * @returns The action function for the selected button. + */ + action(): FunctionButtonAction; + + /** + * Set the action function for the selected button. + * + * @param set the function that is to be triggered on an action. + * @returns DataTables Api for chaining + */ + action(set: FunctionButtonAction): Api; + + /** + * Get the active state for the selected button. + * + * @returns true if currently active, otherwise false. + */ + active(): boolean; + + /** + * Set the active state for the selected button. + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the button. + */ + active(state: boolean): Api; + + /** + * Create a new button, adding it to the selected button instance and inserting immediately into the document. + * + * @returns New DataTables API instance with the result set containing the newly created button. This means it is possible to immediately using the chaining API to manipulate the button. + */ + add(index: number | string, config: string|FunctionButton|ButtonConfig): Api; + + /** + * Disable the selected buttons. + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the button. + */ + disable(): Api; + + /** + * Set the enabled state for the selected button. + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the button. + */ + enable(state?: boolean): Api; + + /** + * Get a jQuery object that contains a reference to the node for the selected button. + * + * @returns A jQuery object that contains the node of the selected button + */ + node(): JQuery; + + /** + * Determine if a button is currently in the processing state or not. + * + * @returns true if the button is currently in its processing state, false otherwise. + */ + processing(): boolean; + + /** + * Set the processing state for the selected button. + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the buttons. + */ + processing(set: boolean): Api; + + /** + * Remove the selected button from the display. The button is destroyed and can no longer be used once removed. + * + * @returns DataTables API instance. + */ + remove(): Api; + + /** + * Get the display text for the selected button + * + * @returns The current display string from the button. + */ + text(): string; + + /** + * Set the display text for the selected button + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the buttons. + */ + text(title: string | FunctionButtonText): Api; + + /** + * Programmatically trigger the action of the selected button. + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the button. + */ + trigger(): Api; +} + + + +interface ApiButtons { + (groupSelector?: any, buttonSelector?: any): ApiButtonsMethods; + + /** + * Display / hide an information message to the end user to indicate that something has happened. + * + * @returns DataTables API instance for chaining. + */ + info(title: string, message?: string, time?: number): Api; + + /** + * Get meta information that is common to many different button types. + * + * @returns An object with properties which contain the filename, messageTop, messageBottom and title. + */ + exportInfo(options?: ButtonsApiExportInfoParameter): ButtonsApiExportInfoReturn; + + /** + * Obtain data from a DataTable that is suitable for exporting by saving into a file or copying to clipboard. + * + * @returns An object with 3 properties, one each for the data in the header, body and footer. + */ + exportData(options?: ButtonsApiExportDataParameter): ButtonsApiExportDataReturn; +} + +interface ApiButtonsMethods extends Api { + /** + * Get the action function for the selected button. + * + * @returns DataTables API instance which contains the action functions for the selected buttons + */ + action(): Api>; + + /** + * Set the action function for the selected button. + * + * @param set the function that is to be triggered on an action. + * @returns DataTables API instance with the selected buttons in the result set, available for chaining further operations on the buttons. + */ + action(set: FunctionButtonAction): Api>; + + /** + * Get the active state for the selected button. + * + * @returns API instance which contains true if currently active, otherwise false for each selected button in the result set. + */ + active(): Api>; + + /** + * Set the active state for the selected button. + * + * @returns DataTables API instance with the selected buttons in the result set, available for chaining further operations on the buttons. + */ + active(state: boolean): Api>; + + /** + * Get a jQuery instance that contains a reference to the button container instance. + */ + container(): JQuery; + + /** + * Get a jQuery instance that contains a reference to the button container instances. + * + * @returns jQuery instance that contains the container elements for the selected button instances. + */ + containers(): JQuery; + + /** + * Destroy the selected button instances, removing the container and all button elements from the document. + * + * @returns DataTables API instance. + */ + destroy(): Api; + + /** + * Disable the selected buttons. + * + * @returns DataTables API instance with the selected buttons in the result set, available for chaining further operations on the buttons. + */ + disable(): Api>; + + /** + * Set the enabled state for the selected button. + * + * @returns DataTables API instance with the selected buttons in the result set, available for chaining further operations on the buttons. + */ + enable(state?: boolean): Api>; + + /** + * Get a jQuery object that contains a reference to the node for the selected button. + * + * @returns A jQuery object that contains the node of the selected button + */ + nodes(): JQuery; + + /** + * Set the processing state for the selected button. + * + * @returns DataTables API instance with the selected buttons in the result set, available for chaining further operations on the buttons. + */ + processing(set: boolean): Api; + + /** + * Remove the selected button from the display. The button is destroyed and can no longer be used once removed. + * + * @returns DataTables API instance. + */ + remove(): Api; + + /** + * Get the display text for the selected button + * + * @returns The current display string from the button. + */ + text(): string; + + /** + * Set the display text for the selected button + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the buttons. + */ + text(title: string | FunctionButtonText): Api>; + + /** + * Programmatically trigger the action of the selected button. + * + * @returns DataTables API instance with the selected button in the result set, available for chaining further operations on the button. + */ + trigger(): Api>; +} + + + + +interface ButtonsApiExportInfoParameter { + extension?: string | (() => string); + filename?: string | (() => string); + messageBottom?: null | string | (() => string); + messageTop?: null | string | (() => string); + title?: null | string | (() => string); +} + +interface ButtonsApiExportInfoReturn { + filename: string; + messageTop: string; + messageBottom: string; + title: string; +} + +interface ButtonsApiExportDataParameter { + rows?: any; + columns?: any; + modifier?: any; + orthogonal?: string; + stripHtml?: boolean; + stripNewlines?: boolean; + decodeEntities?: boolean; + trim?: boolean; + format?: any; +} + +interface ButtonsApiExportDataReturn { + header: string[]; + footer: string[]; + body: string[]; +} + +interface ConfigButtonDom { + button?: ButtonDomButton; + buttonContainer?: ButtonDomButtonEl; + buttonLiner?: ButtonDomButtonEl; + collection?: ButtonDomButtonEl; + container?: ButtonDomButtonEl; +} + +interface ButtonDomButtonEl { + className?: string; + tag?: string; +} + +interface ButtonDomButton extends ButtonDomButtonEl { + active?: string; + disabled?: string; +} + +interface ButtonConfigCommon { + /** + * Action to take when the button is activated + */ + action?: FunctionButtonAction; + + /** + * Ensure that any requirements have been satisfied before initialising a button + */ + available?: FunctionButtonAvailable; + + /** + * Set the class name for the button + */ + className?: string; + + /** + * Function that is called when the button is destroyed + */ + destroy?: FunctionButtonInit; + + /** + * Set a button's initial enabled state + */ + enabled?: boolean; + + /** + * Define which button type the button should be based on + */ + extend?: string; + + /** + * Initialisation function that can be used to add events specific to this button + */ + init?: FunctionButtonInit; + + /** + * Define an activation key for a button + */ + key?: string | ButtonKey; + + /** + * Set a name for each selection + */ + name?: string; + + /** + * Unique namespace for every button + */ + namespace?: string; + + /** + * The text to show in the button + */ + text?: string | FunctionButtonText; + + /** + * Button 'title' attribute text + */ + titleAttr?: string; +} + +interface ButtonKey { + key?: string; + shiftKey?: boolean; + altKey?: boolean; + ctrlKey?: boolean; + metaKey?: boolean; +} + +/** + * A function that will be executed upon creation of the buttons. + */ +type FunctionButton = (dt: Api) => ButtonConfigCommon; + +type FunctionButtonText = (dt: Api, node: JQuery, config: any) => string; + +type FunctionButtonAvailable = (dt: Api, config: any) => boolean; + +type FunctionButtonInit = (dt: Api, node: JQuery, config: any) => void; + +type FunctionButtonAction = (e: any, dt: Api, node: JQuery, config: ButtonConfig) => void; + +type FunctionButtonCustomize = (win: Window|string) => void; + +type FunctionExtButtonsCollectionText = (a: any) => string; + +interface ExtButtons { + [name: string]: ButtonConfigCommon; + + collection: ButtonCollection; +} + +/** + * Collection button + */ +interface ButtonCollection { + action: FunctionButtonAction; + autoClose: boolean; + background: boolean; + backgroundClassName: string; + className: string; + collectionLayout: string; + fade: number; + text: FunctionExtButtonsCollectionText; +} + +/** + * Buttons extension options + */ +interface ButtonConfig extends ButtonConfigCommon { + /** + * CSV / EXCEL: Define what the exported filename should be + */ + filename?: string; + + /** + * COPY / CSV: field separator + */ + fieldSeparator?: string; + + /** + * COPY / CSV: field boundary + */ + fieldBoundary?: string; + + /** + * COPY / CSV: field separator + */ + newLine?: string; + + /** + * CSV / EXCEL / PDF: file extension + */ + extension?: string; + + /** + * CSV: UTF-8 boom + */ + bom?: boolean; + + /** + * CSV: charset + */ + charset?: string|boolean; + + /** + * CSV: escape char + */ + escapeChar?: string; + + /** + * EXCEL + */ + customizeData?: FunctionButtonCustomizeData; + + /** + * PDF: portrait / landscape + */ + orientation?: string; + + /** + * PDF: A3 / A4 / A5 / LEGAL / LETTER / TABLOID + */ + pageSize?: string; + + /** + * COPY / CSV / EXCEL / PDF / PRINT: show header + */ + exportOptions?: ButtonExportOptions | object; + + /** + * COPY / CSV / EXCEL / PDF / PRINT: show header + */ + customize?: FunctionButtonCustomize; + + /** + * COPY / CSV / EXCEL / PDF / PRINT: show header + */ + header?: boolean; + + /** + * COPY / CSV / EXCEL / PDF / PRINT: show footer + */ + footer?: boolean; + + /** + * COPY / PRINT: title + */ + title?: string; + + /** + * COPY / EXCEL / PDF / PRINT: field separator + */ + messageTop?: string; + + /** + * COPY / EXCEL / PDF / PRINT: field separator + */ + messageBottom?: string; + + /** + * PDF / PRINT: Extra message + */ + message?: string|Api|JQuery|object; + + /** + * PRINT: Show print dialoge on click + */ + autoPrint?: boolean; + + /** + * COLVIS: Column selector + */ + columns?: any; + + /** + * COLVIS: + */ + columnText?: FunctionButtonColvisColumnText; +} + +type ButtonSelectorTypes = string | number | JQuery; +interface ButtonExportOptions { + columns?: ButtonSelectorTypes | ButtonSelectorTypes[]; +} + +type FunctionButtonCustomizeData = (content: any) => void; + +type FunctionButtonColvisColumnText = (dt: Api, i: number, title: string) => string;