@vaadin/component-base
Advanced tools
Comparing version 24.5.0-alpha1 to 24.5.0-alpha10
{ | ||
"name": "@vaadin/component-base", | ||
"version": "24.5.0-alpha1", | ||
"version": "24.5.0-alpha10", | ||
"publishConfig": { | ||
@@ -41,7 +41,7 @@ "access": "public" | ||
"devDependencies": { | ||
"@esm-bundle/chai": "^4.3.4", | ||
"@vaadin/testing-helpers": "^0.6.0", | ||
"sinon": "^13.0.2" | ||
"@vaadin/chai-plugins": "24.5.0-alpha10", | ||
"@vaadin/testing-helpers": "^1.0.0", | ||
"sinon": "^18.0.0" | ||
}, | ||
"gitHead": "57806caac5468532a3b4e3dbdda730cd0fca193a" | ||
"gitHead": "6f9c37308031af872a98017bfab4de89aeacda51" | ||
} |
@@ -7,3 +7,3 @@ # @vaadin/component-base | ||
Read the [contributing guide](https://vaadin.com/docs/latest/contributing/overview) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components. | ||
Read the [contributing guide](https://vaadin.com/docs/latest/contributing) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components. | ||
@@ -10,0 +10,0 @@ ## License |
@@ -32,5 +32,5 @@ /** | ||
return true; | ||
} catch (e) { | ||
} catch (_) { | ||
return false; | ||
} | ||
})(); |
@@ -20,9 +20,2 @@ /** | ||
/** | ||
* The number of items. | ||
* | ||
* @type {number} | ||
*/ | ||
size = 0; | ||
/** | ||
* The number of items to display per page. | ||
@@ -63,2 +56,10 @@ * | ||
/** | ||
* The number of items. | ||
* | ||
* @type {number} | ||
* @private | ||
*/ | ||
__size = 0; | ||
/** | ||
* The total number of items, including items from expanded sub-caches. | ||
@@ -81,3 +82,3 @@ * | ||
this.pageSize = pageSize; | ||
this.size = size || 0; | ||
this.size = size; | ||
this.parentCache = parentCache; | ||
@@ -143,2 +144,39 @@ this.parentCacheIndex = parentCacheIndex; | ||
/** | ||
* The number of items. | ||
* | ||
* @return {number} | ||
*/ | ||
get size() { | ||
return this.__size; | ||
} | ||
/** | ||
* Sets the number of items. | ||
* | ||
* @param {number} size | ||
*/ | ||
set size(size) { | ||
const oldSize = this.__size; | ||
if (oldSize === size) { | ||
return; | ||
} | ||
this.__size = size; | ||
if (this.context.placeholder !== undefined) { | ||
this.items.length = size || 0; | ||
for (let i = 0; i < size || 0; i++) { | ||
this.items[i] ||= this.context.placeholder; | ||
} | ||
} | ||
Object.keys(this.pendingRequests).forEach((page) => { | ||
const startIndex = parseInt(page) * this.pageSize; | ||
if (startIndex >= this.size || 0) { | ||
delete this.pendingRequests[page]; | ||
} | ||
}); | ||
} | ||
/** | ||
* Recalculates the flattened size for the cache and its descendant caches recursively. | ||
@@ -167,3 +205,6 @@ */ | ||
items.forEach((item, i) => { | ||
this.items[startIndex + i] = item; | ||
const itemIndex = startIndex + i; | ||
if (this.size === undefined || itemIndex < this.size) { | ||
this.items[itemIndex] = item; | ||
} | ||
}); | ||
@@ -170,0 +211,0 @@ } |
@@ -47,7 +47,2 @@ /** | ||
/** | ||
* A number of items in the root cache. | ||
*/ | ||
size?: number; | ||
/** | ||
* A number of items to display per page. | ||
@@ -73,2 +68,12 @@ */ | ||
/** | ||
* A placeholder item that is used to indicate that the item is not loaded yet. | ||
*/ | ||
placeholder?: unknown; | ||
/** | ||
* A callback that returns whether the given item is a placeholder. | ||
*/ | ||
isPlaceholder?: (item: unknown) => boolean; | ||
constructor( | ||
@@ -79,2 +84,4 @@ host: HTMLElement, | ||
pageSize: number; | ||
placeholder?: unknown; | ||
isPlaceholder?(item: unknown): boolean; | ||
getItemId(item: TItem): unknown; | ||
@@ -81,0 +88,0 @@ isExpanded(item: TItem): boolean; |
@@ -33,9 +33,2 @@ /** | ||
/** | ||
* A number of items in the root cache. | ||
* | ||
* @type {number} | ||
*/ | ||
size; | ||
/** | ||
* A number of items to display per page. | ||
@@ -69,3 +62,20 @@ * | ||
constructor(host, { size, pageSize, isExpanded, getItemId, dataProvider, dataProviderParams }) { | ||
/** | ||
* A placeholder item that is used to indicate that the item is not loaded yet. | ||
* | ||
* @type {unknown} | ||
*/ | ||
placeholder; | ||
/** | ||
* A callback that returns whether the given item is a placeholder. | ||
* | ||
* @type {(item: unknown) => boolean} | ||
*/ | ||
isPlaceholder; | ||
constructor( | ||
host, | ||
{ size, pageSize, isExpanded, getItemId, isPlaceholder, placeholder, dataProvider, dataProviderParams }, | ||
) { | ||
super(); | ||
@@ -76,2 +86,4 @@ this.host = host; | ||
this.isExpanded = isExpanded; | ||
this.placeholder = placeholder; | ||
this.isPlaceholder = isPlaceholder; | ||
this.dataProvider = dataProvider; | ||
@@ -93,2 +105,3 @@ this.dataProviderParams = dataProviderParams; | ||
isExpanded: this.isExpanded, | ||
placeholder: this.placeholder, | ||
// The controller instance is needed to ensure deprecated cache methods work. | ||
@@ -194,3 +207,3 @@ __controller: this, | ||
if (!item) { | ||
if (!this.__isItemLoaded(item)) { | ||
this.__loadCachePage(cache, page); | ||
@@ -210,3 +223,3 @@ } | ||
if (item && this.isExpanded(item) && !cache.getSubCache(index)) { | ||
if (this.__isItemLoaded(item) && this.isExpanded(item) && !cache.getSubCache(index)) { | ||
const subCache = cache.createSubCache(index); | ||
@@ -273,2 +286,12 @@ this.__loadCachePage(subCache, 0); | ||
} | ||
/** @private */ | ||
__isItemLoaded(item) { | ||
if (this.isPlaceholder) { | ||
return !this.isPlaceholder(item); | ||
} else if (this.placeholder) { | ||
return item !== this.placeholder; | ||
} | ||
return !!item; | ||
} | ||
} |
@@ -12,3 +12,3 @@ /** | ||
get() { | ||
return '24.5.0-alpha1'; | ||
return '24.5.0-alpha10'; | ||
}, | ||
@@ -15,0 +15,0 @@ }); |
@@ -48,3 +48,3 @@ /** | ||
return new MouseEvent('test', { buttons: 1 }).buttons === 1; | ||
} catch (e) { | ||
} catch (_) { | ||
return false; | ||
@@ -75,3 +75,3 @@ } | ||
window.removeEventListener('test', null, opts); | ||
} catch (e) {} | ||
} catch (_) {} | ||
})(); | ||
@@ -78,0 +78,0 @@ |
@@ -51,3 +51,3 @@ /** | ||
this.__resizeObserver = new ResizeObserver((entries) => { | ||
this.__resizeObserver = new ResizeObserver(() => { | ||
this.__debounceOverflow = Debouncer.debounce(this.__debounceOverflow, animationFrame, () => { | ||
@@ -54,0 +54,0 @@ this.__updateOverflow(); |
@@ -41,2 +41,3 @@ /** | ||
useUniqueId?: boolean; | ||
uniqueIdPrefix?: string; | ||
initializer?(host: HTMLElement, node: HTMLElement): void; | ||
@@ -43,0 +44,0 @@ }, |
@@ -22,4 +22,3 @@ /** | ||
*/ | ||
static generateId(host, slotName) { | ||
const prefix = slotName || 'default'; | ||
static generateId(host, prefix = 'default') { | ||
return `${prefix}-${host.localName}-${generateUniqueId()}`; | ||
@@ -31,3 +30,3 @@ } | ||
const { initializer, multiple, observe, useUniqueId } = config; | ||
const { initializer, multiple, observe, useUniqueId, uniqueIdPrefix } = config; | ||
@@ -47,3 +46,3 @@ this.host = host; | ||
if (useUniqueId) { | ||
this.defaultId = this.constructor.generateId(host, slotName); | ||
this.defaultId = this.constructor.generateId(host, uniqueIdPrefix || slotName); | ||
} | ||
@@ -50,0 +49,0 @@ } |
@@ -30,4 +30,5 @@ /** | ||
* @param {string} expected The expected URL to match. | ||
* @param {Object} matchOptions Options for path matching. | ||
*/ | ||
export function matchPaths(actual, expected) { | ||
export function matchPaths(actual, expected, matchOptions = { matchNested: false }) { | ||
const base = document.baseURI; | ||
@@ -37,7 +38,8 @@ const actualUrl = new URL(actual, base); | ||
return ( | ||
actualUrl.origin === expectedUrl.origin && | ||
actualUrl.pathname === expectedUrl.pathname && | ||
containsQueryParams(actualUrl.searchParams, expectedUrl.searchParams) | ||
); | ||
const matchesOrigin = actualUrl.origin === expectedUrl.origin; | ||
const matchesPath = matchOptions.matchNested | ||
? actualUrl.pathname === expectedUrl.pathname || actualUrl.pathname.startsWith(`${expectedUrl.pathname}/`) | ||
: actualUrl.pathname === expectedUrl.pathname; | ||
return matchesOrigin && matchesPath && containsQueryParams(actualUrl.searchParams, expectedUrl.searchParams); | ||
} |
@@ -59,3 +59,3 @@ /** | ||
this.scrollTarget.addEventListener('virtualizer-element-focused', (e) => this.__onElementFocused(e)); | ||
this.elementsContainer.addEventListener('focusin', (e) => { | ||
this.elementsContainer.addEventListener('focusin', () => { | ||
this.scrollTarget.dispatchEvent( | ||
@@ -62,0 +62,0 @@ new CustomEvent('virtualizer-element-focused', { detail: { element: this.__getFocusedElement() } }), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
216358
6412