From 247944266cd9c5c287f4ad6acd0d355e80d21836 Mon Sep 17 00:00:00 2001 From: Alex Iglesias Date: Sun, 10 Oct 2021 16:51:09 +0200 Subject: [PATCH] Re-refactored `getCollectionElements`, sorry for confusing you, person who's watching this commits :D --- package.json | 2 +- webflow/getCollectionElements.ts | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 66101dc..b128750 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@finsweet/ts-utils", - "version": "0.18.2", + "version": "0.18.3", "description": "Typescript utils for custom Webflow projects.", "main": "index.ts", "module": "index.ts", diff --git a/webflow/getCollectionElements.ts b/webflow/getCollectionElements.ts index 48fad54..b5a6267 100644 --- a/webflow/getCollectionElements.ts +++ b/webflow/getCollectionElements.ts @@ -18,11 +18,6 @@ const { wrapper, list, paginationNext, paginationPrevious, emptyState } = CMS_CS * @param page The page document. * @returns The specified collection element/elements. */ -export function getCollectionElements( - reference: string | Element, - target: 'items', - page?: Document -): CollectionItemElement[]; export function getCollectionElements( reference: string | Element, target: 'next' | 'previous', @@ -33,6 +28,11 @@ export function getCollectionElements( target: 'empty', page?: Document ): CollectionEmptyElement | null | undefined; +export function getCollectionElements( + reference: string | Element, + target: 'items', + page?: Document +): CollectionItemElement[]; export function getCollectionElements( reference: string | Element, target: 'list', @@ -45,7 +45,7 @@ export function getCollectionElements( ): CollectionListWrapperElement | null | undefined; export function getCollectionElements( reference: string | Element, - target: 'wrapper' | 'list' | 'empty' | 'items' | 'next' | 'previous', + target: 'wrapper' | 'list' | 'items' | 'empty' | 'next' | 'previous', page: Document = document ): | CollectionListWrapperElement @@ -66,7 +66,8 @@ export function getCollectionElements( if (target === 'list') return collectionList; if (target === 'items') return [...(collectionList?.children || [])] as CollectionItemElement[]; if (target === 'empty') return collectionListWrapper.querySelector(`.${emptyState}`); - if (target === 'next') return collectionListWrapper.querySelector(`.${paginationNext}`); - if (target === 'previous') - return collectionListWrapper.querySelector(`.${paginationPrevious}`); + + return collectionListWrapper.querySelector( + `.${target === 'next' ? paginationNext : paginationPrevious}` + ); }