@vuu-ui/vuu-utils 3.3.13 → 3.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.3.13",
2
+ "version": "3.3.14",
3
3
  "author": "heswell",
4
4
  "main": "./src/index.js",
5
5
  "license": "Apache-2.0",
@@ -15,14 +15,14 @@
15
15
  },
16
16
  "devDependencies": {
17
17
  "@dnd-kit/react": "^0.1.21",
18
- "@vuu-ui/vuu-data-types": "3.3.13",
19
- "@vuu-ui/vuu-table-types": "3.3.13",
20
- "@vuu-ui/vuu-filter-types": "3.3.13",
21
- "@vuu-ui/vuu-protocol-types": "3.3.13"
18
+ "@vuu-ui/vuu-data-types": "3.3.14",
19
+ "@vuu-ui/vuu-table-types": "3.3.14",
20
+ "@vuu-ui/vuu-filter-types": "3.3.14",
21
+ "@vuu-ui/vuu-protocol-types": "3.3.14"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@internationalized/date": "^3.0.0",
25
- "@vuu-ui/vuu-filter-parser": "3.3.13",
25
+ "@vuu-ui/vuu-filter-parser": "3.3.14",
26
26
  "clsx": "^2.0.0",
27
27
  "react": "^19.2.3",
28
28
  "react-dom": "^19.2.3"
@@ -1,3 +1,4 @@
1
+ const simpleIdentity = (a, b)=>a === b;
1
2
  function partition(array, test, pass = [], fail = []) {
2
3
  for(let i = 0, len = array.length; i < len; i++)(test(array[i], i) ? pass : fail).push(array[i]);
3
4
  return [
@@ -41,15 +42,15 @@ const moveItem = (items, fromIndex, toIndex)=>{
41
42
  }
42
43
  }
43
44
  };
44
- const getAddedItems = (currentItems, newItems)=>{
45
- const isNew = (i)=>!currentItems?.includes(i);
45
+ const getAddedItems = (currentItems, newItems, compareItems = simpleIdentity)=>{
46
46
  if (void 0 === currentItems) return newItems;
47
+ const isNew = (item)=>currentItems.every((currentItem)=>false === compareItems(item, currentItem));
47
48
  if (newItems.some(isNew)) return newItems.filter(isNew);
48
49
  return [];
49
50
  };
50
- const getRemovedItems = (currentItems, newItems)=>{
51
- const isRemoved = (i)=>!newItems?.includes(i);
51
+ const getRemovedItems = (currentItems, newItems, compareItems = simpleIdentity)=>{
52
52
  if (void 0 === newItems) return currentItems;
53
+ const isRemoved = (item)=>newItems.every((newItem)=>false === compareItems(item, newItem));
53
54
  if (currentItems.some(isRemoved)) return currentItems.filter(isRemoved);
54
55
  return [];
55
56
  };
@@ -1,11 +1,12 @@
1
1
  export type PartitionTest<T> = (value: T, index: number) => boolean;
2
+ export type ItemComparator<T> = (firstItem: T, secondItem: T) => boolean;
2
3
  export declare function partition<T>(array: T[], test: PartitionTest<T>, pass?: T[], fail?: T[]): [T[], T[]];
3
4
  export declare function itemsChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
4
5
  export declare function itemsOrOrderChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
5
6
  export declare const moveItemDeprecated: <T = unknown>(items: T[], item: T, moveTo: number) => T[];
6
7
  export declare const moveItem: <T = unknown>(items: T[], fromIndex: number, toIndex: number) => T[];
7
- export declare const getAddedItems: <T>(currentItems: undefined | readonly T[], newItems: readonly T[]) => readonly T[];
8
- export declare const getRemovedItems: <T>(currentItems: readonly T[], newItems: undefined | readonly T[]) => readonly T[];
8
+ export declare const getAddedItems: <T>(currentItems: undefined | readonly T[], newItems: readonly T[], compareItems?: ItemComparator<T>) => readonly T[];
9
+ export declare const getRemovedItems: <T>(currentItems: readonly T[], newItems: undefined | readonly T[], compareItems?: ItemComparator<T>) => readonly T[];
9
10
  export declare const containsSubsetOfItems: <T>(allItems: readonly T[], comparedItems: readonly T[]) => boolean;
10
11
  export declare const getMissingItems: <T, I>(sourceItems: readonly T[], items: readonly I[], identity: (s: T) => I) => I[];
11
12
  /**