Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@awsui/collection-hooks

Package Overview
Dependencies
Maintainers
4
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@awsui/collection-hooks - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

dist/operations/property-filter.d.ts

45

dist/interfaces.d.ts

@@ -21,2 +21,24 @@ import * as React from 'react';

export declare type TrackBy<T> = string | ((item: T) => string);
export declare type Operator = '<' | '<=' | '>' | '>=' | ':' | '!:' | '=' | '!=';
export declare type Operation = 'and' | 'or';
export interface Token {
value: string;
propertyKey?: string;
operator: Operator;
}
export interface Query {
tokens: readonly Token[];
operation: Operation;
}
export interface FilteringProperty {
key: string;
groupValuesLabel: string;
propertyLabel: string;
operators?: readonly Operator[];
group?: string;
}
export interface PropertyFilteringOption {
propertyKey: string;
value: string;
}
export interface CollectionOptions<T> {

@@ -28,2 +50,9 @@ filtering?: FilteringOptions<T> & {

};
propertyFiltering?: {
empty?: React.ReactNode;
noMatch?: React.ReactNode;
filteringProperties: readonly FilteringProperty[];
filteringFunction?: (item: T, query: Query) => boolean;
defaultQuery?: Query;
};
sorting?: {

@@ -44,2 +73,3 @@ defaultState?: SortingState<T>;

filteringText: string;
propertyFilteringQuery: Query;
currentPageIndex: number;

@@ -54,2 +84,3 @@ sortingState?: SortingState<T>;

setSelectedItems(selectedItems: ReadonlyArray<T>): void;
setPropertyFiltering(query: Query): void;
}

@@ -73,3 +104,12 @@ interface CollectionBaseResult<T> {

filteringText: string;
onChange(event: CustomEvent<{
filteringText: string;
}>): void;
};
propertyFilterProps: {
query: Query;
onChange(event: CustomEvent<Query>): void;
filteringProperties: readonly FilteringProperty[];
filteringOptions: readonly PropertyFilteringOption[];
};
paginationProps: {

@@ -85,7 +125,2 @@ disabled?: boolean;

filteredItemsCount: number | undefined;
filterProps: CollectionBaseResult<T>['filterProps'] & {
onChange(event: CustomEvent<{
filteringText: string;
}>): void;
};
paginationProps: CollectionBaseResult<T>['paginationProps'] & {

@@ -92,0 +127,0 @@ pagesCount: number;

2

dist/operations/index.d.ts
import { CollectionOptions, CollectionState } from '../interfaces';
export declare function processItems<T>(items: ReadonlyArray<T>, { filteringText, sortingState, currentPageIndex }: Partial<CollectionState<T>>, { filtering, sorting, pagination }: CollectionOptions<T>): {
export declare function processItems<T>(items: ReadonlyArray<T>, { filteringText, sortingState, currentPageIndex, propertyFilteringQuery }: Partial<CollectionState<T>>, { filtering, sorting, pagination, propertyFiltering }: CollectionOptions<T>): {
items: readonly T[];

@@ -4,0 +4,0 @@ pagesCount: number | undefined;

import { filter } from './filter.js';
import { propertyFilter } from './property-filter.js';
import { sort } from './sort.js';
import { getPagesCount, normalizePageIndex, paginate } from './paginate.js';
export function processItems(items, _a, _b) {
var filteringText = _a.filteringText, sortingState = _a.sortingState, currentPageIndex = _a.currentPageIndex;
var filtering = _b.filtering, sorting = _b.sorting, pagination = _b.pagination;
var filteringText = _a.filteringText, sortingState = _a.sortingState, currentPageIndex = _a.currentPageIndex, propertyFilteringQuery = _a.propertyFilteringQuery;
var filtering = _b.filtering, sorting = _b.sorting, pagination = _b.pagination, propertyFiltering = _b.propertyFiltering;
var result = items;

@@ -11,2 +12,6 @@ var pagesCount;

var filteredItemsCount;
if (propertyFiltering) {
result = propertyFilter(result, propertyFilteringQuery || { tokens: [], operation: 'and' }, propertyFiltering);
filteredItemsCount = result.length;
}
if (filtering) {

@@ -13,0 +18,0 @@ result = filter(result, filteringText, filtering);

/// <reference types="react" />
import { CollectionOptions, CollectionState, CollectionActions, CollectionRef } from './interfaces';
export declare function useCollectionState<T>(allItems: ReadonlyArray<T>, options: CollectionOptions<T>, collectionRef: React.RefObject<CollectionRef>): readonly [CollectionState<T>, CollectionActions<T>];
export declare function useCollectionState<T>(options: CollectionOptions<T>, collectionRef: React.RefObject<CollectionRef>): readonly [CollectionState<T>, CollectionActions<T>];
import { useReducer } from 'react';
import { createActions, collectionReducer } from './utils.js';
export function useCollectionState(allItems, options, collectionRef) {
var _a, _b, _c, _d, _e, _f, _g;
var _h = useReducer(collectionReducer, {
export function useCollectionState(options, collectionRef) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _k = useReducer(collectionReducer, {
selectedItems: (_b = (_a = options.selection) === null || _a === void 0 ? void 0 : _a.defaultSelectedItems) !== null && _b !== void 0 ? _b : [],

@@ -10,3 +10,4 @@ sortingState: (_c = options.sorting) === null || _c === void 0 ? void 0 : _c.defaultState,

filteringText: (_g = (_f = options.filtering) === null || _f === void 0 ? void 0 : _f.defaultFilteringText) !== null && _g !== void 0 ? _g : '',
}), state = _h[0], dispatch = _h[1];
propertyFilteringQuery: (_j = (_h = options.propertyFiltering) === null || _h === void 0 ? void 0 : _h.defaultQuery) !== null && _j !== void 0 ? _j : { tokens: [], operation: 'and' },
}), state = _k[0], dispatch = _k[1];
return [

@@ -13,0 +14,0 @@ state,

@@ -18,3 +18,3 @@ var __assign = (this && this.__assign) || function () {

var collectionRef = useRef(null);
var _a = useCollectionState(allItems, options, collectionRef), state = _a[0], actions = _a[1];
var _a = useCollectionState(options, collectionRef), state = _a[0], actions = _a[1];
var _b = processItems(allItems, state, options), items = _b.items, pagesCount = _b.pagesCount, filteredItemsCount = _b.filteredItemsCount, actualPageIndex = _b.actualPageIndex;

@@ -21,0 +21,0 @@ if (options.selection && !options.selection.keepSelection) {

import { Dispatch, Reducer } from 'react';
import { CollectionActions, CollectionOptions, CollectionState, SortingState, CollectionSyncResult, CollectionRef } from './interfaces';
import { CollectionActions, CollectionOptions, CollectionState, SortingState, CollectionSyncResult, CollectionRef, Query } from './interfaces';
interface SelectionAction<T> {

@@ -11,11 +11,15 @@ type: 'selection';

}
interface PaginationAction<T> {
interface PaginationAction {
type: 'pagination';
pageIndex: number;
}
interface FilteringAction<T> {
interface FilteringAction {
type: 'filtering';
filteringText: string;
}
declare type Action<T> = SelectionAction<T> | SortingAction<T> | PaginationAction<T> | FilteringAction<T>;
interface PropertyFilteringAction {
type: 'property-filtering';
query: Query;
}
declare type Action<T> = SelectionAction<T> | SortingAction<T> | PaginationAction | FilteringAction | PropertyFilteringAction;
export declare type CollectionReducer<T> = Reducer<CollectionState<T>, Action<T>>;

@@ -27,7 +31,7 @@ export declare function collectionReducer<T>(state: CollectionState<T>, action: Action<T>): CollectionState<T>;

}): CollectionActions<T>;
export declare function createSyncProps<T>(options: CollectionOptions<T>, { filteringText, sortingState, selectedItems, currentPageIndex }: CollectionState<T>, actions: CollectionActions<T>, collectionRef: React.RefObject<CollectionRef>, { pagesCount, actualPageIndex, allItems, }: {
export declare function createSyncProps<T>(options: CollectionOptions<T>, { filteringText, sortingState, selectedItems, currentPageIndex, propertyFilteringQuery }: CollectionState<T>, actions: CollectionActions<T>, collectionRef: React.RefObject<CollectionRef>, { pagesCount, actualPageIndex, allItems, }: {
pagesCount?: number;
actualPageIndex?: number;
allItems: ReadonlyArray<T>;
}): Pick<CollectionSyncResult<T>, 'collectionProps' | 'filterProps' | 'paginationProps'>;
}): Pick<CollectionSyncResult<T>, 'collectionProps' | 'filterProps' | 'paginationProps' | 'propertyFilterProps'>;
export {};

@@ -29,2 +29,6 @@ var __assign = (this && this.__assign) || function () {

break;
case 'property-filtering':
newState.currentPageIndex = 1;
newState.propertyFilteringQuery = action.query;
break;
}

@@ -51,9 +55,38 @@ return newState;

},
setPropertyFiltering: function (query) {
dispatch({ type: 'property-filtering', query: query });
collectionRef.current && collectionRef.current.scrollToTop();
},
};
}
export function createSyncProps(options, _a, actions, collectionRef, _b) {
var filteringText = _a.filteringText, sortingState = _a.sortingState, selectedItems = _a.selectedItems, currentPageIndex = _a.currentPageIndex;
var _c;
var filteringText = _a.filteringText, sortingState = _a.sortingState, selectedItems = _a.selectedItems, currentPageIndex = _a.currentPageIndex, propertyFilteringQuery = _a.propertyFilteringQuery;
var pagesCount = _b.pagesCount, actualPageIndex = _b.actualPageIndex, allItems = _b.allItems;
var empty = options.filtering
? allItems.length
? options.filtering.noMatch
: options.filtering.empty
: null;
empty = options.propertyFiltering
? allItems.length
? options.propertyFiltering.noMatch
: options.propertyFiltering.empty
: empty;
var filteringOptions = options.propertyFiltering
? options.propertyFiltering.filteringProperties.reduce(function (acc, property) {
Object.keys(allItems.reduce(function (acc, item) {
acc['' + item[property.key]] = true;
return acc;
}, {})).forEach(function (value) {
return acc.push({
propertyKey: property.key,
value: value,
});
});
return acc;
}, [])
: [];
return {
collectionProps: __assign(__assign(__assign({ empty: options.filtering ? (allItems.length ? options.filtering.noMatch : options.filtering.empty) : null }, (options.sorting
collectionProps: __assign(__assign(__assign({ empty: empty }, (options.sorting
? {

@@ -84,2 +117,11 @@ onSortingChange: function (_a) {

},
propertyFilterProps: {
query: propertyFilteringQuery,
onChange: function (_a) {
var query = _a.detail;
actions.setPropertyFiltering(query);
},
filteringProperties: ((_c = options.propertyFiltering) === null || _c === void 0 ? void 0 : _c.filteringProperties) || [],
filteringOptions: filteringOptions,
},
paginationProps: {

@@ -86,0 +128,0 @@ currentPageIndex: actualPageIndex !== null && actualPageIndex !== void 0 ? actualPageIndex : currentPageIndex,

{
"name": "@awsui/collection-hooks",
"version": "1.0.11",
"version": "1.0.12",
"type": "module",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc