@xcelsior/ui-spreadsheets 1.0.2 → 1.0.3

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @xcelsior/ui-spreadsheets@1.0.2 build /home/circleci/repo/packages/ui/ui-spreadsheets
2
+ > @xcelsior/ui-spreadsheets@1.0.3 build /home/circleci/repo/packages/ui/ui-spreadsheets
3
3
  > tsup && tsc --noEmit
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  CJS Build start
12
12
  ESM Build start
13
- CJS dist/index.js 150.46 KB
13
+ CJS dist/index.js 151.12 KB
14
14
  CJS dist/index.js.map 2.63 MB
15
- CJS ⚡️ Build success in 334ms
16
- ESM dist/index.mjs 139.74 KB
15
+ CJS ⚡️ Build success in 576ms
16
+ ESM dist/index.mjs 140.30 KB
17
17
  ESM dist/index.mjs.map 2.63 MB
18
- ESM ⚡️ Build success in 335ms
18
+ ESM ⚡️ Build success in 577ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 5124ms
20
+ DTS ⚡️ Build success in 8502ms
21
21
  DTS dist/index.d.ts 22.18 KB
22
22
  DTS dist/index.d.mts 22.18 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @xcelsior/ui-spreadsheets
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - e734bf5: improve spreadsheet performance
8
+ - Updated dependencies [e734bf5]
9
+ - @xcelsior/utils@1.0.1
10
+
3
11
  ## 1.0.2
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2179,6 +2179,7 @@ var import_design_system = require("@xcelsior/design-system");
2179
2179
 
2180
2180
  // src/hooks/useSpreadsheetFiltering.ts
2181
2181
  var import_react10 = require("react");
2182
+ var import_utils9 = require("@xcelsior/utils");
2182
2183
  function useSpreadsheetFiltering({
2183
2184
  data,
2184
2185
  columns,
@@ -2325,19 +2326,10 @@ function useSpreadsheetFiltering({
2325
2326
  },
2326
2327
  []
2327
2328
  );
2328
- const filteredData = (0, import_react10.useMemo)(() => {
2329
- if (!data || !Array.isArray(data)) return [];
2330
- if (serverSide) {
2331
- return data;
2332
- }
2333
- if (!columns || !Array.isArray(columns)) return data;
2334
- let result = [...data];
2335
- for (const [columnId, filter] of Object.entries(filters)) {
2336
- if (!filter) continue;
2337
- const column = columns.find((c) => c.id === columnId);
2338
- if (!column) continue;
2339
- result = result.filter((row) => {
2340
- const value = column.getValue ? column.getValue(row) : row[columnId];
2329
+ const buildFilterPredicate = (0, import_react10.useCallback)(
2330
+ (column, filter) => {
2331
+ return (row) => {
2332
+ const value = column.getValue ? column.getValue(row) : row[column.id];
2341
2333
  if (filter.includeBlanks && isBlankValue(value)) {
2342
2334
  return true;
2343
2335
  }
@@ -2364,32 +2356,48 @@ function useSpreadsheetFiltering({
2364
2356
  if (filter.max !== void 0 && numValue > Number(filter.max)) return false;
2365
2357
  }
2366
2358
  return true;
2367
- });
2368
- }
2369
- if (sortConfig) {
2370
- const column = columns.find((c) => c.id === sortConfig.columnId);
2371
- result.sort((a, b) => {
2372
- const aValue = column?.getValue ? column.getValue(a) : a[sortConfig.columnId];
2373
- const bValue = column?.getValue ? column.getValue(b) : b[sortConfig.columnId];
2359
+ };
2360
+ },
2361
+ [applyTextCondition, applyNumberCondition, applyDateCondition]
2362
+ );
2363
+ const buildSortComparator = (0, import_react10.useCallback)(
2364
+ (column, direction) => {
2365
+ return (a, b) => {
2366
+ const aValue = column?.getValue ? column.getValue(a) : a[sortConfig?.columnId];
2367
+ const bValue = column?.getValue ? column.getValue(b) : b[sortConfig?.columnId];
2374
2368
  if (aValue === null || aValue === void 0) return 1;
2375
2369
  if (bValue === null || bValue === void 0) return -1;
2376
2370
  if (typeof aValue === "string" && typeof bValue === "string") {
2377
- return sortConfig.direction === "asc" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
2371
+ return direction === "asc" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
2378
2372
  }
2379
- return sortConfig.direction === "asc" ? aValue < bValue ? -1 : aValue > bValue ? 1 : 0 : aValue > bValue ? -1 : aValue < bValue ? 1 : 0;
2380
- });
2373
+ return direction === "asc" ? aValue < bValue ? -1 : aValue > bValue ? 1 : 0 : aValue > bValue ? -1 : aValue < bValue ? 1 : 0;
2374
+ };
2375
+ },
2376
+ [sortConfig?.columnId]
2377
+ );
2378
+ const filteredData = (0, import_react10.useMemo)(() => {
2379
+ if (!data || !Array.isArray(data)) return import_utils9.LazyArray.empty();
2380
+ if (serverSide) {
2381
+ return import_utils9.LazyArray.from(data);
2381
2382
  }
2382
- return result;
2383
- }, [
2384
- data,
2385
- filters,
2386
- sortConfig,
2387
- columns,
2388
- serverSide,
2389
- applyDateCondition,
2390
- applyNumberCondition,
2391
- applyTextCondition
2392
- ]);
2383
+ if (!columns || !Array.isArray(columns)) return import_utils9.LazyArray.from(data);
2384
+ let lazyResult = import_utils9.LazyArray.from(data);
2385
+ const filterChain = new import_utils9.FilterChain();
2386
+ for (const [columnId, filter] of Object.entries(filters)) {
2387
+ if (!filter) continue;
2388
+ const column = columns.find((c) => c.id === columnId);
2389
+ if (!column) continue;
2390
+ filterChain.add(buildFilterPredicate(column, filter));
2391
+ }
2392
+ if (!filterChain.isEmpty) {
2393
+ lazyResult = filterChain.applyTo(lazyResult);
2394
+ }
2395
+ if (sortConfig) {
2396
+ const column = columns.find((c) => c.id === sortConfig.columnId);
2397
+ lazyResult = lazyResult.sort(buildSortComparator(column, sortConfig.direction));
2398
+ }
2399
+ return lazyResult;
2400
+ }, [data, filters, sortConfig, columns, serverSide, buildFilterPredicate, buildSortComparator]);
2393
2401
  const handleFilterChange = (0, import_react10.useCallback)(
2394
2402
  (columnId, filter) => {
2395
2403
  const newFilters = { ...filters };