@vuu-ui/vuu-utils 4.0.0-alpha.1 → 4.0.0-alpha.10

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": "4.0.0-alpha.1",
2
+ "version": "4.0.0-alpha.10",
3
3
  "author": "heswell",
4
4
  "main": "./src/index.js",
5
5
  "license": "Apache-2.0",
@@ -16,14 +16,14 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@dnd-kit/react": "^0.1.21",
19
- "@vuu-ui/vuu-data-types": "4.0.0-alpha.1",
20
- "@vuu-ui/vuu-table-types": "4.0.0-alpha.1",
21
- "@vuu-ui/vuu-filter-types": "4.0.0-alpha.1",
22
- "@vuu-ui/vuu-protocol-types": "4.0.0-alpha.1"
19
+ "@vuu-ui/vuu-data-types": "4.0.0-alpha.10",
20
+ "@vuu-ui/vuu-table-types": "4.0.0-alpha.10",
21
+ "@vuu-ui/vuu-filter-types": "4.0.0-alpha.10",
22
+ "@vuu-ui/vuu-protocol-types": "4.0.0-alpha.10"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@internationalized/date": "^3.0.0",
26
- "@vuu-ui/vuu-filter-parser": "4.0.0-alpha.1",
26
+ "@vuu-ui/vuu-filter-parser": "4.0.0-alpha.10",
27
27
  "clsx": "^2.0.0",
28
28
  "react": "^19.2.3",
29
29
  "react-dom": "^19.2.3"
@@ -38,6 +38,7 @@
38
38
  "exports": {
39
39
  ".": {
40
40
  "import": "./src/index.js",
41
+ "default": "./src/index.js",
41
42
  "types": "./types/index.d.ts"
42
43
  }
43
44
  },
@@ -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,12 +42,23 @@ const moveItem = (items, fromIndex, toIndex)=>{
41
42
  }
42
43
  }
43
44
  };
44
- const getAddedItems = (values, newValues)=>{
45
- const isNew = (v)=>!values?.includes(v);
46
- if (void 0 === values) return newValues;
47
- if (newValues.some(isNew)) return newValues.filter(isNew);
45
+ const getAddedItems = (currentItems, newItems, compareItems = simpleIdentity)=>{
46
+ if (void 0 === currentItems) return newItems;
47
+ const isNew = (item)=>currentItems.every((currentItem)=>false === compareItems(item, currentItem));
48
+ if (newItems.some(isNew)) return newItems.filter(isNew);
48
49
  return [];
49
50
  };
51
+ const getRemovedItems = (currentItems, newItems, compareItems = simpleIdentity)=>{
52
+ if (void 0 === newItems) return currentItems;
53
+ const isRemoved = (item)=>newItems.every((newItem)=>false === compareItems(item, newItem));
54
+ if (currentItems.some(isRemoved)) return currentItems.filter(isRemoved);
55
+ return [];
56
+ };
57
+ const containsSubsetOfItems = (allItems, comparedItems)=>{
58
+ if (comparedItems.length > allItems.length) return false;
59
+ const invalidItems = getAddedItems(allItems, comparedItems);
60
+ return 0 === invalidItems.length;
61
+ };
50
62
  const getMissingItems = (sourceItems, items, identity)=>items.filter((i)=>-1 === sourceItems.findIndex((s)=>identity(s) === i));
51
63
  const reorderItems = (originalItems, orderedNames)=>{
52
64
  const orderedItems = [];
@@ -58,4 +70,4 @@ const reorderItems = (originalItems, orderedNames)=>{
58
70
  }
59
71
  return orderedItems;
60
72
  };
61
- export { getAddedItems, getMissingItems, itemsChanged, itemsOrOrderChanged, moveItem, moveItemDeprecated, partition, reorderItems };
73
+ export { containsSubsetOfItems, getAddedItems, getMissingItems, getRemovedItems, itemsChanged, itemsOrOrderChanged, moveItem, moveItemDeprecated, partition, reorderItems };
package/src/form-utils.js CHANGED
@@ -38,11 +38,15 @@ function getTypedValue(value, type, throwIfInvalid = false, options) {
38
38
  case "int":
39
39
  if (stringIsValidInt(value)) return parseInt(value, 10);
40
40
  if (!throwIfInvalid) return;
41
- throw Error(`value ${value} is not a valid ${type}`);
41
+ throw new DataValidationError(`value ${value} is not a valid ${type}`, "whole number", getActualType(value));
42
42
  case "long":
43
43
  if (stringIsValidLong(value)) return value;
44
44
  if (!throwIfInvalid) return;
45
- throw Error(`value ${value} is not a valid ${type}`);
45
+ throw new DataValidationError(`value ${value} is not a valid ${type}`, "whole number", getActualType(value));
46
+ case "char":
47
+ if (1 === value.length) return value;
48
+ if (!throwIfInvalid) return;
49
+ throw new DataValidationError(`value ${value} is not a valid ${type}`, "single character", getActualType(value));
46
50
  case "scaleddecimal2":
47
51
  return ScaledDecimal2(value);
48
52
  case "scaleddecimal4":
@@ -29,7 +29,7 @@ const getTargetSize = (element, size, dimension)=>{
29
29
  return 0;
30
30
  }
31
31
  };
32
- const resizeObserver = new ResizeObserver((entries)=>{
32
+ const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver((entries)=>{
33
33
  for (const entry of entries){
34
34
  const { target, borderBoxSize, contentBoxSize } = entry;
35
35
  const observedTarget = observedMap.get(target);
@@ -81,7 +81,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
81
81
  if (observedTarget) {
82
82
  const measurements = measure(target);
83
83
  observedTarget.measurements = measurements;
84
- resizeObserver.observe(target);
84
+ resizeObserver?.observe(target);
85
85
  if (reportInitialSize) onResize(measurements);
86
86
  } else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation", "font-weight:bold; color:red;");
87
87
  }
@@ -93,7 +93,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
93
93
  }
94
94
  return ()=>{
95
95
  if (target && observedMap.has(target)) {
96
- resizeObserver.unobserve(target);
96
+ resizeObserver?.unobserve(target);
97
97
  observedMap.delete(target);
98
98
  }
99
99
  };
@@ -1,11 +1,14 @@
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
- export declare function itemsChanged<T = unknown>(currentItems: T[], newItems: T[], identityProperty?: string): boolean;
4
- export declare function itemsOrOrderChanged<T = unknown>(currentItems: T[], newItems: T[], identityProperty?: string): boolean;
4
+ export declare function itemsChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
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>(values: undefined | T[], newValues: T[]) => T[];
8
- export declare const getMissingItems: <T, I>(sourceItems: T[], items: I[], identity: (s: T) => I) => I[];
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[];
10
+ export declare const containsSubsetOfItems: <T>(allItems: readonly T[], comparedItems: readonly T[]) => boolean;
11
+ export declare const getMissingItems: <T, I>(sourceItems: readonly T[], items: readonly I[], identity: (s: T) => I) => I[];
9
12
  /**
10
13
  * Given an ordered list of item names, return items in same order
11
14
  */
@@ -171,39 +171,7 @@ export declare const setCalculatedColumnType: (column: ColumnDescriptor, serverD
171
171
  export declare const setCalculatedColumnExpression: (column: ColumnDescriptor, expression: string) => ColumnDescriptor;
172
172
  export declare const moveColumnTo: (columns: ColumnDescriptor[], column: ColumnDescriptor, newIndex: number) => ColumnDescriptor[];
173
173
  export declare function replaceColumn<C extends ColumnDescriptor = RuntimeColumnDescriptor>(columns: readonly C[], column: C): C[];
174
- export declare const applyDefaultColumnConfig: ({ columns: columnsProp, table }: TableSchema, getDefaultColumnConfig?: DefaultColumnConfiguration, includeVuuDefaultColumns?: boolean) => (SchemaColumn | {
175
- aggregate?: VuuAggType;
176
- align?: ColumnAlignment;
177
- allowColumnHeaderMenu?: false;
178
- className?: string;
179
- colHeaderContentRenderer?: string;
180
- colHeaderLabelRenderer?: string;
181
- exportFormatter?: (value: unknown) => string;
182
- flex?: number;
183
- getIcon?: (row: DataRow) => string | undefined;
184
- groupable?: boolean;
185
- heading?: string[];
186
- hidden?: boolean;
187
- isSystemColumn?: boolean;
188
- locked?: Exclude<PinLocation, "left"> | false;
189
- maxWidth?: number;
190
- minWidth?: number;
191
- pin?: PinLocation | false;
192
- removeable?: boolean;
193
- resizeable?: boolean;
194
- selected?: boolean;
195
- sortable?: boolean;
196
- source?: "client" | "server";
197
- status?: import("@salt-ds/core").ValidationStatus;
198
- width?: number;
199
- editableBulk?: import("@vuu-ui/vuu-data-types").BulkEdit;
200
- label?: string;
201
- required?: boolean;
202
- type?: DataValueType;
203
- editable?: import("@vuu-ui/vuu-data-types").DataEditable | undefined;
204
- name: string;
205
- serverDataType: VuuColumnDataType;
206
- })[] | readonly SchemaColumn[];
174
+ export declare const applyDefaultColumnConfig: ({ columns: columnsProp, table }: TableSchema, getDefaultColumnConfig?: DefaultColumnConfiguration, includeVuuDefaultColumns?: boolean) => readonly SchemaColumn[];
207
175
  export type columnOptions = {
208
176
  availableWidth?: number;
209
177
  columnLayout?: ColumnLayout;