@infinite-table/infinite-react 0.0.4 → 0.0.5

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.
Files changed (4) hide show
  1. package/index.d.ts +75 -56
  2. package/index.esm.js +144 -115
  3. package/index.js +144 -115
  4. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -327,45 +327,6 @@ declare module "components/DataSource/state/getInitialState" {
327
327
  state: DataSourceState<T>;
328
328
  }): DataSourceDerivedState<T>;
329
329
  }
330
- declare module "components/DataSource/state/reducer" {
331
- import type { DataSourceState, DataSourceDerivedState } from "components/DataSource/types";
332
- export function concludeReducer<T>(params: {
333
- previousState: DataSourceState<T> & DataSourceDerivedState<T>;
334
- state: DataSourceState<T> & DataSourceDerivedState<T>;
335
- }): DataSourceState<T> & DataSourceDerivedState<T>;
336
- }
337
- declare module "components/DataSource/index" {
338
- import { DataSourceProps } from "components/DataSource/types";
339
- import { useDataSource } from "components/DataSource/publicHooks/useDataSource";
340
- import { GroupRowsState } from "components/DataSource/GroupRowsState";
341
- function DataSource<T>(props: DataSourceProps<T>): JSX.Element;
342
- export { useDataSource, DataSource, GroupRowsState };
343
- export * from "components/DataSource/types";
344
- }
345
- declare module "components/DataSource/GroupRowsState" {
346
- import { DataSourceExpandedAndCollapsedGroupRows } from "components/DataSource/index";
347
- export class GroupRowsState<KeyType extends any = any> {
348
- private expandedMap?;
349
- private collapsedMap?;
350
- private collapsedAll;
351
- private expandedAll;
352
- private initialState;
353
- constructor(state: DataSourceExpandedAndCollapsedGroupRows<KeyType> | GroupRowsState<KeyType>);
354
- getState(): DataSourceExpandedAndCollapsedGroupRows<KeyType>;
355
- destroy(): void;
356
- private update;
357
- areAllCollapsed(): boolean;
358
- areAllExpanded(): boolean;
359
- collapseAll(): void;
360
- expandAll(): void;
361
- isGroupRowExpanded(keys: KeyType[]): boolean | undefined;
362
- isGroupRowCollapsed(keys: KeyType[]): boolean;
363
- setGroupRowExpanded(keys: KeyType[], shouldExpand: boolean): void;
364
- collapseGroupRow(keys: KeyType[]): void;
365
- expandGroupRow(keys: KeyType[]): void;
366
- toggleGroupRow(keys: KeyType[]): void;
367
- }
368
- }
369
330
  declare module "components/types/Renderable" {
370
331
  import * as React from 'react';
371
332
  export type Renderable = React.ReactNode;
@@ -393,6 +354,7 @@ declare module "components/InfiniteTable/types/InfiniteTableColumn" {
393
354
  import type { DiscriminatedUnion, RequireAtLeastOne } from "components/InfiniteTable/types/Utility";
394
355
  import type { InfiniteTableRowInfo } from "components/InfiniteTable/types/index";
395
356
  import { CSSProperties } from 'react';
357
+ import { PivotBy } from "utils/groupAndPivot/index";
396
358
  export type { DiscriminatedUnion, RequireAtLeastOne };
397
359
  export type InfiniteTableToggleGroupRowFn = (groupKeys: any[]) => void;
398
360
  export interface InfiniteTableColumnRenderParam<DATA_TYPE, COL_TYPE = InfiniteTableComputedColumn<DATA_TYPE>> {
@@ -495,7 +457,16 @@ declare module "components/InfiniteTable/types/InfiniteTableColumn" {
495
457
  pivotColumn?: true;
496
458
  pivotTotalColumn?: true;
497
459
  pivotGroupKeys?: any[];
498
- renderValue?: InfiniteTableColumnRenderValueFunction<T>;
460
+ pivotByForColumn?: DataSourcePivotBy<T>;
461
+ pivotIndexForColumn?: number;
462
+ pivotGroupKeyForColumn?: any;
463
+ };
464
+ export type InfiniteTablePivotFinalColumn<DataType, KeyType extends any = any> = InfiniteTablePivotColumn<DataType> & {
465
+ pivotBy: DataSourcePivotBy<DataType>[];
466
+ pivotGroupKeys: KeyType[];
467
+ pivotByForColumn: PivotBy<DataType, KeyType>;
468
+ pivotIndexForColumn: number;
469
+ pivotGroupKeyForColumn: KeyType;
499
470
  };
500
471
  type InfiniteTableComputedColumnBase<T> = {
501
472
  computedWidth: number;
@@ -521,12 +492,61 @@ declare module "components/InfiniteTable/types/InfiniteTableColumn" {
521
492
  };
522
493
  export type InfiniteTableComputedColumn<T> = InfiniteTableColumn<T> & InfiniteTableComputedColumnBase<T> & InfiniteTablePivotColumn<T> & InfiniteTableGeneratedGroupColumn<T>;
523
494
  }
495
+ declare module "utils/groupAndPivot/getPivotColumnsAndColumnGroups" {
496
+ import type { DataSourcePivotBy } from "components/DataSource/index";
497
+ import type { InfiniteTablePropColumnGroups, InfiniteTablePropColumns } from "components/InfiniteTable/index";
498
+ import type { InfiniteTablePivotColumn } from "components/InfiniteTable/types/InfiniteTableColumn";
499
+ import type { InfiniteTablePropPivotTotalColumnPosition } from "components/InfiniteTable/types/InfiniteTableState";
500
+ import { DeepMap } from "utils/DeepMap";
501
+ export type ComputedColumnsAndGroups<DataType> = {
502
+ columns: InfiniteTablePropColumns<DataType, InfiniteTablePivotColumn<DataType>>;
503
+ columnGroups: InfiniteTablePropColumnGroups;
504
+ };
505
+ export function getPivotColumnsAndColumnGroups<DataType, KeyType = any>(deepMap: DeepMap<KeyType, boolean>, pivotBy: DataSourcePivotBy<DataType>[], pivotTotalColumnPosition: InfiniteTablePropPivotTotalColumnPosition): ComputedColumnsAndGroups<DataType>;
506
+ }
507
+ declare module "components/DataSource/state/reducer" {
508
+ import type { DataSourceState, DataSourceDerivedState } from "components/DataSource/types";
509
+ export function concludeReducer<T>(params: {
510
+ previousState: DataSourceState<T> & DataSourceDerivedState<T>;
511
+ state: DataSourceState<T> & DataSourceDerivedState<T>;
512
+ }): DataSourceState<T> & DataSourceDerivedState<T>;
513
+ }
514
+ declare module "components/DataSource/index" {
515
+ import { DataSourceProps } from "components/DataSource/types";
516
+ import { useDataSource } from "components/DataSource/publicHooks/useDataSource";
517
+ import { GroupRowsState } from "components/DataSource/GroupRowsState";
518
+ function DataSource<T>(props: DataSourceProps<T>): JSX.Element;
519
+ export { useDataSource, DataSource, GroupRowsState };
520
+ export * from "components/DataSource/types";
521
+ }
522
+ declare module "components/DataSource/GroupRowsState" {
523
+ import { DataSourceExpandedAndCollapsedGroupRows } from "components/DataSource/index";
524
+ export class GroupRowsState<KeyType extends any = any> {
525
+ private expandedMap?;
526
+ private collapsedMap?;
527
+ private collapsedAll;
528
+ private expandedAll;
529
+ private initialState;
530
+ constructor(state: DataSourceExpandedAndCollapsedGroupRows<KeyType> | GroupRowsState<KeyType>);
531
+ getState(): DataSourceExpandedAndCollapsedGroupRows<KeyType>;
532
+ destroy(): void;
533
+ private update;
534
+ areAllCollapsed(): boolean;
535
+ areAllExpanded(): boolean;
536
+ collapseAll(): void;
537
+ expandAll(): void;
538
+ isGroupRowExpanded(keys: KeyType[]): boolean | undefined;
539
+ isGroupRowCollapsed(keys: KeyType[]): boolean;
540
+ setGroupRowExpanded(keys: KeyType[], shouldExpand: boolean): void;
541
+ collapseGroupRow(keys: KeyType[]): void;
542
+ expandGroupRow(keys: KeyType[]): void;
543
+ toggleGroupRow(keys: KeyType[]): void;
544
+ }
545
+ }
524
546
  declare module "utils/groupAndPivot/index" {
525
- import { DataSourcePivotBy } from "@infinite-table/infinite-react";
526
547
  import { GroupRowsState } from "components/DataSource/GroupRowsState";
527
- import { InfiniteTablePivotColumn } from "components/InfiniteTable/types/InfiniteTableColumn";
528
- import { InfiniteTableGroupColumnBase, InfiniteTablePropColumnGroups, InfiniteTablePropColumns } from "components/InfiniteTable/types/InfiniteTableProps";
529
- import { InfiniteTablePropPivotTotalColumnPosition } from "components/InfiniteTable/types/InfiniteTableState";
548
+ import { InfiniteTablePivotColumn, InfiniteTablePivotFinalColumn } from "components/InfiniteTable/types/InfiniteTableColumn";
549
+ import { InfiniteTableGroupColumnBase } from "components/InfiniteTable/types/InfiniteTableProps";
530
550
  import { DeepMap } from "utils/DeepMap";
531
551
  export type AggregationReducer<T, AggregationResultType> = {
532
552
  initialValue: AggregationResultType;
@@ -584,7 +604,11 @@ declare module "utils/groupAndPivot/index" {
584
604
  toKey?: (value: any, data: DataType) => GroupKeyType<KeyType>;
585
605
  column?: InfiniteTableGroupColumnBase<DataType>;
586
606
  };
587
- export type PivotBy<DataType, KeyType> = GroupBy<DataType, KeyType>;
607
+ export type PivotBy<DataType, KeyType> = Omit<GroupBy<DataType, KeyType>, 'column'> & {
608
+ column?: InfiniteTablePivotColumn<DataType> | (({ column, }: {
609
+ column: InfiniteTablePivotFinalColumn<DataType, KeyType>;
610
+ }) => Partial<InfiniteTablePivotColumn<DataType>>);
611
+ };
588
612
  type GroupParams<DataType, KeyType> = {
589
613
  groupBy: GroupBy<DataType, KeyType>[];
590
614
  defaultToKey?: (value: any, item: DataType) => GroupKeyType<KeyType>;
@@ -610,11 +634,6 @@ declare module "utils/groupAndPivot/index" {
610
634
  export function enhancedFlatten<DataType, KeyType = any>(param: EnhancedFlattenParam<DataType, KeyType>): {
611
635
  data: InfiniteTableRowInfo<DataType>[];
612
636
  };
613
- export type ComputedColumnsAndGroups<DataType> = {
614
- columns: InfiniteTablePropColumns<DataType, InfiniteTablePivotColumn<DataType>>;
615
- columnGroups: InfiniteTablePropColumnGroups;
616
- };
617
- export function getPivotColumnsAndColumnGroups<DataType, KeyType = any>(deepMap: DeepMap<KeyType, boolean>, pivotBy: DataSourcePivotBy<DataType>[], pivotTotalColumnPosition: InfiniteTablePropPivotTotalColumnPosition): ComputedColumnsAndGroups<DataType>;
618
637
  }
619
638
  declare module "components/InfiniteTable/theme.css" {
620
639
  export const ThemeVars: import("@vanilla-extract/private").MapLeafNodes<{
@@ -865,7 +884,7 @@ declare module "components/InfiniteTable/types/InfiniteTableProps" {
865
884
  groupCount: number;
866
885
  groupRowsBy: DataSourceGroupRowsBy<T>[];
867
886
  };
868
- export type PivotColumnGetterOptions<T> = {
887
+ export type InfiniteTablePivotColumnGetterOptions<T> = {
869
888
  column: InfiniteTablePivotColumn<T>;
870
889
  groupRowsBy: DataSourcePropGroupRowsBy<T>;
871
890
  pivotBy: DataSourcePropPivotBy<T>;
@@ -879,7 +898,7 @@ declare module "components/InfiniteTable/types/InfiniteTableProps" {
879
898
  };
880
899
  export type InfiniteTablePropGroupColumn<T> = InfiniteTableGroupColumnBase<T> | InfiniteTableGroupColumnFunction<T>;
881
900
  export type InfiniteTableGroupColumnFunction<T> = (options: InfiniteTableGroupColumnGetterOptions<T>, toggleGroupRow: (groupKeys: any[]) => void) => InfiniteTableGroupColumnBase<T>;
882
- export type InfiniteTablePropPivotColumn<T> = InfiniteTablePivotColumnBase<T> | ((options: PivotColumnGetterOptions<T>) => InfiniteTablePivotColumnBase<T>);
901
+ export type InfiniteTablePropPivotColumn<T> = InfiniteTablePivotColumnBase<T> | ((options: InfiniteTablePivotColumnGetterOptions<T>) => InfiniteTablePivotColumnBase<T>);
883
902
  export type InfiniteTablePropPivotRowLabelsColumn<T> = InfiniteTablePropPivotColumn<T>;
884
903
  export type InfiniteTablePropComponents = {
885
904
  LoadMask?: React.FC<LoadMaskProps>;
@@ -1177,8 +1196,8 @@ declare module "components/InfiniteTable/state/getInitialState" {
1177
1196
  pivotTotalColumnPosition: 1 | ((value: import("components/InfiniteTable/types/InfiniteTableState").InfiniteTablePropPivotTotalColumnPosition | undefined) => import("components/InfiniteTable/types/InfiniteTableState").InfiniteTablePropPivotTotalColumnPosition);
1178
1197
  pivotColumns: 1 | ((value: import("components/InfiniteTable/types").InfiniteTablePropColumns<T, import("components/InfiniteTable/types/InfiniteTableColumn").InfiniteTablePivotColumn<T>> | undefined) => import("components/InfiniteTable/types").InfiniteTablePropColumns<T, import("components/InfiniteTable/types/InfiniteTableColumn").InfiniteTablePivotColumn<T>> | undefined);
1179
1198
  pivotColumnGroups: 1 | ((value: import("components/InfiniteTable/types").InfiniteTablePropColumnGroups | undefined) => import("components/InfiniteTable/types").InfiniteTablePropColumnGroups | undefined);
1180
- sortable: 1 | ((value: boolean | undefined) => boolean);
1181
1199
  pivotColumn: 1 | ((value: Partial<import("components/InfiniteTable/types/InfiniteTableProps").InfiniteTablePropPivotColumn<T>> | undefined) => Partial<import("components/InfiniteTable/types/InfiniteTableProps").InfiniteTablePropPivotColumn<T>> | undefined);
1200
+ sortable: 1 | ((value: boolean | undefined) => boolean);
1182
1201
  components: 1 | ((value: import("components/InfiniteTable/types").InfiniteTablePropComponents | undefined) => import("components/InfiniteTable/types").InfiniteTablePropComponents | undefined);
1183
1202
  groupColumn: 1 | ((value: Partial<InfiniteTablePropGroupColumn<T>> | undefined) => Partial<InfiniteTablePropGroupColumn<T>> | undefined);
1184
1203
  loadingText: 1 | ((value: import("react").ReactNode) => import("react").ReactNode);
@@ -1510,9 +1529,9 @@ declare module "components/InfiniteTable/hooks/useToggleGroupRow" {
1510
1529
  export function useToggleGroupRow<T>(): ToggleGrouRowFn;
1511
1530
  }
1512
1531
  declare module "components/InfiniteTable/hooks/useColumnsWhen" {
1513
- import { InfiniteTableColumn } from "components/InfiniteTable/index";
1514
- import { DataSourceGroupRowsBy } from "components/DataSource/index";
1515
- import { InfiniteTablePropGroupRenderStrategy, InfiniteTableProps } from "components/InfiniteTable/types/InfiniteTableProps";
1532
+ import type { InfiniteTableColumn } from "components/InfiniteTable/index";
1533
+ import type { DataSourceGroupRowsBy } from "components/DataSource/index";
1534
+ import type { InfiniteTablePropGroupRenderStrategy, InfiniteTableProps } from "components/InfiniteTable/types/InfiniteTableProps";
1516
1535
  export function useColumnsWhen<T>(): void;
1517
1536
  export function getColumnsWhenGrouping<T>(params: {
1518
1537
  columns: Map<string, InfiniteTableColumn<T>>;
package/index.esm.js CHANGED
@@ -2025,48 +2025,51 @@ function getComputedPivotColumnsFromDataSourcePivotColumns(pivotColumns, params)
2025
2025
  return;
2026
2026
  }
2027
2027
  let column = __spreadValues({}, col);
2028
- if (pivotColumn) {
2029
- if (typeof pivotColumn === "function") {
2030
- column = __spreadValues(__spreadValues({}, column), pivotColumn({
2031
- column,
2032
- pivotBy,
2033
- groupRowsBy
2034
- }));
2035
- } else {
2036
- column = __spreadValues(__spreadValues({}, column), pivotColumn);
2037
- }
2038
- }
2039
2028
  const isPivotRowLabelsColumn = !column.pivotColumn && !column.pivotTotalColumn;
2040
- if (pivotRowLabelsColumn && isPivotRowLabelsColumn) {
2041
- if (typeof pivotRowLabelsColumn === "function") {
2042
- column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn({
2043
- column,
2044
- pivotBy,
2045
- groupRowsBy
2046
- }));
2047
- } else {
2048
- column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn);
2029
+ if (!isPivotRowLabelsColumn) {
2030
+ if (pivotColumn) {
2031
+ if (typeof pivotColumn === "function") {
2032
+ column = __spreadValues(__spreadValues({}, column), pivotColumn({
2033
+ column,
2034
+ pivotBy,
2035
+ groupRowsBy
2036
+ }));
2037
+ } else {
2038
+ column = __spreadValues(__spreadValues({}, column), pivotColumn);
2039
+ }
2049
2040
  }
2050
- }
2051
- if (isPivotRowLabelsColumn && !column.render) {
2052
- column.render = (renderOptions) => {
2053
- var _a;
2054
- let { value, rowInfo, column: column2, groupRowsBy: groupRowsBy2 } = renderOptions;
2055
- if (column2.renderValue) {
2056
- value = column2.renderValue(renderOptions);
2041
+ } else {
2042
+ if (pivotRowLabelsColumn) {
2043
+ if (typeof pivotRowLabelsColumn === "function") {
2044
+ column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn({
2045
+ column,
2046
+ pivotBy,
2047
+ groupRowsBy
2048
+ }));
2049
+ } else {
2050
+ column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn);
2057
2051
  }
2058
- const showExpanderIcon = (((_a = rowInfo.groupKeys) == null ? void 0 : _a.length) || 0) < groupRowsBy2.length;
2059
- return /* @__PURE__ */ createElement4("div", {
2060
- className: join(display.flex, alignItems.center, GroupRowExpanderCls)
2061
- }, showExpanderIcon ? /* @__PURE__ */ createElement4(ExpanderIcon, {
2062
- expanded: !rowInfo.collapsed,
2063
- onChange: () => {
2064
- toggleGroupRow(rowInfo.groupKeys);
2052
+ }
2053
+ if (!column.render) {
2054
+ column.render = (renderOptions) => {
2055
+ var _a;
2056
+ let { value, rowInfo, column: column2, groupRowsBy: groupRowsBy2 } = renderOptions;
2057
+ if (column2.renderValue) {
2058
+ value = column2.renderValue(renderOptions);
2065
2059
  }
2066
- }) : null, /* @__PURE__ */ createElement4("div", {
2067
- className: cssEllipsisClassName
2068
- }, value != null ? value : null));
2069
- };
2060
+ const showExpanderIcon = (((_a = rowInfo.groupKeys) == null ? void 0 : _a.length) || 0) < groupRowsBy2.length;
2061
+ return /* @__PURE__ */ createElement4("div", {
2062
+ className: join(display.flex, alignItems.center, GroupRowExpanderCls)
2063
+ }, showExpanderIcon ? /* @__PURE__ */ createElement4(ExpanderIcon, {
2064
+ expanded: !rowInfo.collapsed,
2065
+ onChange: () => {
2066
+ toggleGroupRow(rowInfo.groupKeys);
2067
+ }
2068
+ }) : null, /* @__PURE__ */ createElement4("div", {
2069
+ className: cssEllipsisClassName
2070
+ }, value != null ? value : null));
2071
+ };
2072
+ }
2070
2073
  }
2071
2074
  if (!column.render && column.renderValue) {
2072
2075
  column.render = (renderOptions) => {
@@ -2685,78 +2688,6 @@ function mapPropsToState2(params) {
2685
2688
  };
2686
2689
  }
2687
2690
 
2688
- // src/utils/multisort/sortTypes.ts
2689
- var sortTypes = {
2690
- number: function(first, second) {
2691
- return first - second;
2692
- },
2693
- string: function(first, second) {
2694
- first = `${first}`;
2695
- second = `${second}`;
2696
- return first.localeCompare(second);
2697
- }
2698
- };
2699
- var sortTypes_default = sortTypes;
2700
-
2701
- // src/utils/multisort/index.ts
2702
- var multisort = (sortInfo, array, get) => {
2703
- array.sort(getMultisortFunction(sortInfo, get));
2704
- return array;
2705
- };
2706
- multisort.knownTypes = sortTypes_default;
2707
- var getSingleSortFunction = (info) => {
2708
- if (!info) {
2709
- return;
2710
- }
2711
- const field = info.field;
2712
- var dir = info.dir < 0 ? -1 : info.dir > 0 ? 1 : 0;
2713
- if (!dir) {
2714
- return;
2715
- }
2716
- let fn = info.fn;
2717
- if (!fn && info.type) {
2718
- fn = multisort.knownTypes[info.type];
2719
- if (!fn) {
2720
- console.warn(`Unknown sort type "${info.type}" - please pass one of ${Object.keys(multisort.knownTypes).join(", ")}`);
2721
- }
2722
- }
2723
- if (!fn) {
2724
- fn = sortTypes_default.string;
2725
- }
2726
- return (first, second) => {
2727
- const a = field ? first[field] : first;
2728
- const b = field ? second[field] : second;
2729
- return dir * fn(a, b);
2730
- };
2731
- };
2732
- var getSortFunctions = (sortInfo) => {
2733
- return sortInfo.map(getSingleSortFunction).filter((fn) => fn instanceof Function);
2734
- };
2735
- var getMultisortFunction = (sortInfo, get) => {
2736
- const fns = getSortFunctions(sortInfo);
2737
- return (first, second) => {
2738
- if (get) {
2739
- first = get(first);
2740
- second = get(second);
2741
- }
2742
- let result = 0;
2743
- let i = 0;
2744
- let fn;
2745
- const len = fns.length;
2746
- for (; i < len; i++) {
2747
- fn = fns[i];
2748
- if (!fn) {
2749
- continue;
2750
- }
2751
- result = fn(first, second);
2752
- if (result !== 0) {
2753
- return result;
2754
- }
2755
- }
2756
- return result;
2757
- };
2758
- };
2759
-
2760
2691
  // src/utils/groupAndPivot/index.ts
2761
2692
  function DEFAULT_TO_KEY(value) {
2762
2693
  return value;
@@ -2986,6 +2917,80 @@ function enhancedFlatten(param) {
2986
2917
  data: result
2987
2918
  };
2988
2919
  }
2920
+
2921
+ // src/utils/multisort/sortTypes.ts
2922
+ var sortTypes = {
2923
+ number: function(first, second) {
2924
+ return first - second;
2925
+ },
2926
+ string: function(first, second) {
2927
+ first = `${first}`;
2928
+ second = `${second}`;
2929
+ return first.localeCompare(second);
2930
+ }
2931
+ };
2932
+ var sortTypes_default = sortTypes;
2933
+
2934
+ // src/utils/multisort/index.ts
2935
+ var multisort = (sortInfo, array, get) => {
2936
+ array.sort(getMultisortFunction(sortInfo, get));
2937
+ return array;
2938
+ };
2939
+ multisort.knownTypes = sortTypes_default;
2940
+ var getSingleSortFunction = (info) => {
2941
+ if (!info) {
2942
+ return;
2943
+ }
2944
+ const field = info.field;
2945
+ var dir = info.dir < 0 ? -1 : info.dir > 0 ? 1 : 0;
2946
+ if (!dir) {
2947
+ return;
2948
+ }
2949
+ let fn = info.fn;
2950
+ if (!fn && info.type) {
2951
+ fn = multisort.knownTypes[info.type];
2952
+ if (!fn) {
2953
+ console.warn(`Unknown sort type "${info.type}" - please pass one of ${Object.keys(multisort.knownTypes).join(", ")}`);
2954
+ }
2955
+ }
2956
+ if (!fn) {
2957
+ fn = sortTypes_default.string;
2958
+ }
2959
+ return (first, second) => {
2960
+ const a = field ? first[field] : first;
2961
+ const b = field ? second[field] : second;
2962
+ return dir * fn(a, b);
2963
+ };
2964
+ };
2965
+ var getSortFunctions = (sortInfo) => {
2966
+ return sortInfo.map(getSingleSortFunction).filter((fn) => fn instanceof Function);
2967
+ };
2968
+ var getMultisortFunction = (sortInfo, get) => {
2969
+ const fns = getSortFunctions(sortInfo);
2970
+ return (first, second) => {
2971
+ if (get) {
2972
+ first = get(first);
2973
+ second = get(second);
2974
+ }
2975
+ let result = 0;
2976
+ let i = 0;
2977
+ let fn;
2978
+ const len = fns.length;
2979
+ for (; i < len; i++) {
2980
+ fn = fns[i];
2981
+ if (!fn) {
2982
+ continue;
2983
+ }
2984
+ result = fn(first, second);
2985
+ if (result !== 0) {
2986
+ return result;
2987
+ }
2988
+ }
2989
+ return result;
2990
+ };
2991
+ };
2992
+
2993
+ // src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts
2989
2994
  function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPosition) {
2990
2995
  const pivotLength = pivotBy.length;
2991
2996
  const columns = new Map([
@@ -3010,10 +3015,14 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3010
3015
  if (keys.length === pivotLength) {
3011
3016
  const parentKeys = keys.slice(0, -1);
3012
3017
  let columnGroupId = parentKeys.join("/");
3013
- columns.set(`${keys.join("/")}`, {
3018
+ const pivotByForColumn = pivotBy[keys.length - 1];
3019
+ let computedPivotColumn = __spreadValues({
3014
3020
  pivotBy,
3015
3021
  pivotColumn: true,
3016
3022
  pivotGroupKeys: keys,
3023
+ pivotGroupKeyForColumn: keys[keys.length - 1],
3024
+ pivotIndexForColumn: keys.length - 1,
3025
+ pivotByForColumn,
3017
3026
  sortable: false,
3018
3027
  columnGroup: parentKeys.length ? `${columnGroupId}` : void 0,
3019
3028
  header: keys[keys.length - 1],
@@ -3022,7 +3031,15 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3022
3031
  const value = (_c = (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[0]) != null ? _c : null;
3023
3032
  return value;
3024
3033
  }
3025
- });
3034
+ }, pivotByForColumn.column);
3035
+ if (pivotByForColumn.column) {
3036
+ if (typeof pivotByForColumn.column === "function") {
3037
+ Object.assign(computedPivotColumn, pivotByForColumn.column({ column: computedPivotColumn }));
3038
+ } else {
3039
+ Object.assign(computedPivotColumn, pivotByForColumn.column);
3040
+ }
3041
+ }
3042
+ columns.set(`${keys.join("/")}`, computedPivotColumn);
3026
3043
  } else {
3027
3044
  const colGroupId = keys.join("/");
3028
3045
  const parentKeys = keys.slice(0, -1);
@@ -3031,11 +3048,15 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3031
3048
  header: keys.join(" >> ")
3032
3049
  });
3033
3050
  if (pivotTotalColumnPosition !== false) {
3034
- columns.set(`${keys.join("/")}-total`, {
3051
+ const pivotByForColumn = pivotBy[keys.length - 1];
3052
+ let computedPivotColumn = __spreadValues({
3035
3053
  columnGroup: parentKeys.length ? parentKeys.join("/") : void 0,
3036
3054
  header: `${keys.join("/")} total `,
3037
3055
  pivotTotalColumn: true,
3038
3056
  pivotGroupKeys: keys,
3057
+ pivotGroupKeyForColumn: keys[keys.length - 1],
3058
+ pivotByForColumn,
3059
+ pivotIndexForColumn: keys.length - 1,
3039
3060
  pivotBy,
3040
3061
  sortable: false,
3041
3062
  valueGetter: ({ rowInfo }) => {
@@ -3043,7 +3064,15 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3043
3064
  const value = (_c = (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[0]) != null ? _c : null;
3044
3065
  return value;
3045
3066
  }
3046
- });
3067
+ }, pivotByForColumn.column);
3068
+ if (pivotByForColumn.column) {
3069
+ if (typeof pivotByForColumn.column === "function") {
3070
+ Object.assign(computedPivotColumn, pivotByForColumn.column({ column: computedPivotColumn }));
3071
+ } else {
3072
+ Object.assign(computedPivotColumn, pivotByForColumn.column);
3073
+ }
3074
+ }
3075
+ columns.set(`${keys.join("/")}-total`, computedPivotColumn);
3047
3076
  }
3048
3077
  }
3049
3078
  if (pivotTotalColumnPosition === "start" || pivotTotalColumnPosition === false) {
@@ -6828,7 +6857,7 @@ var useLicense = (licenseKey) => {
6828
6857
  const valid = useMemo11(() => {
6829
6858
  let valid2 = isValidLicense(licenseKey, {
6830
6859
  publishedAt: 1624970570587,
6831
- version: "0.0.4"
6860
+ version: "0.0.5"
6832
6861
  });
6833
6862
  if (!licenseKey && !valid2 && isInsideSandbox) {
6834
6863
  return true;
package/index.js CHANGED
@@ -2011,48 +2011,51 @@ function getComputedPivotColumnsFromDataSourcePivotColumns(pivotColumns, params)
2011
2011
  return;
2012
2012
  }
2013
2013
  let column = __spreadValues({}, col);
2014
- if (pivotColumn) {
2015
- if (typeof pivotColumn === "function") {
2016
- column = __spreadValues(__spreadValues({}, column), pivotColumn({
2017
- column,
2018
- pivotBy,
2019
- groupRowsBy
2020
- }));
2021
- } else {
2022
- column = __spreadValues(__spreadValues({}, column), pivotColumn);
2023
- }
2024
- }
2025
2014
  const isPivotRowLabelsColumn = !column.pivotColumn && !column.pivotTotalColumn;
2026
- if (pivotRowLabelsColumn && isPivotRowLabelsColumn) {
2027
- if (typeof pivotRowLabelsColumn === "function") {
2028
- column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn({
2029
- column,
2030
- pivotBy,
2031
- groupRowsBy
2032
- }));
2033
- } else {
2034
- column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn);
2015
+ if (!isPivotRowLabelsColumn) {
2016
+ if (pivotColumn) {
2017
+ if (typeof pivotColumn === "function") {
2018
+ column = __spreadValues(__spreadValues({}, column), pivotColumn({
2019
+ column,
2020
+ pivotBy,
2021
+ groupRowsBy
2022
+ }));
2023
+ } else {
2024
+ column = __spreadValues(__spreadValues({}, column), pivotColumn);
2025
+ }
2035
2026
  }
2036
- }
2037
- if (isPivotRowLabelsColumn && !column.render) {
2038
- column.render = (renderOptions) => {
2039
- var _a;
2040
- let { value, rowInfo, column: column2, groupRowsBy: groupRowsBy2 } = renderOptions;
2041
- if (column2.renderValue) {
2042
- value = column2.renderValue(renderOptions);
2027
+ } else {
2028
+ if (pivotRowLabelsColumn) {
2029
+ if (typeof pivotRowLabelsColumn === "function") {
2030
+ column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn({
2031
+ column,
2032
+ pivotBy,
2033
+ groupRowsBy
2034
+ }));
2035
+ } else {
2036
+ column = __spreadValues(__spreadValues({}, column), pivotRowLabelsColumn);
2043
2037
  }
2044
- const showExpanderIcon = (((_a = rowInfo.groupKeys) == null ? void 0 : _a.length) || 0) < groupRowsBy2.length;
2045
- return /* @__PURE__ */ React7.createElement("div", {
2046
- className: join(display.flex, alignItems.center, GroupRowExpanderCls)
2047
- }, showExpanderIcon ? /* @__PURE__ */ React7.createElement(ExpanderIcon, {
2048
- expanded: !rowInfo.collapsed,
2049
- onChange: () => {
2050
- toggleGroupRow(rowInfo.groupKeys);
2038
+ }
2039
+ if (!column.render) {
2040
+ column.render = (renderOptions) => {
2041
+ var _a;
2042
+ let { value, rowInfo, column: column2, groupRowsBy: groupRowsBy2 } = renderOptions;
2043
+ if (column2.renderValue) {
2044
+ value = column2.renderValue(renderOptions);
2051
2045
  }
2052
- }) : null, /* @__PURE__ */ React7.createElement("div", {
2053
- className: cssEllipsisClassName
2054
- }, value != null ? value : null));
2055
- };
2046
+ const showExpanderIcon = (((_a = rowInfo.groupKeys) == null ? void 0 : _a.length) || 0) < groupRowsBy2.length;
2047
+ return /* @__PURE__ */ React7.createElement("div", {
2048
+ className: join(display.flex, alignItems.center, GroupRowExpanderCls)
2049
+ }, showExpanderIcon ? /* @__PURE__ */ React7.createElement(ExpanderIcon, {
2050
+ expanded: !rowInfo.collapsed,
2051
+ onChange: () => {
2052
+ toggleGroupRow(rowInfo.groupKeys);
2053
+ }
2054
+ }) : null, /* @__PURE__ */ React7.createElement("div", {
2055
+ className: cssEllipsisClassName
2056
+ }, value != null ? value : null));
2057
+ };
2058
+ }
2056
2059
  }
2057
2060
  if (!column.render && column.renderValue) {
2058
2061
  column.render = (renderOptions) => {
@@ -2666,78 +2669,6 @@ function mapPropsToState2(params) {
2666
2669
  };
2667
2670
  }
2668
2671
 
2669
- // src/utils/multisort/sortTypes.ts
2670
- var sortTypes = {
2671
- number: function(first, second) {
2672
- return first - second;
2673
- },
2674
- string: function(first, second) {
2675
- first = `${first}`;
2676
- second = `${second}`;
2677
- return first.localeCompare(second);
2678
- }
2679
- };
2680
- var sortTypes_default = sortTypes;
2681
-
2682
- // src/utils/multisort/index.ts
2683
- var multisort = (sortInfo, array, get) => {
2684
- array.sort(getMultisortFunction(sortInfo, get));
2685
- return array;
2686
- };
2687
- multisort.knownTypes = sortTypes_default;
2688
- var getSingleSortFunction = (info) => {
2689
- if (!info) {
2690
- return;
2691
- }
2692
- const field = info.field;
2693
- var dir = info.dir < 0 ? -1 : info.dir > 0 ? 1 : 0;
2694
- if (!dir) {
2695
- return;
2696
- }
2697
- let fn = info.fn;
2698
- if (!fn && info.type) {
2699
- fn = multisort.knownTypes[info.type];
2700
- if (!fn) {
2701
- console.warn(`Unknown sort type "${info.type}" - please pass one of ${Object.keys(multisort.knownTypes).join(", ")}`);
2702
- }
2703
- }
2704
- if (!fn) {
2705
- fn = sortTypes_default.string;
2706
- }
2707
- return (first, second) => {
2708
- const a = field ? first[field] : first;
2709
- const b = field ? second[field] : second;
2710
- return dir * fn(a, b);
2711
- };
2712
- };
2713
- var getSortFunctions = (sortInfo) => {
2714
- return sortInfo.map(getSingleSortFunction).filter((fn) => fn instanceof Function);
2715
- };
2716
- var getMultisortFunction = (sortInfo, get) => {
2717
- const fns = getSortFunctions(sortInfo);
2718
- return (first, second) => {
2719
- if (get) {
2720
- first = get(first);
2721
- second = get(second);
2722
- }
2723
- let result = 0;
2724
- let i = 0;
2725
- let fn;
2726
- const len = fns.length;
2727
- for (; i < len; i++) {
2728
- fn = fns[i];
2729
- if (!fn) {
2730
- continue;
2731
- }
2732
- result = fn(first, second);
2733
- if (result !== 0) {
2734
- return result;
2735
- }
2736
- }
2737
- return result;
2738
- };
2739
- };
2740
-
2741
2672
  // src/utils/groupAndPivot/index.ts
2742
2673
  function DEFAULT_TO_KEY(value) {
2743
2674
  return value;
@@ -2967,6 +2898,80 @@ function enhancedFlatten(param) {
2967
2898
  data: result
2968
2899
  };
2969
2900
  }
2901
+
2902
+ // src/utils/multisort/sortTypes.ts
2903
+ var sortTypes = {
2904
+ number: function(first, second) {
2905
+ return first - second;
2906
+ },
2907
+ string: function(first, second) {
2908
+ first = `${first}`;
2909
+ second = `${second}`;
2910
+ return first.localeCompare(second);
2911
+ }
2912
+ };
2913
+ var sortTypes_default = sortTypes;
2914
+
2915
+ // src/utils/multisort/index.ts
2916
+ var multisort = (sortInfo, array, get) => {
2917
+ array.sort(getMultisortFunction(sortInfo, get));
2918
+ return array;
2919
+ };
2920
+ multisort.knownTypes = sortTypes_default;
2921
+ var getSingleSortFunction = (info) => {
2922
+ if (!info) {
2923
+ return;
2924
+ }
2925
+ const field = info.field;
2926
+ var dir = info.dir < 0 ? -1 : info.dir > 0 ? 1 : 0;
2927
+ if (!dir) {
2928
+ return;
2929
+ }
2930
+ let fn = info.fn;
2931
+ if (!fn && info.type) {
2932
+ fn = multisort.knownTypes[info.type];
2933
+ if (!fn) {
2934
+ console.warn(`Unknown sort type "${info.type}" - please pass one of ${Object.keys(multisort.knownTypes).join(", ")}`);
2935
+ }
2936
+ }
2937
+ if (!fn) {
2938
+ fn = sortTypes_default.string;
2939
+ }
2940
+ return (first, second) => {
2941
+ const a = field ? first[field] : first;
2942
+ const b = field ? second[field] : second;
2943
+ return dir * fn(a, b);
2944
+ };
2945
+ };
2946
+ var getSortFunctions = (sortInfo) => {
2947
+ return sortInfo.map(getSingleSortFunction).filter((fn) => fn instanceof Function);
2948
+ };
2949
+ var getMultisortFunction = (sortInfo, get) => {
2950
+ const fns = getSortFunctions(sortInfo);
2951
+ return (first, second) => {
2952
+ if (get) {
2953
+ first = get(first);
2954
+ second = get(second);
2955
+ }
2956
+ let result = 0;
2957
+ let i = 0;
2958
+ let fn;
2959
+ const len = fns.length;
2960
+ for (; i < len; i++) {
2961
+ fn = fns[i];
2962
+ if (!fn) {
2963
+ continue;
2964
+ }
2965
+ result = fn(first, second);
2966
+ if (result !== 0) {
2967
+ return result;
2968
+ }
2969
+ }
2970
+ return result;
2971
+ };
2972
+ };
2973
+
2974
+ // src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts
2970
2975
  function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPosition) {
2971
2976
  const pivotLength = pivotBy.length;
2972
2977
  const columns = new Map([
@@ -2991,10 +2996,14 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
2991
2996
  if (keys.length === pivotLength) {
2992
2997
  const parentKeys = keys.slice(0, -1);
2993
2998
  let columnGroupId = parentKeys.join("/");
2994
- columns.set(`${keys.join("/")}`, {
2999
+ const pivotByForColumn = pivotBy[keys.length - 1];
3000
+ let computedPivotColumn = __spreadValues({
2995
3001
  pivotBy,
2996
3002
  pivotColumn: true,
2997
3003
  pivotGroupKeys: keys,
3004
+ pivotGroupKeyForColumn: keys[keys.length - 1],
3005
+ pivotIndexForColumn: keys.length - 1,
3006
+ pivotByForColumn,
2998
3007
  sortable: false,
2999
3008
  columnGroup: parentKeys.length ? `${columnGroupId}` : void 0,
3000
3009
  header: keys[keys.length - 1],
@@ -3003,7 +3012,15 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3003
3012
  const value = (_c = (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[0]) != null ? _c : null;
3004
3013
  return value;
3005
3014
  }
3006
- });
3015
+ }, pivotByForColumn.column);
3016
+ if (pivotByForColumn.column) {
3017
+ if (typeof pivotByForColumn.column === "function") {
3018
+ Object.assign(computedPivotColumn, pivotByForColumn.column({ column: computedPivotColumn }));
3019
+ } else {
3020
+ Object.assign(computedPivotColumn, pivotByForColumn.column);
3021
+ }
3022
+ }
3023
+ columns.set(`${keys.join("/")}`, computedPivotColumn);
3007
3024
  } else {
3008
3025
  const colGroupId = keys.join("/");
3009
3026
  const parentKeys = keys.slice(0, -1);
@@ -3012,11 +3029,15 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3012
3029
  header: keys.join(" >> ")
3013
3030
  });
3014
3031
  if (pivotTotalColumnPosition !== false) {
3015
- columns.set(`${keys.join("/")}-total`, {
3032
+ const pivotByForColumn = pivotBy[keys.length - 1];
3033
+ let computedPivotColumn = __spreadValues({
3016
3034
  columnGroup: parentKeys.length ? parentKeys.join("/") : void 0,
3017
3035
  header: `${keys.join("/")} total `,
3018
3036
  pivotTotalColumn: true,
3019
3037
  pivotGroupKeys: keys,
3038
+ pivotGroupKeyForColumn: keys[keys.length - 1],
3039
+ pivotByForColumn,
3040
+ pivotIndexForColumn: keys.length - 1,
3020
3041
  pivotBy,
3021
3042
  sortable: false,
3022
3043
  valueGetter: ({ rowInfo }) => {
@@ -3024,7 +3045,15 @@ function getPivotColumnsAndColumnGroups(deepMap, pivotBy, pivotTotalColumnPositi
3024
3045
  const value = (_c = (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[0]) != null ? _c : null;
3025
3046
  return value;
3026
3047
  }
3027
- });
3048
+ }, pivotByForColumn.column);
3049
+ if (pivotByForColumn.column) {
3050
+ if (typeof pivotByForColumn.column === "function") {
3051
+ Object.assign(computedPivotColumn, pivotByForColumn.column({ column: computedPivotColumn }));
3052
+ } else {
3053
+ Object.assign(computedPivotColumn, pivotByForColumn.column);
3054
+ }
3055
+ }
3056
+ columns.set(`${keys.join("/")}-total`, computedPivotColumn);
3028
3057
  }
3029
3058
  }
3030
3059
  if (pivotTotalColumnPosition === "start" || pivotTotalColumnPosition === false) {
@@ -6730,7 +6759,7 @@ var useLicense = (licenseKey) => {
6730
6759
  const valid = (0, import_react42.useMemo)(() => {
6731
6760
  let valid2 = isValidLicense(licenseKey, {
6732
6761
  publishedAt: 1624970570587,
6733
- version: "0.0.4"
6762
+ version: "0.0.5"
6734
6763
  });
6735
6764
  if (!licenseKey && !valid2 && isInsideSandbox) {
6736
6765
  return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infinite-table/infinite-react",
3
3
  "description": "Infinite Table for React",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
7
7
  "typings": "index.d.ts",
@@ -15,5 +15,5 @@
15
15
  },
16
16
  "license": "Commercial & Open Source",
17
17
  "//": "will be updated at build time",
18
- "publishedAt": 1638307822158
18
+ "publishedAt": 1638368677113
19
19
  }