@awsui/collection-hooks
Advanced tools
Comparing version 1.0.36 to 1.0.37
export { useCollection } from './use-collection.js'; | ||
export { CollectionRef, FilteringOptions, UseCollectionOptions, UseCollectionResult, PropertyFilterOperator, PropertyFilterOperation, PropertyFilterToken, PropertyFilterQuery, PropertyFilterProperty, PropertyFilterOption, } from './interfaces'; | ||
export { CollectionRef, FilteringOptions, UseCollectionOptions, UseCollectionResult, PropertyFilterOperator, PropertyFilterOperatorExtended, PropertyFilterOperatorMatch, PropertyFilterOperation, PropertyFilterToken, PropertyFilterQuery, PropertyFilterProperty, PropertyFilterOption, } from './interfaces'; |
"use strict"; | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useCollection = void 0; | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
var use_collection_js_1 = require("./use-collection.js"); | ||
Object.defineProperty(exports, "useCollection", { enumerable: true, get: function () { return use_collection_js_1.useCollection; } }); |
@@ -105,5 +105,12 @@ import * as React from 'react'; | ||
export declare type PropertyFilterOperator = '<' | '<=' | '>' | '>=' | ':' | '!:' | '=' | '!='; | ||
export interface PropertyFilterOperatorExtended<TokenValue> { | ||
operator: PropertyFilterOperator; | ||
match?: PropertyFilterOperatorMatch<TokenValue>; | ||
} | ||
export declare type PropertyFilterOperatorMatch<TokenValue> = PropertyFilterOperatorMatchByType | PropertyFilterOperatorMatchCustom<TokenValue>; | ||
export declare type PropertyFilterOperatorMatchByType = 'date' | 'datetime'; | ||
export declare type PropertyFilterOperatorMatchCustom<TokenValue> = (itemValue: unknown, tokenValue: TokenValue) => boolean; | ||
export declare type PropertyFilterOperation = 'and' | 'or'; | ||
export interface PropertyFilterToken { | ||
value: string; | ||
value: any; | ||
propertyKey?: string; | ||
@@ -116,7 +123,7 @@ operator: PropertyFilterOperator; | ||
} | ||
export interface PropertyFilterProperty { | ||
export interface PropertyFilterProperty<TokenValue = any> { | ||
key: string; | ||
groupValuesLabel: string; | ||
propertyLabel: string; | ||
operators?: readonly PropertyFilterOperator[]; | ||
operators?: readonly (PropertyFilterOperator | PropertyFilterOperatorExtended<TokenValue>)[]; | ||
defaultOperator?: PropertyFilterOperator; | ||
@@ -123,0 +130,0 @@ group?: string; |
@@ -1,10 +0,3 @@ | ||
import { PropertyFilterOperator, PropertyFilterQuery, UseCollectionOptions } from '../interfaces'; | ||
export declare type FilteringPropertiesMap<T> = { | ||
[key in keyof T]: { | ||
operators: { | ||
[key in PropertyFilterOperator]?: true; | ||
}; | ||
}; | ||
}; | ||
import { PropertyFilterQuery, UseCollectionOptions } from '../interfaces'; | ||
export declare function propertyFilter<T>(items: ReadonlyArray<T>, query: PropertyFilterQuery, { filteringFunction, filteringProperties }: NonNullable<UseCollectionOptions<T>['propertyFiltering']>): ReadonlyArray<T>; | ||
export declare const fixupFalsyValues: <T>(value: T) => string | T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fixupFalsyValues = exports.propertyFilter = void 0; | ||
var filterUsingOperator = function (itemValue, tokenValue, operator) { | ||
var compare_dates_js_1 = require("../date-utils/compare-dates.js"); | ||
var filterUsingOperator = function (itemValue, tokenValue, _a) { | ||
var operator = _a.operator, match = _a.match; | ||
if (match === 'date' || match === 'datetime') { | ||
var comparator = match === 'date' ? compare_dates_js_1.compareDates : compare_dates_js_1.compareTimestamps; | ||
var comparisonResult = comparator(itemValue, tokenValue); | ||
switch (operator) { | ||
case '<': | ||
return comparisonResult < 0; | ||
case '<=': | ||
return comparisonResult <= 0; | ||
case '>': | ||
return comparisonResult > 0; | ||
case '>=': | ||
return comparisonResult >= 0; | ||
case '=': | ||
return comparisonResult === 0; | ||
case '!=': | ||
return comparisonResult !== 0; | ||
default: | ||
return false; | ||
} | ||
} | ||
else if (typeof match === 'function') { | ||
return match(itemValue, tokenValue); | ||
} | ||
else if (match) { | ||
throw new Error('Unsupported `operator.match` type given.'); | ||
} | ||
switch (operator) { | ||
@@ -29,3 +57,3 @@ case '<': | ||
var operators = filteringPropertiesMap[propertyKey].operators; | ||
return !!operators[operator] && filterUsingOperator(item[propertyKey], value, ':'); | ||
return (!!operators[operator] && filterUsingOperator(item[propertyKey], value, { operator: ':' })); | ||
}); | ||
@@ -42,3 +70,4 @@ return operator === ':' ? matches : !matches; | ||
var itemValue = (0, exports.fixupFalsyValues)(item[token.propertyKey]); | ||
return filterUsingOperator(itemValue, token.value, token.operator); | ||
var operator = filteringPropertiesMap[token.propertyKey].operators[token.operator]; | ||
return filterUsingOperator(itemValue, token.value, operator !== null && operator !== void 0 ? operator : { operator: token.operator }); | ||
} | ||
@@ -66,6 +95,13 @@ return freeTextFilter(token.value, item, token.operator, filteringPropertiesMap); | ||
var key = _a.key, operators = _a.operators, defaultOperator = _a.defaultOperator; | ||
var operatorSet = (_b = {}, _b[defaultOperator !== null && defaultOperator !== void 0 ? defaultOperator : '='] = true, _b); | ||
operators === null || operators === void 0 ? void 0 : operators.forEach(function (op) { return (operatorSet[op] = true); }); | ||
var operatorMap = (_b = {}, _b[defaultOperator !== null && defaultOperator !== void 0 ? defaultOperator : '='] = { operator: defaultOperator !== null && defaultOperator !== void 0 ? defaultOperator : '=' }, _b); | ||
operators === null || operators === void 0 ? void 0 : operators.forEach(function (op) { | ||
if (typeof op === 'string') { | ||
operatorMap[op] = { operator: op }; | ||
} | ||
else { | ||
operatorMap[op.operator] = { operator: op.operator, match: op.match }; | ||
} | ||
}); | ||
acc[key] = { | ||
operators: operatorSet, | ||
operators: operatorMap, | ||
}; | ||
@@ -72,0 +108,0 @@ return acc; |
export { useCollection } from './use-collection.js'; | ||
export { CollectionRef, FilteringOptions, UseCollectionOptions, UseCollectionResult, PropertyFilterOperator, PropertyFilterOperation, PropertyFilterToken, PropertyFilterQuery, PropertyFilterProperty, PropertyFilterOption, } from './interfaces'; | ||
export { CollectionRef, FilteringOptions, UseCollectionOptions, UseCollectionResult, PropertyFilterOperator, PropertyFilterOperatorExtended, PropertyFilterOperatorMatch, PropertyFilterOperation, PropertyFilterToken, PropertyFilterQuery, PropertyFilterProperty, PropertyFilterOption, } from './interfaces'; |
@@ -105,5 +105,12 @@ import * as React from 'react'; | ||
export declare type PropertyFilterOperator = '<' | '<=' | '>' | '>=' | ':' | '!:' | '=' | '!='; | ||
export interface PropertyFilterOperatorExtended<TokenValue> { | ||
operator: PropertyFilterOperator; | ||
match?: PropertyFilterOperatorMatch<TokenValue>; | ||
} | ||
export declare type PropertyFilterOperatorMatch<TokenValue> = PropertyFilterOperatorMatchByType | PropertyFilterOperatorMatchCustom<TokenValue>; | ||
export declare type PropertyFilterOperatorMatchByType = 'date' | 'datetime'; | ||
export declare type PropertyFilterOperatorMatchCustom<TokenValue> = (itemValue: unknown, tokenValue: TokenValue) => boolean; | ||
export declare type PropertyFilterOperation = 'and' | 'or'; | ||
export interface PropertyFilterToken { | ||
value: string; | ||
value: any; | ||
propertyKey?: string; | ||
@@ -116,7 +123,7 @@ operator: PropertyFilterOperator; | ||
} | ||
export interface PropertyFilterProperty { | ||
export interface PropertyFilterProperty<TokenValue = any> { | ||
key: string; | ||
groupValuesLabel: string; | ||
propertyLabel: string; | ||
operators?: readonly PropertyFilterOperator[]; | ||
operators?: readonly (PropertyFilterOperator | PropertyFilterOperatorExtended<TokenValue>)[]; | ||
defaultOperator?: PropertyFilterOperator; | ||
@@ -123,0 +130,0 @@ group?: string; |
@@ -1,10 +0,3 @@ | ||
import { PropertyFilterOperator, PropertyFilterQuery, UseCollectionOptions } from '../interfaces'; | ||
export declare type FilteringPropertiesMap<T> = { | ||
[key in keyof T]: { | ||
operators: { | ||
[key in PropertyFilterOperator]?: true; | ||
}; | ||
}; | ||
}; | ||
import { PropertyFilterQuery, UseCollectionOptions } from '../interfaces'; | ||
export declare function propertyFilter<T>(items: ReadonlyArray<T>, query: PropertyFilterQuery, { filteringFunction, filteringProperties }: NonNullable<UseCollectionOptions<T>['propertyFiltering']>): ReadonlyArray<T>; | ||
export declare const fixupFalsyValues: <T>(value: T) => string | T; |
@@ -1,2 +0,30 @@ | ||
var filterUsingOperator = function (itemValue, tokenValue, operator) { | ||
import { compareDates, compareTimestamps } from '../date-utils/compare-dates.js'; | ||
var filterUsingOperator = function (itemValue, tokenValue, _a) { | ||
var operator = _a.operator, match = _a.match; | ||
if (match === 'date' || match === 'datetime') { | ||
var comparator = match === 'date' ? compareDates : compareTimestamps; | ||
var comparisonResult = comparator(itemValue, tokenValue); | ||
switch (operator) { | ||
case '<': | ||
return comparisonResult < 0; | ||
case '<=': | ||
return comparisonResult <= 0; | ||
case '>': | ||
return comparisonResult > 0; | ||
case '>=': | ||
return comparisonResult >= 0; | ||
case '=': | ||
return comparisonResult === 0; | ||
case '!=': | ||
return comparisonResult !== 0; | ||
default: | ||
return false; | ||
} | ||
} | ||
else if (typeof match === 'function') { | ||
return match(itemValue, tokenValue); | ||
} | ||
else if (match) { | ||
throw new Error('Unsupported `operator.match` type given.'); | ||
} | ||
switch (operator) { | ||
@@ -26,3 +54,3 @@ case '<': | ||
var operators = filteringPropertiesMap[propertyKey].operators; | ||
return !!operators[operator] && filterUsingOperator(item[propertyKey], value, ':'); | ||
return (!!operators[operator] && filterUsingOperator(item[propertyKey], value, { operator: ':' })); | ||
}); | ||
@@ -39,3 +67,4 @@ return operator === ':' ? matches : !matches; | ||
var itemValue = fixupFalsyValues(item[token.propertyKey]); | ||
return filterUsingOperator(itemValue, token.value, token.operator); | ||
var operator = filteringPropertiesMap[token.propertyKey].operators[token.operator]; | ||
return filterUsingOperator(itemValue, token.value, operator !== null && operator !== void 0 ? operator : { operator: token.operator }); | ||
} | ||
@@ -63,6 +92,13 @@ return freeTextFilter(token.value, item, token.operator, filteringPropertiesMap); | ||
var key = _a.key, operators = _a.operators, defaultOperator = _a.defaultOperator; | ||
var operatorSet = (_b = {}, _b[defaultOperator !== null && defaultOperator !== void 0 ? defaultOperator : '='] = true, _b); | ||
operators === null || operators === void 0 ? void 0 : operators.forEach(function (op) { return (operatorSet[op] = true); }); | ||
var operatorMap = (_b = {}, _b[defaultOperator !== null && defaultOperator !== void 0 ? defaultOperator : '='] = { operator: defaultOperator !== null && defaultOperator !== void 0 ? defaultOperator : '=' }, _b); | ||
operators === null || operators === void 0 ? void 0 : operators.forEach(function (op) { | ||
if (typeof op === 'string') { | ||
operatorMap[op] = { operator: op }; | ||
} | ||
else { | ||
operatorMap[op.operator] = { operator: op.operator, match: op.match }; | ||
} | ||
}); | ||
acc[key] = { | ||
operators: operatorSet, | ||
operators: operatorMap, | ||
}; | ||
@@ -69,0 +105,0 @@ return acc; |
{ | ||
"bundleDependencies": false, | ||
"commit": "a9d72bb", | ||
"commit": "5726a4d", | ||
"deprecated": false, | ||
@@ -50,4 +50,4 @@ "exports": { | ||
"type": "module", | ||
"version": "1.0.36", | ||
"version": "1.0.37", | ||
"license": "Apache-2.0" | ||
} |
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
77829
59
1443