From 312205dd02ed28c9a46913c8ef85251c0225b6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=83lin=20Br=C3=A2ndu=C8=99e?= Date: Thu, 15 Feb 2018 22:16:12 +0200 Subject: [PATCH 1/2] [isotope-layout] Export the module from the definitions --- types/isotope-layout/index.d.ts | 7 ++++++- types/isotope-layout/isotope-layout-tests.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/types/isotope-layout/index.d.ts b/types/isotope-layout/index.d.ts index 019aa9ec37..e9c39dea62 100644 --- a/types/isotope-layout/index.d.ts +++ b/types/isotope-layout/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for isotope 3.0 // Project: http://isotope.metafizzy.co/ // Definitions by: Anže Videnič +// Mălin Brândușe // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -270,13 +271,17 @@ interface Isotope extends IsotopeLibrary.Isotope { } declare var Isotope: { prototype: IsotopeLibrary.Isotope; - new (selector: string): IsotopeLibrary.Isotope; + new (elementOrSelector: HTMLElement | string, options: IsotopeLibrary.IsotopeOptions): IsotopeLibrary.Isotope; /** * Get the Isotope instance via its element. Isotope.data() is useful for getting the Isotope instance in JavaScript, after it has been initalized in HTML. */ data(element: HTMLElement | string): IsotopeLibrary.Isotope; }; +declare module 'isotope-layout' { + export default Isotope; +} + interface JQuery { /** * Get the Isotope instance from a jQuery object. Isotope instances are useful to access Isotope properties. diff --git a/types/isotope-layout/isotope-layout-tests.ts b/types/isotope-layout/isotope-layout-tests.ts index 648ba507ce..998e8b0392 100644 --- a/types/isotope-layout/isotope-layout-tests.ts +++ b/types/isotope-layout/isotope-layout-tests.ts @@ -98,7 +98,7 @@ $grid.isotope('layout').isotope('reloadItems').isotope('shuffle'); let iso: Isotope = $grid.data('isotope'); // test native javascript methods -iso = new Isotope('.grid'); +iso = new Isotope('.grid', {}); iso.addItems($('.items')); iso.appended(new HTMLElement()); iso.arrange({ cellsByColumn: { columnWidth: 101, rowHeight: 12 } }); From daffa70f19756c7bbc4ab6df80f61f9d0b3f56f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=83lin=20Br=C3=A2ndu=C8=99e?= Date: Thu, 15 Feb 2018 23:34:31 +0200 Subject: [PATCH 2/2] fixed lint errors --- types/isotope-layout/index.d.ts | 323 +++++++++---------- types/isotope-layout/isotope-layout-tests.ts | 1 + 2 files changed, 161 insertions(+), 163 deletions(-) diff --git a/types/isotope-layout/index.d.ts b/types/isotope-layout/index.d.ts index e9c39dea62..5e1f0623e4 100644 --- a/types/isotope-layout/index.d.ts +++ b/types/isotope-layout/index.d.ts @@ -5,9 +5,10 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -/// +export as namespace Isotope +export = Isotope; -declare namespace IsotopeLibrary { +declare namespace Isotope { type LayoutModes = 'masonry' | 'fitRows' | 'cellsByRow' | 'vertical' | 'packery' | 'masonryHorizontal' | 'fitColumns' | 'cellsByColumn' | 'horiz'; type Elements = HTMLElement[] | HTMLElement | JQuery | NodeList; @@ -124,96 +125,6 @@ declare namespace IsotopeLibrary { visibleStyle?: Style; } - interface Isotope { - /** - * Adds item elements to the Isotope instance. addItems does not lay out items like appended, prepended, or insert. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - addItems(elements: Elements): void; - /** - * Adds and lays out newly appended item elements to the end of the layout. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - appended(elements: Elements): void; - /** - * Filters, sorts, and lays out items. arrange is the principle method of Isotope. It is the default method with jQuery .isotope(). Pass in options to apply filtering and sorting. - * @param options All options are optional, but itemSelector is recommended. Layout modes have their own separate options. - */ - arrange(options: IsotopeOptions): void; - /** - * Removes the Isotope functionality completely. destroy will return the element back to its pre-initialized state. - */ - destroy(): void; - /** - * Returns an array of filtered item elements in current sorted order. - */ - getFilteredItemElements(): Element[]; - /** - * Returns an array of all item elements in the Isotope instance. - */ - getItemElements(): Element[]; - /** - * Hide items. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - hideItemElements(elements: Elements): void; - /** - * Appends elements into container element, adds elements as items, and arranges items with filtering and sorting. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - insert(elements: Elements): void; - /** - * Lays out all item elements. layout is useful when an item has changed size, and all items need to be laid out again. layout does not apply filtering or sorting. - */ - layout(): void; - /** - * Lays out specified items. - * @param elements Array of Isotope.Items - * @param isStill Disables transitions - */ - layoutItems(elements: HTMLElement[], isStill: boolean): void; - /** - * Adds and lays out newly prepended item elements at the beginning of layout. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - prepended(elements: Elements): void; - /** - * Recollects all item elements. - * For frameworks like Angular and React, reloadItems may be useful to apply changes to the DOM to Isotope. - */ - reloadItems(): void; - /** - * Removes elements from the Isotope instance and DOM. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - remove(elements: Elements): void; - /** - * Reveals hidden items. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - revealItemElements(elements: Elements): void; - /** - * Shuffles items in a random order. - */ - shuffle(): void; - /** - * Stamps elements in the layout. Isotope will lay out item elements around stamped elements. - * Stamping is only supported by some layout modes: masonry, packery and masonryhorizontal. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - stamp(elements: Elements): void; - /** - * Un-stamps elements in the layout, so that Isotope will no longer layout item elements around them. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - unstamp(elements: Elements): void; - /** - * Updates sort data - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - updateSortData(elements: Elements): void; - } - interface Sorter { [key: string]: ((itemElm: JQuery) => number | string) | string; } @@ -267,111 +178,197 @@ declare namespace IsotopeLibrary { } } -interface Isotope extends IsotopeLibrary.Isotope { } - -declare var Isotope: { - prototype: IsotopeLibrary.Isotope; - new (elementOrSelector: HTMLElement | string, options: IsotopeLibrary.IsotopeOptions): IsotopeLibrary.Isotope; +interface Isotope { /** - * Get the Isotope instance via its element. Isotope.data() is useful for getting the Isotope instance in JavaScript, after it has been initalized in HTML. + * Adds item elements to the Isotope instance. addItems does not lay out items like appended, prepended, or insert. + * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - data(element: HTMLElement | string): IsotopeLibrary.Isotope; -}; - -declare module 'isotope-layout' { - export default Isotope; -} - -interface JQuery { + addItems(elements: Isotope.Elements): void; /** - * Get the Isotope instance from a jQuery object. Isotope instances are useful to access Isotope properties. + * Adds and lays out newly appended item elements to the end of the layout. + * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - data(methodName: 'isotope'): IsotopeLibrary.Isotope; + appended(elements: Isotope.Elements): void; + /** + * Filters, sorts, and lays out items. arrange is the principle method of Isotope. It is the default method with jQuery .isotope(). Pass in options to apply filtering and sorting. + * @param options All options are optional, but itemSelector is recommended. Layout modes have their own separate options. + */ + arrange(options: Isotope.IsotopeOptions): void; + /** + * Removes the Isotope functionality completely. destroy will return the element back to its pre-initialized state. + */ + destroy(): void; + /** + * Returns an array of filtered item elements in current sorted order. + */ + getFilteredItemElements(): Element[]; + /** + * Returns an array of all item elements in the Isotope instance. + */ + getItemElements(): Element[]; + /** + * Hide items. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + hideItemElements(elements: Isotope.Elements): void; + /** + * Appends elements into container element, adds elements as items, and arranges items with filtering and sorting. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + insert(elements: Isotope.Elements): void; + /** + * Lays out all item elements. layout is useful when an item has changed size, and all items need to be laid out again. layout does not apply filtering or sorting. + */ + layout(): void; /** * Lays out specified items. * @param elements Array of Isotope.Items * @param isStill Disables transitions */ - isotope(methodName: 'layoutItems', elements: HTMLElement[], isStill: boolean): JQuery; - /** - * Adds item elements to the Isotope instance. addItems does not lay out items like appended, prepended, or insert. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - isotope(methodName: 'addItems', elements: IsotopeLibrary.Elements): JQuery; - /** - * Adds and lays out newly appended item elements to the end of the layout. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - isotope(methodName: 'appended', elements: IsotopeLibrary.Elements): JQuery; - /** - * Hide items. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - isotope(methodName: 'hideItemElements', elements: IsotopeLibrary.Elements): JQuery; - /** - * Appends elements into container element, adds elements as items, and arranges items with filtering and sorting. - * @param elements Element, jQuery Object, NodeList, or Array of Elements - */ - isotope(methodName: 'insert', elements: IsotopeLibrary.Elements): JQuery; + layoutItems(elements: HTMLElement[], isStill: boolean): void; /** * Adds and lays out newly prepended item elements at the beginning of layout. * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - isotope(methodName: 'prepended', elements: IsotopeLibrary.Elements): JQuery; + prepended(elements: Isotope.Elements): void; + /** + * Recollects all item elements. + * For frameworks like Angular and React, reloadItems may be useful to apply changes to the DOM to Isotope. + */ + reloadItems(): void; /** * Removes elements from the Isotope instance and DOM. * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - isotope(methodName: 'remove', elements: IsotopeLibrary.Elements): JQuery; + remove(elements: Isotope.Elements): void; /** * Reveals hidden items. * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - isotope(methodName: 'revealItemElements', elements: IsotopeLibrary.Elements): JQuery; + revealItemElements(elements: Isotope.Elements): void; + /** + * Shuffles items in a random order. + */ + shuffle(): void; /** * Stamps elements in the layout. Isotope will lay out item elements around stamped elements. * Stamping is only supported by some layout modes: masonry, packery and masonryhorizontal. * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - isotope(methodName: 'stamp', elements: IsotopeLibrary.Elements): JQuery; + stamp(elements: Isotope.Elements): void; /** * Un-stamps elements in the layout, so that Isotope will no longer layout item elements around them. * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - isotope(methodName: 'unstamp', elements: IsotopeLibrary.Elements): JQuery; + unstamp(elements: Isotope.Elements): void; /** * Updates sort data * @param elements Element, jQuery Object, NodeList, or Array of Elements */ - isotope(methodName: 'updateSortData', elements: IsotopeLibrary.Elements): JQuery; + updateSortData(elements: Isotope.Elements): void; +} + +declare const Isotope: { + prototype: Isotope, + new (elementOrSelector: HTMLElement | string, options: Isotope.IsotopeOptions): Isotope; /** - * Removes the Isotope functionality completely. destroy will return the element back to its pre-initialized state. + * Get the Isotope instance via its element. Isotope.data() is useful for getting the Isotope instance in JavaScript, after it has been initalized in HTML. */ - isotope(methodName: 'destroy'): void; - /** - * Returns an array of filtered item elements in current sorted order. - */ - isotope(methodName: 'getFilteredItemElements'): Element[]; - /** - * Returns an array of all item elements in the Isotope instance. - */ - isotope(methodName: 'getItemElements'): Element[]; - /** - * Lays out all item elements. layout is useful when an item has changed size, and all items need to be laid out again. layout does not apply filtering or sorting. - */ - isotope(methodName: 'layout'): JQuery; - /** - * Recollects all item elements. - * For frameworks like Angular and React, reloadItems may be useful to apply changes to the DOM to Isotope. - */ - isotope(methodName: 'reloadItems'): JQuery; - /** - * Shuffles items in a random order. - */ - isotope(methodName: 'shuffle'): JQuery; - /** - * Filters, sorts, and lays out items. Pass in options to apply filtering and sorting. - * @param options All options are optional, but itemSelector is recommended. Layout modes have their own separate options. - */ - isotope(options: IsotopeLibrary.IsotopeOptions): JQuery; + data(element: HTMLElement | string): Isotope; +}; + +declare global { + interface JQuery { + /** + * Get the Isotope instance from a jQuery object. Isotope instances are useful to access Isotope properties. + */ + data(methodName: 'isotope'): Isotope; + /** + * Lays out specified items. + * @param elements Array of Isotope.Items + * @param isStill Disables transitions + */ + isotope(methodName: 'layoutItems', elements: HTMLElement[], isStill: boolean): JQuery; + /** + * Adds item elements to the Isotope instance. addItems does not lay out items like appended, prepended, or insert. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'addItems', elements: Isotope.Elements): JQuery; + /** + * Adds and lays out newly appended item elements to the end of the layout. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'appended', elements: Isotope.Elements): JQuery; + /** + * Hide items. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'hideItemElements', elements: Isotope.Elements): JQuery; + /** + * Appends elements into container element, adds elements as items, and arranges items with filtering and sorting. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'insert', elements: Isotope.Elements): JQuery; + /** + * Adds and lays out newly prepended item elements at the beginning of layout. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'prepended', elements: Isotope.Elements): JQuery; + /** + * Removes elements from the Isotope instance and DOM. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'remove', elements: Isotope.Elements): JQuery; + /** + * Reveals hidden items. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'revealItemElements', elements: Isotope.Elements): JQuery; + /** + * Stamps elements in the layout. Isotope will lay out item elements around stamped elements. + * Stamping is only supported by some layout modes: masonry, packery and masonryhorizontal. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'stamp', elements: Isotope.Elements): JQuery; + /** + * Un-stamps elements in the layout, so that Isotope will no longer layout item elements around them. + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'unstamp', elements: Isotope.Elements): JQuery; + /** + * Updates sort data + * @param elements Element, jQuery Object, NodeList, or Array of Elements + */ + isotope(methodName: 'updateSortData', elements: Isotope.Elements): JQuery; + /** + * Removes the Isotope functionality completely. destroy will return the element back to its pre-initialized state. + */ + isotope(methodName: 'destroy'): void; + /** + * Returns an array of filtered item elements in current sorted order. + */ + isotope(methodName: 'getFilteredItemElements'): Element[]; + /** + * Returns an array of all item elements in the Isotope instance. + */ + isotope(methodName: 'getItemElements'): Element[]; + /** + * Lays out all item elements. layout is useful when an item has changed size, and all items need to be laid out again. layout does not apply filtering or sorting. + */ + isotope(methodName: 'layout'): JQuery; + /** + * Recollects all item elements. + * For frameworks like Angular and React, reloadItems may be useful to apply changes to the DOM to Isotope. + */ + isotope(methodName: 'reloadItems'): JQuery; + /** + * Shuffles items in a random order. + */ + isotope(methodName: 'shuffle'): JQuery; + /** + * Filters, sorts, and lays out items. Pass in options to apply filtering and sorting. + * @param options All options are optional, but itemSelector is recommended. Layout modes have their own separate options. + */ + isotope(options: Isotope.IsotopeOptions): JQuery; + } } diff --git a/types/isotope-layout/isotope-layout-tests.ts b/types/isotope-layout/isotope-layout-tests.ts index 998e8b0392..776412b2c2 100644 --- a/types/isotope-layout/isotope-layout-tests.ts +++ b/types/isotope-layout/isotope-layout-tests.ts @@ -1,3 +1,4 @@ +/// /* inspired by documentation at http://isotope.metafizzy.co/ */ // test all options