From 7112b4b70b108e83a6bdc5bfc803d78f5e40259f Mon Sep 17 00:00:00 2001 From: Alex Iglesias Date: Fri, 1 Oct 2021 12:25:08 +0200 Subject: [PATCH] `getCollectionElements`: Now `items` query will return `HTMLDivElement[]` instead of `NodeListOf` --- package.json | 2 +- webflow/getCollectionElements.ts | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index f46c51a..9c51ab6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@finsweet/ts-utils", - "version": "0.13.7", + "version": "0.13.8", "description": "Typescript utils for custom Webflow projects.", "main": "index.ts", "module": "index.ts", diff --git a/webflow/getCollectionElements.ts b/webflow/getCollectionElements.ts index d04f4c3..02b6d5a 100644 --- a/webflow/getCollectionElements.ts +++ b/webflow/getCollectionElements.ts @@ -6,11 +6,7 @@ * @param page The page document. * @returns The specified collection element/elements. */ -export function getCollectionElements( - reference: string | Element, - target: 'items', - page?: Document -): NodeListOf; +export function getCollectionElements(reference: string | Element, target: 'items', page?: Document): HTMLDivElement[]; export function getCollectionElements( reference: string | Element, target: 'next' | 'previous', @@ -25,13 +21,13 @@ export function getCollectionElements( reference: string | Element, target: 'wrapper' | 'list' | 'items' | 'next' | 'previous', page: Document = document -): HTMLDivElement | NodeListOf | HTMLAnchorElement | null | undefined { +): HTMLDivElement | HTMLDivElement[] | HTMLAnchorElement | null | undefined { const referenceElement = typeof reference === 'string' ? page.querySelector(reference) : reference; if (!referenceElement) return; if (target === 'wrapper') return referenceElement.closest(`.w-dyn-list`); - if (target === 'items') return referenceElement.querySelectorAll('.w-dyn-item'); + if (target === 'items') return [...referenceElement.querySelectorAll('.w-dyn-item')]; if (target === 'next') return referenceElement.querySelector('.w-pagination-next'); if (target === 'previous') return referenceElement.querySelector('.w-pagination-previous');