@infinite-table/infinite-react 4.2.1-canary.0 → 4.3.0

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 (6) hide show
  1. package/index.d.ts +2249 -205
  2. package/index.dev.js +2145 -1846
  3. package/index.dev.mjs +2170 -1870
  4. package/index.js +2145 -1846
  5. package/index.mjs +2170 -1870
  6. package/package.json +2 -2
package/index.js CHANGED
@@ -127,6 +127,7 @@ var require_binary_search = __commonJS({
127
127
  var src_exports = {};
128
128
  __export(src_exports, {
129
129
  CellSelectionState: () => CellSelectionState,
130
+ DataClient: () => DataClient,
130
131
  DataSource: () => DataSource,
131
132
  DataSourceActionType: () => DataSourceActionType,
132
133
  DeepMap: () => DeepMap,
@@ -147,13 +148,15 @@ __export(src_exports, {
147
148
  eventMatchesKeyboardShortcut: () => eventMatchesKeyboardShortcut,
148
149
  filterTypes: () => defaultFilterTypes2,
149
150
  flatten: () => flatten,
150
- getComponentStateRoot: () => getComponentStateRoot,
151
+ getComponentStateRoot: () => buildManagedComponent,
151
152
  group: () => group,
152
153
  interceptMap: () => interceptMap,
153
154
  keyboardShortcuts: () => keyboardShortcuts,
154
155
  multisort: () => multisort,
155
- useComponentState: () => useComponentState,
156
- useDataSource: () => useDataSource,
156
+ queryKeyToCacheKey: () => queryKeyToCacheKey,
157
+ useComponentState: () => useManagedComponentState,
158
+ useDataSourceInternal: () => useDataSourceInternal,
159
+ useDataSourceState: () => useDataSourceState,
157
160
  useEffectWithChanges: () => useEffectWithChanges,
158
161
  useEffectWithObject: () => useEffectWithObject,
159
162
  useGridScroll: () => useGridScroll,
@@ -161,6 +164,7 @@ __export(src_exports, {
161
164
  useInfiniteColumnEditor: () => useInfiniteColumnEditor,
162
165
  useInfiniteColumnFilterEditor: () => useInfiniteColumnFilterEditor,
163
166
  useInfiniteHeaderCell: () => useInfiniteHeaderCell,
167
+ useManagedDataSource: () => useManagedDataSource,
164
168
  useMasterRowInfo: () => useMasterRowInfo,
165
169
  useOverlay: () => useOverlay,
166
170
  useOverlayPortal: () => useOverlayPortal,
@@ -184,7 +188,7 @@ function debounce(fn, { wait }) {
184
188
  }
185
189
 
186
190
  // src/components/InfiniteTable/index.tsx
187
- var React67 = __toESM(require("react"));
191
+ var React68 = __toESM(require("react"));
188
192
 
189
193
  // src/utils/join.ts
190
194
  var join = (...args) => args.filter((x) => !!`${x}`).join(" ");
@@ -730,10 +734,13 @@ var COLORS = [
730
734
  ];
731
735
  var COLOR_SYMBOL = Symbol("color");
732
736
  var USED_COLORS_MAP = /* @__PURE__ */ new WeakMap();
733
- USED_COLORS_MAP.set(
734
- COLORS,
735
- COLORS.map((_) => 0)
736
- );
737
+ function initUsedColors(colors = COLORS) {
738
+ USED_COLORS_MAP.set(
739
+ colors,
740
+ colors.map((_) => 0)
741
+ );
742
+ }
743
+ initUsedColors();
737
744
  var getNextColor = (colors = COLORS) => {
738
745
  var _a, _b;
739
746
  let usedColors = [];
@@ -767,8 +774,13 @@ function isChannelTargeted(channel, permissionToken) {
767
774
  partsMap.set(parts, true);
768
775
  const tokenParts = permissionToken.split(CHANNEL_SEPARATOR);
769
776
  const hasWildcard = new Set(tokenParts).has(CHANNEL_WILDCARD);
770
- const storagePartsWithoutWildcard = hasWildcard ? tokenParts.slice(0, tokenParts.indexOf(CHANNEL_WILDCARD)) : tokenParts;
777
+ const indexOfToken = tokenParts.indexOf(CHANNEL_WILDCARD);
778
+ const storagePartsWithoutWildcard = hasWildcard ? tokenParts.slice(0, indexOfToken) : tokenParts;
771
779
  if (partsMap.getKeysStartingWith(storagePartsWithoutWildcard, hasWildcard).length > 0) {
780
+ const remainingParts = tokenParts.slice(indexOfToken + 1);
781
+ if (remainingParts.length) {
782
+ return channel.endsWith(remainingParts.join(CHANNEL_SEPARATOR));
783
+ }
772
784
  return true;
773
785
  }
774
786
  return void 0;
@@ -851,7 +863,7 @@ function debugPackage(channelName) {
851
863
  let lastMessageTimestamp = 0;
852
864
  const isEnabled = () => enabled != null ? enabled : isLoggingEnabled(channel, storageKeyValue);
853
865
  const color = getNextColor(debug.colors);
854
- const logger2 = Object.defineProperties(
866
+ const logger3 = Object.defineProperties(
855
867
  (...args) => {
856
868
  if (isLoggingEnabled(channel, storageKeyValue)) {
857
869
  const now = Date.now();
@@ -928,8 +940,8 @@ function debugPackage(channelName) {
928
940
  }
929
941
  }
930
942
  );
931
- loggers.set(channelParts, logger2);
932
- return logger2;
943
+ loggers.set(channelParts, logger3);
944
+ return logger3;
933
945
  }
934
946
  return debugFactory(channelName);
935
947
  }
@@ -945,6 +957,12 @@ Object.defineProperty(debugPackage, "enable", {
945
957
  var debug = debugPackage;
946
958
  debug.colors = COLORS;
947
959
  debug.logFn = defaultLogger;
960
+ debug.destroyAll = () => {
961
+ initUsedColors();
962
+ initUsedColors(debug.colors);
963
+ loggers.clear();
964
+ enabledChannelsCache.clear();
965
+ };
948
966
 
949
967
  // src/utils/debug.ts
950
968
  var debugTable = debug(`InfiniteTable`);
@@ -1111,7 +1129,7 @@ var CSSNumericVariableWatch = (props) => {
1111
1129
  );
1112
1130
  };
1113
1131
 
1114
- // src/components/DataSource/publicHooks/useDataSource.ts
1132
+ // src/components/DataSource/publicHooks/useDataSourceState.ts
1115
1133
  var React5 = __toESM(require("react"));
1116
1134
 
1117
1135
  // src/components/DataSource/DataSourceContext.ts
@@ -1141,8 +1159,8 @@ function getDataSourceMasterDetailContext() {
1141
1159
  return DSMasterDetailContext = React4.createContext(void 0);
1142
1160
  }
1143
1161
 
1144
- // src/components/DataSource/publicHooks/useDataSource.ts
1145
- function useDataSource() {
1162
+ // src/components/DataSource/publicHooks/useDataSourceState.ts
1163
+ function useDataSourceState() {
1146
1164
  const DataSourceContext = getDataSourceContext();
1147
1165
  const contextValue = React5.useContext(DataSourceContext);
1148
1166
  return contextValue.componentState;
@@ -4573,8 +4591,8 @@ function forwardProps(propsToForward, props, setupState) {
4573
4591
  }
4574
4592
  return mappedState;
4575
4593
  }
4576
- function getComponentStateRoot(config) {
4577
- return React14.memo(function ComponentStateRoot(props) {
4594
+ function buildManagedComponent(config) {
4595
+ function useManagedComponent(props) {
4578
4596
  var _a, _b;
4579
4597
  const [initialSetupState] = (0, import_react14.useState)(() => {
4580
4598
  return config.initSetupState ? config.initSetupState(props) : {};
@@ -4752,8 +4770,8 @@ function getComponentStateRoot(config) {
4752
4770
  }
4753
4771
  });
4754
4772
  if (updatedPropsToStateCount > 0 || newMappedStateCount > 0) {
4755
- const logger2 = config.debugName ? dbg(`${config.debugName}:rerender`) : dbg("rerender");
4756
- logger2(
4773
+ const logger3 = config.debugName ? dbg(`${config.debugName}:rerender`) : dbg("rerender");
4774
+ logger3(
4757
4775
  "Triggered by new values for the following props",
4758
4776
  ...[
4759
4777
  ...Object.keys(newMappedState != null ? newMappedState : {}),
@@ -4790,10 +4808,18 @@ function getComponentStateRoot(config) {
4790
4808
  (_a2 = config.cleanup) == null ? void 0 : _a2.call(config, getComponentState());
4791
4809
  };
4792
4810
  });
4793
- return /* @__PURE__ */ React14.createElement(Context.Provider, { value: contextValue }, props.children);
4811
+ return { contextValue, ContextComponent: Context };
4812
+ }
4813
+ const ManagedComponentContextProvider = React14.memo(function CSR(props) {
4814
+ const { contextValue, ContextComponent } = useManagedComponent(props);
4815
+ return /* @__PURE__ */ React14.createElement(ContextComponent.Provider, { value: contextValue }, props.children);
4794
4816
  });
4817
+ return {
4818
+ ManagedComponentContextProvider,
4819
+ useManagedComponent
4820
+ };
4795
4821
  }
4796
- function useComponentState() {
4822
+ function useManagedComponentState() {
4797
4823
  const Context = getComponentStateContext();
4798
4824
  return React14.useContext(Context);
4799
4825
  }
@@ -7765,7 +7791,7 @@ function forwardProps2() {
7765
7791
  domProps: 1
7766
7792
  };
7767
7793
  }
7768
- var InfiniteCheckBoxRoot = getComponentStateRoot({
7794
+ var { ManagedComponentContextProvider: InfiniteCheckBoxRoot } = buildManagedComponent({
7769
7795
  // @ts-ignore
7770
7796
  forwardProps: forwardProps2,
7771
7797
  // @ts-ignore
@@ -7784,7 +7810,7 @@ var InfiniteCheckBoxRoot = getComponentStateRoot({
7784
7810
  debugName: "InfiniteCheckBox"
7785
7811
  });
7786
7812
  function InfiniteCheckBoxComponent() {
7787
- const { componentState, componentActions } = useComponentState();
7813
+ const { componentState, componentActions } = useManagedComponentState();
7788
7814
  const { checked, domProps, disabled } = componentState;
7789
7815
  const inputRef = (0, import_react23.useRef)(null);
7790
7816
  (0, import_react23.useEffect)(() => {
@@ -9252,7 +9278,7 @@ function InfiniteTableHeaderCell(props) {
9252
9278
  getState: getDataSourceState,
9253
9279
  componentState: { filterDelay, filterTypes }
9254
9280
  } = useDataSourceContextValue();
9255
- const { allRowsSelected, someRowsSelected, selectionMode } = useDataSource();
9281
+ const { allRowsSelected, someRowsSelected, selectionMode } = useDataSourceState();
9256
9282
  const dragging = columnReorderDragColumnId === column.id;
9257
9283
  const { onResize, height, width, headerOptions, columnsMap } = props;
9258
9284
  const sortInfo = column.computedSortInfo;
@@ -10969,8 +10995,7 @@ function enhancedFlatten(param) {
10969
10995
  }
10970
10996
 
10971
10997
  // src/components/DataSource/index.tsx
10972
- var React50 = __toESM(require("react"));
10973
- var import_react36 = require("react");
10998
+ var React51 = __toESM(require("react"));
10974
10999
 
10975
11000
  // src/utils/multisort/sortTypes.ts
10976
11001
  var numberComparator = function(first, second) {
@@ -11076,558 +11101,154 @@ var getMultisortFunction = (sortInfo, get) => {
11076
11101
  };
11077
11102
  };
11078
11103
 
11079
- // src/components/DataSource/DataSourceCache.ts
11080
- var DataSourceCache = class {
11081
- constructor() {
11082
- this.affectedFields = /* @__PURE__ */ new Set();
11083
- this.allFieldsAffected = false;
11084
- this.primaryKeyToData = /* @__PURE__ */ new Map();
11085
- this.getAffectedFields = () => {
11086
- if (this.allFieldsAffected) {
11087
- return true;
11088
- }
11089
- return this.affectedFields;
11090
- };
11091
- this.delete = (primaryKey, originalData, metadata) => {
11092
- this.allFieldsAffected = true;
11093
- const pk = primaryKey;
11094
- const value = this.primaryKeyToData.get(pk) || [];
11095
- value.push({
11096
- type: "delete",
11097
- primaryKey,
11098
- originalData,
11099
- metadata
11100
- });
11101
- this.primaryKeyToData.set(pk, value);
11102
- };
11103
- this.insert = (primaryKey, data, position2, metadata) => {
11104
- const pk = primaryKey;
11105
- const value = this.primaryKeyToData.get(pk) || [];
11106
- this.allFieldsAffected = true;
11107
- value.push({
11108
- type: "insert",
11109
- primaryKey,
11110
- data,
11111
- position: position2,
11112
- originalData: null,
11113
- metadata
11114
- });
11115
- this.primaryKeyToData.set(pk, value);
11116
- };
11117
- this.update = (primaryKey, data, originalData, metadata) => {
11118
- if (!this.allFieldsAffected) {
11119
- const keys = Object.keys(data);
11120
- keys.forEach((key) => this.affectedFields.add(key));
11121
- }
11122
- const pk = primaryKey;
11123
- const value = this.primaryKeyToData.get(pk) || [];
11124
- value.push({
11125
- type: "update",
11126
- primaryKey,
11127
- data,
11128
- originalData,
11129
- metadata
11130
- });
11131
- this.primaryKeyToData.set(primaryKey, value);
11132
- };
11133
- this.clear = () => {
11134
- this.allFieldsAffected = false;
11135
- this.affectedFields.clear();
11136
- this.primaryKeyToData.clear();
11137
- };
11138
- this.isEmpty = () => {
11139
- return this.primaryKeyToData.size === 0;
11140
- };
11141
- this.removeInfo = (primaryKey) => {
11142
- this.primaryKeyToData.delete(primaryKey);
11143
- };
11144
- this.getMutationsForPrimaryKey = (primaryKey) => {
11145
- const data = this.primaryKeyToData.get(primaryKey);
11146
- return data;
11147
- };
11148
- this.getMutations = () => {
11149
- return new Map(this.primaryKeyToData);
11150
- };
11104
+ // src/components/DataSource/BooleanDeepCollectionState.ts
11105
+ var BooleanDeepCollectionState = class {
11106
+ constructor(state) {
11107
+ const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? (
11108
+ //@ts-ignore
11109
+ state.getState()
11110
+ ) : state;
11111
+ const positiveItems = this.getPositiveFromState(stateObject);
11112
+ const negativeItems = this.getNegativeFromState(stateObject);
11113
+ this.update({
11114
+ negativeItems,
11115
+ positiveItems
11116
+ });
11151
11117
  }
11152
- static clone(cache, { light = false } = {}) {
11153
- const clone = new DataSourceCache();
11154
- clone.allFieldsAffected = cache.allFieldsAffected;
11155
- clone.affectedFields = new Set(cache.affectedFields);
11156
- clone.primaryKeyToData = light ? cache.primaryKeyToData : new Map(
11157
- cache.primaryKeyToData
11158
- );
11159
- return clone;
11118
+ getInitialState() {
11119
+ return this.initialState;
11160
11120
  }
11161
- };
11162
-
11163
- // src/components/DataSource/dataSourceGetters.ts
11164
- function getRowInfoAt(rowIndex, getState) {
11165
- return getState().dataArray[rowIndex];
11166
- }
11167
- function getRowInfoArray(getState) {
11168
- return getState().dataArray;
11169
- }
11170
-
11171
- // src/components/DataSource/getDataSourceApi.ts
11172
- function getDataSourceApi(param) {
11173
- return new DataSourceApiImpl(param);
11174
- }
11175
- var DataSourceApiImpl = class {
11176
- constructor(param) {
11177
- this.pendingOperations = [];
11178
- this.pendingPromise = null;
11179
- this.resolvePendingPromise = null;
11180
- this.toPrimaryKey = (data) => {
11181
- return this.getState().toPrimaryKey(data);
11182
- };
11183
- this.getRowInfoArray = () => {
11184
- return getRowInfoArray(this.getState);
11185
- };
11186
- this.getRowInfoByIndex = (index) => {
11187
- var _a;
11188
- return (_a = getRowInfoAt(index, this.getState)) != null ? _a : null;
11189
- };
11190
- this.getRowInfoByPrimaryKey = (id) => {
11191
- const index = this.getIndexByPrimaryKey(id);
11192
- return this.getRowInfoByIndex(index);
11193
- };
11194
- this.getIndexByPrimaryKey = (id) => {
11195
- var _a;
11196
- const map2 = this.getState().idToIndexMap;
11197
- return (_a = map2.get(id)) != null ? _a : -1;
11198
- };
11199
- this.getPrimaryKeyByIndex = (index) => {
11200
- const rowInfo = this.getRowInfoByIndex(index);
11201
- return rowInfo ? rowInfo.id : void 0;
11202
- };
11203
- this.getOriginalDataArray = () => {
11204
- return this.getState().originalDataArray;
11205
- };
11206
- this.getDataByPrimaryKey = (id) => {
11207
- var _a;
11208
- const { indexer } = this.getState();
11209
- return (_a = indexer.getDataForPrimaryKey(id)) != null ? _a : null;
11210
- };
11211
- this.updateData = (data, options) => {
11212
- return this.updateDataArray([data], options);
11213
- };
11214
- this.updateDataArray = (data, options) => {
11215
- const result = this.batchOperation({
11216
- type: "update",
11217
- array: data,
11218
- primaryKeys: data.map((d) => {
11219
- return this.toPrimaryKey(d);
11220
- }),
11221
- metadata: options == null ? void 0 : options.metadata
11222
- });
11223
- if (options == null ? void 0 : options.flush) {
11224
- this.commit();
11225
- }
11226
- return result;
11227
- };
11228
- this.removeDataByPrimaryKey = (id, options) => {
11229
- const result = this.batchOperation({
11230
- type: "delete",
11231
- primaryKeys: [id],
11232
- metadata: options == null ? void 0 : options.metadata
11233
- });
11234
- if (options == null ? void 0 : options.flush) {
11235
- this.commit();
11121
+ // protected getState(): BooleanDeepCollectionStateObject<KeyType> {
11122
+ // return {
11123
+ // positiveItems: this.allPositive
11124
+ // ? true
11125
+ // : this.positiveMap?.topDownKeys() ?? [],
11126
+ // negativeItems: this.allNegative
11127
+ // ? true
11128
+ // : this.negativeMap?.topDownKeys() ?? [],
11129
+ // };
11130
+ // }
11131
+ destroy() {
11132
+ var _a, _b;
11133
+ (_a = this.positiveMap) == null ? void 0 : _a.clear();
11134
+ (_b = this.negativeMap) == null ? void 0 : _b.clear();
11135
+ delete this.positiveMap;
11136
+ delete this.negativeMap;
11137
+ }
11138
+ update(state) {
11139
+ const { positiveItems, negativeItems } = state;
11140
+ this.allNegative = negativeItems === true;
11141
+ this.allPositive = positiveItems === true;
11142
+ if (this.allNegative && this.allPositive) {
11143
+ throw `Cannot have both negativeItems and positiveItems be true!`;
11144
+ }
11145
+ if (negativeItems !== true) {
11146
+ if (this.negativeMap) {
11147
+ this.negativeMap.clear();
11148
+ this.negativeMap.fill(negativeItems.map((keys) => [keys, true]));
11149
+ } else {
11150
+ this.negativeMap = new DeepMap(
11151
+ negativeItems.map((keys) => [keys, true])
11152
+ );
11236
11153
  }
11237
- return result;
11238
- };
11239
- this.removeData = (data, options) => {
11240
- const result = this.batchOperation({
11241
- type: "delete",
11242
- primaryKeys: [this.toPrimaryKey(data)],
11243
- metadata: options == null ? void 0 : options.metadata
11244
- });
11245
- if (options == null ? void 0 : options.flush) {
11246
- this.commit();
11154
+ if (this.positiveMap) {
11155
+ this.positiveMap.clear();
11247
11156
  }
11248
- return result;
11249
- };
11250
- this.removeDataArrayByPrimaryKeys = (ids, options) => {
11251
- const result = this.batchOperation({
11252
- type: "delete",
11253
- primaryKeys: ids,
11254
- metadata: options == null ? void 0 : options.metadata
11255
- });
11256
- if (options == null ? void 0 : options.flush) {
11257
- this.commit();
11157
+ }
11158
+ if (positiveItems !== true) {
11159
+ if (this.positiveMap) {
11160
+ this.positiveMap.clear();
11161
+ this.positiveMap.fill(positiveItems.map((keys) => [keys, true]));
11162
+ } else {
11163
+ this.positiveMap = new DeepMap(
11164
+ positiveItems.map((keys) => [keys, true])
11165
+ );
11258
11166
  }
11259
- return result;
11260
- };
11261
- this.removeDataArray = (data, options) => {
11262
- const result = this.batchOperation({
11263
- type: "delete",
11264
- primaryKeys: data.map(this.toPrimaryKey),
11265
- metadata: options == null ? void 0 : options.metadata
11266
- });
11267
- if (options == null ? void 0 : options.flush) {
11268
- this.commit();
11167
+ if (this.negativeMap) {
11168
+ this.negativeMap.clear();
11269
11169
  }
11270
- return result;
11271
- };
11272
- this.addData = (data, options) => {
11273
- return this.addDataArray([data], options);
11274
- };
11275
- this.addDataArray = (data, options) => {
11276
- return this.insertDataArray(data, __spreadProps(__spreadValues({}, options), {
11277
- position: "end"
11278
- }));
11279
- };
11280
- this.insertData = (data, options) => {
11281
- return this.insertDataArray([data], options);
11282
- };
11283
- this.insertDataArray = (data, options) => {
11284
- let position2 = "before";
11285
- let primaryKey = void 0;
11286
- if (options.position === "before" || options.position === "after") {
11287
- position2 = options.position;
11288
- primaryKey = options.primaryKey;
11289
- } else {
11290
- const arr = this.getOriginalDataArray();
11291
- if (options.position === "start") {
11292
- position2 = "before";
11293
- primaryKey = this.toPrimaryKey(arr[0]);
11294
- } else {
11295
- position2 = "after";
11296
- primaryKey = this.toPrimaryKey(arr[arr.length - 1]);
11297
- }
11298
- }
11299
- const result = this.batchOperation({
11300
- type: "insert",
11301
- array: data,
11302
- position: position2,
11303
- metadata: options == null ? void 0 : options.metadata,
11304
- primaryKey
11305
- });
11306
- if (options == null ? void 0 : options.flush) {
11307
- this.commit();
11308
- }
11309
- return result;
11310
- };
11311
- this.setSortInfo = (sortInfo) => {
11312
- const multiSort = this.getState().multiSort;
11313
- if (Array.isArray(sortInfo)) {
11314
- this.actions.sortInfo = sortInfo.length ? multiSort ? sortInfo : sortInfo[0] : null;
11315
- return;
11316
- }
11317
- this.actions.sortInfo = sortInfo;
11318
- return;
11319
- };
11320
- this.getState = param.getState;
11321
- this.actions = param.actions;
11322
- }
11323
- batchOperation(operation) {
11324
- if (!this.pendingPromise) {
11325
- this.pendingPromise = new Promise((resolve) => {
11326
- this.resolvePendingPromise = resolve;
11327
- });
11328
- raf(() => {
11329
- this.commit();
11330
- });
11331
11170
  }
11332
- this.pendingOperations.push(operation);
11333
- return this.pendingPromise;
11334
11171
  }
11335
- batchOperations(operations) {
11336
- this.pendingOperations.push(...operations);
11172
+ areAllNegative() {
11173
+ return this.allNegative && (this.positiveMap ? this.positiveMap.size === 0 : true);
11337
11174
  }
11338
- commitOperations(operations) {
11339
- if (!operations.length) {
11340
- return;
11341
- }
11342
- const currentCache = this.getState().cache;
11343
- let cache = currentCache ? DataSourceCache.clone(currentCache, { light: true }) : new DataSourceCache();
11344
- operations.forEach((operation) => {
11345
- switch (operation.type) {
11346
- case "update":
11347
- operation.array.forEach((data, index) => {
11348
- const key = operation.primaryKeys[index];
11349
- const rowInfo = this.getRowInfoByPrimaryKey(key);
11350
- if (rowInfo && !rowInfo.isGroupRow) {
11351
- cache.update(
11352
- operation.primaryKeys[index],
11353
- data,
11354
- rowInfo.data,
11355
- operation.metadata
11356
- );
11357
- }
11358
- });
11359
- break;
11360
- case "delete":
11361
- operation.primaryKeys.forEach((key) => {
11362
- const rowInfo = this.getRowInfoByPrimaryKey(key);
11363
- if (rowInfo && !rowInfo.isGroupRow) {
11364
- cache.delete(key, rowInfo.data, operation.metadata);
11365
- }
11366
- });
11367
- break;
11368
- case "insert":
11369
- let pk = operation.primaryKey;
11370
- let position2 = operation.position;
11371
- operation.array.forEach((data) => {
11372
- cache.insert(pk, data, position2, operation.metadata);
11373
- pk = this.toPrimaryKey(data);
11374
- position2 = "after";
11375
- });
11376
- break;
11377
- }
11378
- });
11379
- this.actions.cache = cache;
11175
+ areAllPositive() {
11176
+ return this.allPositive && (this.negativeMap ? this.negativeMap.size === 0 : true);
11380
11177
  }
11381
- commit() {
11382
- this.commitOperations(this.pendingOperations);
11383
- this.pendingOperations.length = 0;
11384
- if (this.pendingPromise && this.resolvePendingPromise) {
11385
- const resolve = this.resolvePendingPromise;
11386
- requestAnimationFrame(() => {
11387
- resolve(true);
11388
- });
11389
- this.pendingPromise = null;
11390
- this.resolvePendingPromise = null;
11391
- }
11178
+ makeAllNegative() {
11179
+ this.update({
11180
+ negativeItems: true,
11181
+ positiveItems: []
11182
+ });
11392
11183
  }
11393
- };
11394
- function getCacheAffectedParts(state) {
11395
- const cache = state.cache;
11396
- if (!cache) {
11397
- return {
11398
- sortInfo: false,
11399
- groupBy: false,
11400
- filterValue: false,
11401
- aggregationReducers: false
11402
- };
11184
+ makeAllPositive() {
11185
+ this.update({
11186
+ positiveItems: true,
11187
+ negativeItems: []
11188
+ });
11403
11189
  }
11404
- let sortInfoAffected = false;
11405
- let groupByAffected = false;
11406
- let filterAffected = false;
11407
- let aggregationsAffected = false;
11408
- const keys = cache.getAffectedFields();
11409
- const { sortInfo, groupBy, filterValue, aggregationReducers } = state;
11410
- if (sortInfo && sortInfo.length) {
11411
- if (keys === true) {
11412
- sortInfoAffected = true;
11413
- } else {
11414
- for (const sort of sortInfo) {
11415
- let field = sort.field;
11416
- if (field) {
11417
- field = Array.isArray(field) ? field : [field];
11418
- sortInfoAffected = field.reduce((result, f) => {
11419
- return result || typeof f !== "function" ? keys.has(f) : false;
11420
- }, false);
11421
- if (sortInfoAffected) {
11422
- break;
11423
- }
11424
- }
11190
+ isItemPositive(keys) {
11191
+ var _a, _b;
11192
+ if (this.allPositive === true) {
11193
+ if (this.allNegative === true) {
11194
+ throw 'Cannot have both positiveItems and negativeItems be "true"';
11425
11195
  }
11196
+ return !((_a = this.negativeMap) == null ? void 0 : _a.has(keys));
11426
11197
  }
11198
+ return (_b = this.positiveMap) == null ? void 0 : _b.has(keys);
11427
11199
  }
11428
- if (groupBy && groupBy.length) {
11429
- if (keys === true) {
11430
- groupByAffected = true;
11431
- } else {
11432
- for (const group2 of groupBy) {
11433
- if (group2.field && keys.has(group2.field)) {
11434
- groupByAffected = true;
11435
- break;
11200
+ isItemNegative(keys) {
11201
+ return !this.isItemPositive(keys);
11202
+ }
11203
+ setItemValue(keys, shouldMakePositive) {
11204
+ var _a;
11205
+ if (shouldMakePositive === this.isItemPositive(keys)) {
11206
+ return;
11207
+ }
11208
+ if (shouldMakePositive) {
11209
+ if (this.allNegative === true) {
11210
+ if (!this.positiveMap) {
11211
+ throw `No positiveMap found when trying to set item ${keys.join(
11212
+ ","
11213
+ )} be positive`;
11214
+ }
11215
+ this.positiveMap.set(keys, true);
11216
+ } else if (this.allPositive === true) {
11217
+ if (!this.negativeMap) {
11218
+ throw `No negativeMap found when trying to set item ${keys.join(
11219
+ ","
11220
+ )} be positive`;
11436
11221
  }
11222
+ this.negativeMap.delete(keys);
11437
11223
  }
11438
- }
11439
- }
11440
- if (filterValue && filterValue.length) {
11441
- if (keys === true) {
11442
- filterAffected = true;
11443
11224
  } else {
11444
- for (const filter of filterValue) {
11445
- if (filter.id) {
11446
- filterAffected = true;
11447
- break;
11225
+ if (this.allPositive === true) {
11226
+ if (!this.negativeMap) {
11227
+ throw `No negativeMap found when trying to set item ${keys.join(
11228
+ ","
11229
+ )} be negative`;
11448
11230
  }
11449
- if (filter.field && keys.has(filter.field)) {
11450
- filterAffected = true;
11451
- break;
11231
+ this.negativeMap.set(keys, true);
11232
+ } else if (this.allNegative === true) {
11233
+ if (!this.positiveMap) {
11234
+ throw `No positiveMap found when trying to set item ${keys.join(
11235
+ ","
11236
+ )} be negative`;
11452
11237
  }
11238
+ (_a = this.positiveMap) == null ? void 0 : _a.delete(keys);
11453
11239
  }
11454
11240
  }
11455
11241
  }
11456
- if (aggregationReducers && Object.keys(aggregationReducers).length) {
11457
- if (keys === true) {
11458
- aggregationsAffected = true;
11459
- } else {
11460
- for (const key in aggregationReducers)
11461
- if (aggregationReducers.hasOwnProperty(key)) {
11462
- const reducer = aggregationReducers[key];
11463
- if (!reducer.field) {
11464
- aggregationsAffected = true;
11465
- break;
11466
- } else {
11467
- if (keys.has(reducer.field)) {
11468
- aggregationsAffected = true;
11469
- break;
11470
- }
11471
- }
11472
- }
11473
- }
11242
+ makeItemNegative(keys) {
11243
+ this.setItemValue(keys, false);
11474
11244
  }
11475
- return {
11476
- sortInfo: sortInfoAffected,
11477
- groupBy: groupByAffected,
11478
- filterValue: filterAffected,
11479
- aggregationReducers: aggregationsAffected
11480
- };
11481
- }
11482
-
11483
- // src/components/DataSource/BooleanDeepCollectionState.ts
11484
- var BooleanDeepCollectionState = class {
11485
- constructor(state) {
11486
- const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? (
11487
- //@ts-ignore
11488
- state.getState()
11489
- ) : state;
11490
- const positiveItems = this.getPositiveFromState(stateObject);
11491
- const negativeItems = this.getNegativeFromState(stateObject);
11492
- this.update({
11493
- negativeItems,
11494
- positiveItems
11495
- });
11496
- }
11497
- getInitialState() {
11498
- return this.initialState;
11499
- }
11500
- // protected getState(): BooleanDeepCollectionStateObject<KeyType> {
11501
- // return {
11502
- // positiveItems: this.allPositive
11503
- // ? true
11504
- // : this.positiveMap?.topDownKeys() ?? [],
11505
- // negativeItems: this.allNegative
11506
- // ? true
11507
- // : this.negativeMap?.topDownKeys() ?? [],
11508
- // };
11509
- // }
11510
- destroy() {
11511
- var _a, _b;
11512
- (_a = this.positiveMap) == null ? void 0 : _a.clear();
11513
- (_b = this.negativeMap) == null ? void 0 : _b.clear();
11514
- delete this.positiveMap;
11515
- delete this.negativeMap;
11516
- }
11517
- update(state) {
11518
- const { positiveItems, negativeItems } = state;
11519
- this.allNegative = negativeItems === true;
11520
- this.allPositive = positiveItems === true;
11521
- if (this.allNegative && this.allPositive) {
11522
- throw `Cannot have both negativeItems and positiveItems be true!`;
11523
- }
11524
- if (negativeItems !== true) {
11525
- if (this.negativeMap) {
11526
- this.negativeMap.clear();
11527
- this.negativeMap.fill(negativeItems.map((keys) => [keys, true]));
11528
- } else {
11529
- this.negativeMap = new DeepMap(
11530
- negativeItems.map((keys) => [keys, true])
11531
- );
11532
- }
11533
- if (this.positiveMap) {
11534
- this.positiveMap.clear();
11535
- }
11536
- }
11537
- if (positiveItems !== true) {
11538
- if (this.positiveMap) {
11539
- this.positiveMap.clear();
11540
- this.positiveMap.fill(positiveItems.map((keys) => [keys, true]));
11541
- } else {
11542
- this.positiveMap = new DeepMap(
11543
- positiveItems.map((keys) => [keys, true])
11544
- );
11545
- }
11546
- if (this.negativeMap) {
11547
- this.negativeMap.clear();
11548
- }
11549
- }
11550
- }
11551
- areAllNegative() {
11552
- return this.allNegative && (this.positiveMap ? this.positiveMap.size === 0 : true);
11553
- }
11554
- areAllPositive() {
11555
- return this.allPositive && (this.negativeMap ? this.negativeMap.size === 0 : true);
11556
- }
11557
- makeAllNegative() {
11558
- this.update({
11559
- negativeItems: true,
11560
- positiveItems: []
11561
- });
11562
- }
11563
- makeAllPositive() {
11564
- this.update({
11565
- positiveItems: true,
11566
- negativeItems: []
11567
- });
11568
- }
11569
- isItemPositive(keys) {
11570
- var _a, _b;
11571
- if (this.allPositive === true) {
11572
- if (this.allNegative === true) {
11573
- throw 'Cannot have both positiveItems and negativeItems be "true"';
11574
- }
11575
- return !((_a = this.negativeMap) == null ? void 0 : _a.has(keys));
11576
- }
11577
- return (_b = this.positiveMap) == null ? void 0 : _b.has(keys);
11578
- }
11579
- isItemNegative(keys) {
11580
- return !this.isItemPositive(keys);
11581
- }
11582
- setItemValue(keys, shouldMakePositive) {
11583
- var _a;
11584
- if (shouldMakePositive === this.isItemPositive(keys)) {
11585
- return;
11586
- }
11587
- if (shouldMakePositive) {
11588
- if (this.allNegative === true) {
11589
- if (!this.positiveMap) {
11590
- throw `No positiveMap found when trying to set item ${keys.join(
11591
- ","
11592
- )} be positive`;
11593
- }
11594
- this.positiveMap.set(keys, true);
11595
- } else if (this.allPositive === true) {
11596
- if (!this.negativeMap) {
11597
- throw `No negativeMap found when trying to set item ${keys.join(
11598
- ","
11599
- )} be positive`;
11600
- }
11601
- this.negativeMap.delete(keys);
11602
- }
11603
- } else {
11604
- if (this.allPositive === true) {
11605
- if (!this.negativeMap) {
11606
- throw `No negativeMap found when trying to set item ${keys.join(
11607
- ","
11608
- )} be negative`;
11609
- }
11610
- this.negativeMap.set(keys, true);
11611
- } else if (this.allNegative === true) {
11612
- if (!this.positiveMap) {
11613
- throw `No positiveMap found when trying to set item ${keys.join(
11614
- ","
11615
- )} be negative`;
11616
- }
11617
- (_a = this.positiveMap) == null ? void 0 : _a.delete(keys);
11618
- }
11619
- }
11620
- }
11621
- makeItemNegative(keys) {
11622
- this.setItemValue(keys, false);
11623
- }
11624
- makeItemPositive(keys) {
11625
- this.setItemValue(keys, true);
11626
- }
11627
- toggleItem(keys) {
11628
- this.setItemValue(keys, !this.isItemPositive(keys));
11629
- }
11630
- };
11245
+ makeItemPositive(keys) {
11246
+ this.setItemValue(keys, true);
11247
+ }
11248
+ toggleItem(keys) {
11249
+ this.setItemValue(keys, !this.isItemPositive(keys));
11250
+ }
11251
+ };
11631
11252
 
11632
11253
  // src/components/DataSource/GroupRowsState.ts
11633
11254
  var GroupRowsState = class extends BooleanDeepCollectionState {
@@ -11679,554 +11300,548 @@ var GroupRowsState = class extends BooleanDeepCollectionState {
11679
11300
  }
11680
11301
  };
11681
11302
 
11682
- // src/components/DataSource/privateHooks/useLoadData.ts
11683
- var import_react35 = require("react");
11303
+ // src/utils/groupAndPivot/getGroupKeysForDataItem.ts
11304
+ function getGroupKeysForDataItem(data, groupBy) {
11305
+ return groupBy.reduce((groupKeys, groupBy2) => {
11306
+ const { field: groupByProperty, valueGetter, toKey: groupToKey } = groupBy2;
11307
+ const value = groupByProperty ? data[groupByProperty] : valueGetter == null ? void 0 : valueGetter({ data, field: groupByProperty });
11308
+ const key = (groupToKey || DEFAULT_TO_KEY)(
11309
+ value,
11310
+ data
11311
+ );
11312
+ groupKeys.push(key);
11313
+ return groupKeys;
11314
+ }, []);
11315
+ }
11684
11316
 
11685
- // src/components/hooks/useEffectWithChanges.ts
11686
- var import_react34 = require("react");
11687
- function useEffectWithChanges(fn, deps) {
11688
- const prevRef = (0, import_react34.useRef)({});
11689
- const oldValuesRef = (0, import_react34.useRef)({});
11690
- const oldValues = oldValuesRef.current;
11691
- const changesRef = (0, import_react34.useRef)({});
11692
- const changes = changesRef.current;
11693
- const useEffectDeps = [];
11694
- for (const k in deps) {
11695
- if (deps.hasOwnProperty(k)) {
11696
- if (deps[k] !== prevRef.current[k]) {
11697
- changes[k] = deps[k];
11698
- oldValues[k] = prevRef.current[k];
11317
+ // src/components/DataSource/RowSelectionState.ts
11318
+ var RowSelectionState = class {
11319
+ constructor(state, getConfig, _forTestingOnly) {
11320
+ this.selectedRows = null;
11321
+ this.deselectedRows = null;
11322
+ this.defaultSelection = false;
11323
+ this.selectedMap = new DeepMap();
11324
+ this.deselectedMap = new DeepMap();
11325
+ this.onlyUsePrimaryKeys = false;
11326
+ // TODO make it easy to share the cache with another instance
11327
+ this.selectionCache = new DeepMap();
11328
+ this.selectionCountCache = new DeepMap();
11329
+ this.mapSet = (name, key) => {
11330
+ if (!Array.isArray(key)) {
11331
+ if (this.onlyUsePrimaryKeys) {
11332
+ key = [key];
11333
+ } else {
11334
+ key = [...this.getGroupKeysForPrimaryKey(key), key];
11335
+ }
11699
11336
  }
11700
- useEffectDeps.push(deps[k]);
11337
+ this.xcache();
11338
+ if (name === "selected") {
11339
+ this.selectedMap.set(key, true);
11340
+ } else {
11341
+ this.deselectedMap.set(key, true);
11342
+ }
11343
+ };
11344
+ this._selectedMapSet = (key) => {
11345
+ this.mapSet("selected", key);
11346
+ };
11347
+ this._deselectedMapSet = (key) => {
11348
+ this.mapSet("deselected", key);
11349
+ };
11350
+ const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? (
11351
+ //@ts-ignore
11352
+ state.getState()
11353
+ ) : state;
11354
+ this.getConfig = getConfig;
11355
+ this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
11356
+ if (_forTestingOnly) {
11357
+ Object.assign(this, _forTestingOnly);
11701
11358
  }
11359
+ this.update(stateObject);
11702
11360
  }
11703
- prevRef.current = deps;
11704
- (0, import_react34.useEffect)(() => {
11705
- const changes2 = changesRef.current;
11706
- let result = void 0;
11707
- if (Object.keys(changes2).length !== 0) {
11708
- result = fn(changes2, oldValues);
11361
+ getGroupKeysForPrimaryKey(pk) {
11362
+ const { indexer, groupBy } = this.getConfig();
11363
+ const data = indexer.getDataForPrimaryKey(pk);
11364
+ return data ? getGroupKeysForDataItem(data, groupBy) : [];
11365
+ }
11366
+ getGroupDeepMap() {
11367
+ return this.getConfig().groupDeepMap;
11368
+ }
11369
+ getGroupCount(groupKeys) {
11370
+ var _a;
11371
+ if (groupKeys.length == 0) {
11372
+ return this.getConfig().totalCount;
11709
11373
  }
11710
- changesRef.current = {};
11711
- oldValuesRef.current = {};
11712
- return result;
11713
- }, useEffectDeps);
11714
- }
11715
- function useEffectWithObject(fn, deps) {
11716
- const useEffectDeps = [];
11717
- for (const k in deps) {
11718
- if (deps.hasOwnProperty(k)) {
11719
- useEffectDeps.push(deps[k]);
11374
+ const groupDeepMap = this.getGroupDeepMap();
11375
+ const deepMapValue = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
11376
+ if (!deepMapValue) {
11377
+ return 0;
11720
11378
  }
11379
+ return (_a = deepMapValue.totalChildrenCount) != null ? _a : deepMapValue.items.length || 0;
11721
11380
  }
11722
- (0, import_react34.useEffect)(fn, useEffectDeps);
11723
- }
11724
-
11725
- // src/utils/composeFunctions.ts
11726
- function composeFunctions(...fns) {
11727
- const f = (...args) => {
11728
- fns.forEach((fn) => {
11729
- if (typeof fn === "function") {
11730
- fn(...args);
11731
- }
11732
- });
11733
- };
11734
- return f;
11735
- }
11736
-
11737
- // src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts
11738
- function prepareColumn(column) {
11739
- const { pivotByAtIndex: pivotByForColumn, pivotAggregator } = column;
11740
- if (pivotByForColumn == null ? void 0 : pivotByForColumn.column) {
11741
- if (typeof pivotByForColumn.column === "function") {
11742
- Object.assign(column, pivotByForColumn.column({ column }));
11743
- } else {
11744
- Object.assign(column, pivotByForColumn.column);
11745
- }
11381
+ getGroupKeysDirectlyInsideGroup(groupKeys) {
11382
+ const { groupDeepMap } = this.getConfig();
11383
+ return (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith(groupKeys, true, 1)) || [];
11746
11384
  }
11747
- if (pivotAggregator == null ? void 0 : pivotAggregator.pivotColumn) {
11748
- if (typeof pivotAggregator.pivotColumn === "function") {
11749
- Object.assign(column, pivotAggregator.pivotColumn({ column }));
11750
- } else {
11751
- Object.assign(column, pivotAggregator.pivotColumn);
11385
+ getAllPrimaryKeysInsideGroup(groupKeys) {
11386
+ const { groupDeepMap } = this.getConfig();
11387
+ if (!groupKeys.length) {
11388
+ const topLevelKeys = (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith([], true, 1)) || [];
11389
+ return topLevelKeys.map((groupKeys2) => this.getAllPrimaryKeysInsideGroup(groupKeys2)).flat();
11752
11390
  }
11391
+ const group2 = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
11392
+ return group2 ? group2.items.map(this.getConfig().toPrimaryKey) : [];
11753
11393
  }
11754
- return column;
11755
- }
11756
- function prepareColumnGroup(columnGroup) {
11757
- const { pivotByAtIndex: pivotByForColumnGroup } = columnGroup;
11758
- if (pivotByForColumnGroup == null ? void 0 : pivotByForColumnGroup.columnGroup) {
11759
- if (typeof pivotByForColumnGroup.columnGroup === "function") {
11760
- Object.assign(
11761
- columnGroup,
11762
- pivotByForColumnGroup.columnGroup({ columnGroup })
11763
- );
11764
- } else {
11765
- Object.assign(columnGroup, pivotByForColumnGroup.columnGroup);
11766
- }
11394
+ getGroupByLength() {
11395
+ return this.getConfig().groupBy.length;
11767
11396
  }
11768
- return columnGroup;
11769
- }
11770
- function getPivotColumnsAndColumnGroups({
11771
- deepMap,
11772
- pivotBy,
11773
- pivotTotalColumnPosition,
11774
- pivotGrandTotalColumnPosition,
11775
- reducers = {},
11776
- showSeparatePivotColumnForSingleAggregation = false
11777
- }) {
11778
- const pivotLength = pivotBy.length;
11779
- const aggregationReducers = Object.keys(
11780
- reducers
11781
- ).map((key) => {
11782
- return __spreadProps(__spreadValues({}, reducers[key]), { id: key });
11783
- });
11784
- if (!aggregationReducers.length) {
11785
- showSeparatePivotColumnForSingleAggregation = true;
11786
- pivotGrandTotalColumnPosition = false;
11787
- pivotTotalColumnPosition = false;
11788
- aggregationReducers.push({
11789
- id: "__empty-aggregation-reducer__",
11790
- name: "-",
11791
- initialValue: null,
11792
- reducer: () => null
11793
- });
11397
+ static from(rowSeleStateObject, getConfig, overrides) {
11398
+ return new RowSelectionState(rowSeleStateObject, getConfig, overrides);
11794
11399
  }
11795
- const columns = {};
11796
- const columnGroups = {};
11797
- const addGrandTotalColumns = once(function() {
11798
- aggregationReducers.forEach((reducer, index) => {
11799
- columns[`total:${reducer.id}`] = prepareColumn({
11800
- header: `${reducer.name || reducer.id} total`,
11801
- pivotBy,
11802
- pivotColumn: true,
11803
- pivotTotalColumn: true,
11804
- pivotAggregator: reducer,
11805
- pivotAggregatorIndex: index,
11806
- pivotGroupKeys: [],
11807
- pivotGroupKey: "",
11808
- pivotIndex: -1,
11809
- valueFormatter: ({ rowInfo }) => {
11810
- var _a;
11811
- return rowInfo.isGroupRow ? (_a = rowInfo.reducerResults) == null ? void 0 : _a[reducer.id] : null;
11400
+ update(stateObject) {
11401
+ var _a, _b;
11402
+ this.selectedRows = stateObject.selectedRows || null;
11403
+ this.deselectedRows = stateObject.deselectedRows || null;
11404
+ this.selectedMap.clear();
11405
+ this.deselectedMap.clear();
11406
+ (_a = this.selectedRows) == null ? void 0 : _a.forEach(this._selectedMapSet);
11407
+ (_b = this.deselectedRows) == null ? void 0 : _b.forEach(this._deselectedMapSet);
11408
+ this.defaultSelection = stateObject.defaultSelection;
11409
+ this.xcache();
11410
+ }
11411
+ xcache() {
11412
+ this.selectionCache.clear();
11413
+ this.selectionCountCache.clear();
11414
+ }
11415
+ getState() {
11416
+ const normalize = (allKeys) => {
11417
+ const groupByLength = this.getGroupByLength();
11418
+ return allKeys.map((keys) => {
11419
+ if (this.onlyUsePrimaryKeys) {
11420
+ return keys[0];
11812
11421
  }
11422
+ return keys.length > groupByLength ? keys.pop() : keys;
11813
11423
  });
11424
+ };
11425
+ const selectedRows = normalize(this.selectedMap.topDownKeys());
11426
+ const deselectedRows = normalize(this.deselectedMap.topDownKeys());
11427
+ return {
11428
+ defaultSelection: this.defaultSelection,
11429
+ selectedRows,
11430
+ deselectedRows
11431
+ };
11432
+ }
11433
+ deselectAll() {
11434
+ this.update({
11435
+ defaultSelection: false,
11436
+ selectedRows: [],
11437
+ deselectedRows: []
11814
11438
  });
11815
- });
11816
- if (!pivotLength && pivotTotalColumnPosition === "start" || pivotGrandTotalColumnPosition === "start") {
11817
- addGrandTotalColumns();
11818
11439
  }
11819
- const isSingleAggregationColumn = !showSeparatePivotColumnForSingleAggregation && aggregationReducers.length === 1;
11820
- deepMap.visitDepthFirst((_value, keys, _indexInGroup, next) => {
11821
- keys = [...keys];
11822
- if (pivotTotalColumnPosition === "end") {
11823
- next == null ? void 0 : next();
11440
+ selectAll() {
11441
+ this.update({
11442
+ defaultSelection: true,
11443
+ deselectedRows: [],
11444
+ selectedRows: []
11445
+ });
11446
+ }
11447
+ isRowDefaultSelected() {
11448
+ return this.defaultSelection === true;
11449
+ }
11450
+ isRowDefaultDeselected() {
11451
+ return this.defaultSelection === false;
11452
+ }
11453
+ /**
11454
+ *
11455
+ * @param key the id of the row - if a row in a grouped datasource, this is the final row id, without the group keys
11456
+ * @param groupKeys the keys of row parents, in order
11457
+ * @returns Whether the row is selected or not.
11458
+ */
11459
+ isRowSelected(key, groupKeys) {
11460
+ if (this.onlyUsePrimaryKeys) {
11461
+ return this.defaultSelection ? !this.deselectedMap.has([key]) : this.selectedMap.has([key]);
11824
11462
  }
11825
- if (keys.length === pivotLength) {
11826
- const pivotByForColumn = pivotBy[keys.length - 1];
11827
- const parentKeys = keys.slice(0, -1);
11828
- let parentColumnGroupId = parentKeys.join("/");
11829
- if (!isSingleAggregationColumn) {
11830
- const columnGroupId = parentColumnGroupId;
11831
- parentColumnGroupId = keys.join("/");
11832
- const pivotGroupKey = keys[keys.length - 1];
11833
- columnGroups[parentColumnGroupId] = prepareColumnGroup({
11834
- header: `${pivotGroupKey}`,
11835
- columnGroup: columnGroupId,
11836
- pivotBy,
11837
- pivotGroupKeys: keys,
11838
- pivotByAtIndex: pivotByForColumn,
11839
- pivotIndex: keys.length - 1,
11840
- pivotGroupKey
11841
- });
11463
+ groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
11464
+ const finalKey = [...groupKeys, key];
11465
+ const cachedResult = this.selectionCache.get(finalKey);
11466
+ if (cachedResult !== void 0) {
11467
+ return cachedResult;
11468
+ }
11469
+ const inSelected = this.selectedMap.has(finalKey);
11470
+ const inDeselected = this.deselectedMap.has(finalKey);
11471
+ if (inSelected) {
11472
+ this.selectionCache.set(finalKey, true);
11473
+ return true;
11474
+ }
11475
+ if (inDeselected) {
11476
+ this.selectionCache.set(finalKey, false);
11477
+ return false;
11478
+ }
11479
+ if (this.selectedMap.has(groupKeys)) {
11480
+ this.selectionCache.set(finalKey, true);
11481
+ return true;
11482
+ }
11483
+ if (this.deselectedMap.has(groupKeys)) {
11484
+ this.selectionCache.set(finalKey, false);
11485
+ return false;
11486
+ }
11487
+ groupKeys = [...groupKeys];
11488
+ while (groupKeys.length) {
11489
+ groupKeys.pop();
11490
+ const inSelected2 = this.selectedMap.has(groupKeys);
11491
+ const inDeselected2 = this.deselectedMap.has(groupKeys);
11492
+ if (inSelected2) {
11493
+ this.selectionCache.set(finalKey, true);
11494
+ return true;
11842
11495
  }
11843
- aggregationReducers.forEach((reducer, index) => {
11844
- const header = isSingleAggregationColumn ? `${keys[keys.length - 1]}` : reducer.name || reducer.id;
11845
- const computedPivotColumn = prepareColumn({
11846
- pivotBy,
11847
- pivotColumn: true,
11848
- pivotTotalColumn: false,
11849
- pivotAggregator: reducer,
11850
- pivotAggregatorIndex: index,
11851
- pivotGroupKeys: keys,
11852
- pivotGroupKey: keys[keys.length - 1],
11853
- pivotIndex: keys.length - 1,
11854
- pivotByAtIndex: pivotByForColumn,
11855
- defaultSortable: false,
11856
- columnGroup: parentColumnGroupId,
11857
- header,
11858
- valueFormatter: ({ rowInfo }) => {
11859
- var _a, _b;
11860
- if (!rowInfo.isGroupRow) {
11861
- return null;
11862
- }
11863
- return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
11864
- }
11865
- });
11866
- const columnId = `${reducer.id}:${keys.join("/")}`;
11867
- columns[columnId] = computedPivotColumn;
11868
- });
11496
+ if (inDeselected2) {
11497
+ this.selectionCache.set(finalKey, false);
11498
+ return false;
11499
+ }
11500
+ }
11501
+ this.selectionCache.set(finalKey, this.defaultSelection);
11502
+ return this.defaultSelection;
11503
+ }
11504
+ isRowDeselected(key, groupKeys) {
11505
+ return !this.isRowSelected(key, groupKeys);
11506
+ }
11507
+ setRowSelected(key, selected, groupKeys) {
11508
+ if (selected) {
11509
+ this.setRowAsSelected(key, groupKeys);
11869
11510
  } else {
11870
- const colGroupId = keys.join("/");
11871
- const parentKeys = keys.slice(0, -1);
11872
- columnGroups[colGroupId] = prepareColumnGroup({
11873
- columnGroup: parentKeys.length ? parentKeys.join("/") : void 0,
11874
- header: `${keys[keys.length - 1]}`,
11875
- pivotBy,
11876
- pivotGroupKeys: keys,
11877
- pivotIndex: keys.length - 1,
11878
- pivotByAtIndex: pivotBy[keys.length - 1],
11879
- pivotGroupKey: keys[keys.length - 1]
11880
- });
11881
- if (pivotTotalColumnPosition !== false) {
11882
- const pivotByForColumn = pivotBy[keys.length - 1];
11883
- let columnGroupId = parentKeys.length ? parentKeys.join("/") : void 0;
11884
- if (!isSingleAggregationColumn) {
11885
- const parentGroupForTotalsGroup = columnGroupId;
11886
- columnGroupId = `total:${keys.join("/")}`;
11887
- columnGroups[columnGroupId] = prepareColumnGroup({
11888
- header: `${keys[keys.length - 1]} total`,
11889
- columnGroup: parentGroupForTotalsGroup,
11890
- pivotBy,
11891
- pivotTotalColumnGroup: true,
11892
- pivotGroupKeys: keys,
11893
- pivotIndex: keys.length - 1,
11894
- pivotByAtIndex: pivotByForColumn,
11895
- pivotGroupKey: keys[keys.length - 1]
11896
- });
11511
+ this.setRowAsDeselected(key, groupKeys);
11512
+ }
11513
+ }
11514
+ /**
11515
+ * Returns if the selection state ('full','partial','none') for the current group
11516
+ *
11517
+ * The selection state will be full (true) if either of those are true:
11518
+ * * the group keys are specified as selected
11519
+ * * all the children are specified as selected
11520
+ *
11521
+ * The selection state will be partial (null) if either of those are true:
11522
+ * * the group keys are partially selected
11523
+ * * some of the children are specified as selected
11524
+ *
11525
+ *
11526
+ * @param groupKeys the keys of the group row
11527
+ * @param children leaf children that belong to the group
11528
+ * @returns boolean
11529
+ */
11530
+ getGroupRowSelectionState(initialGroupKeys) {
11531
+ const cachedResult = this.selectionCache.get(initialGroupKeys);
11532
+ if (cachedResult !== void 0) {
11533
+ return cachedResult;
11534
+ }
11535
+ const { selectedCount, deselectedCount } = this.getSelectionCountFor(
11536
+ initialGroupKeys,
11537
+ this.onlyUsePrimaryKeys ? (
11538
+ // there is no need for the state from the parent group
11539
+ // when we are in this case, so don't do that
11540
+ void 0
11541
+ ) : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys)
11542
+ );
11543
+ const result = selectedCount && deselectedCount ? null : selectedCount ? true : false;
11544
+ this.selectionCache.set(initialGroupKeys, result);
11545
+ return result;
11546
+ }
11547
+ getGroupRowBooleanSelectionStateFromParent(initialGroupKeys) {
11548
+ if (!initialGroupKeys.length) {
11549
+ return this.defaultSelection;
11550
+ }
11551
+ const groupKeys = [...initialGroupKeys];
11552
+ const selfDeselected = this.deselectedMap.has(groupKeys);
11553
+ const selfSelected = this.selectedMap.has(groupKeys);
11554
+ let selectionState = selfSelected && !selfDeselected ? true : selfDeselected && !selfSelected ? false : void 0;
11555
+ if (selectionState === void 0) {
11556
+ while (groupKeys.length) {
11557
+ groupKeys.pop();
11558
+ if (this.deselectedMap.has(groupKeys)) {
11559
+ selectionState = false;
11560
+ break;
11561
+ }
11562
+ if (this.selectedMap.has(groupKeys)) {
11563
+ selectionState = true;
11564
+ break;
11897
11565
  }
11898
- aggregationReducers.forEach((reducer, index) => {
11899
- const header = isSingleAggregationColumn ? `${keys[keys.length - 1]} total ` : `${reducer.name || reducer.id} total`;
11900
- const computedPivotColumn = prepareColumn({
11901
- columnGroup: columnGroupId,
11902
- header,
11903
- pivotAggregator: reducer,
11904
- pivotAggregatorIndex: index,
11905
- pivotColumn: true,
11906
- pivotTotalColumn: true,
11907
- pivotGroupKeys: keys,
11908
- pivotGroupKey: keys[keys.length - 1],
11909
- pivotByAtIndex: pivotByForColumn,
11910
- pivotIndex: keys.length - 1,
11911
- pivotBy,
11912
- defaultSortable: false,
11913
- valueFormatter: ({ rowInfo }) => {
11914
- var _a, _b;
11915
- if (!rowInfo.isGroupRow) {
11916
- return null;
11917
- }
11918
- return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
11919
- }
11920
- });
11921
- columns[`total:${reducer.id}:${keys.join("/")}`] = computedPivotColumn;
11922
- });
11923
11566
  }
11924
11567
  }
11925
- if (pivotTotalColumnPosition === "start" || pivotTotalColumnPosition === false) {
11926
- next == null ? void 0 : next();
11568
+ if (selectionState === void 0) {
11569
+ selectionState = this.defaultSelection;
11927
11570
  }
11928
- });
11929
- if (!pivotLength && pivotTotalColumnPosition === "end" || pivotGrandTotalColumnPosition === "end") {
11930
- addGrandTotalColumns();
11571
+ return selectionState;
11931
11572
  }
11932
- const result = {
11933
- columns,
11934
- columnGroups
11935
- };
11936
- return result;
11937
- }
11938
-
11939
- // src/utils/groupAndPivot/getGroupKeysForDataItem.ts
11940
- function getGroupKeysForDataItem(data, groupBy) {
11941
- return groupBy.reduce((groupKeys, groupBy2) => {
11942
- const { field: groupByProperty, valueGetter, toKey: groupToKey } = groupBy2;
11943
- const value = groupByProperty ? data[groupByProperty] : valueGetter == null ? void 0 : valueGetter({ data, field: groupByProperty });
11944
- const key = (groupToKey || DEFAULT_TO_KEY)(
11945
- value,
11946
- data
11573
+ isGroupRowPartlySelected(groupKeys) {
11574
+ return this.getGroupRowSelectionState(groupKeys) === null;
11575
+ }
11576
+ isGroupRowSelected(groupKeys) {
11577
+ return this.getGroupRowSelectionState(groupKeys) === true;
11578
+ }
11579
+ isGroupRowDeselected(groupKeys) {
11580
+ return this.getGroupRowSelectionState(groupKeys) === false;
11581
+ }
11582
+ selectGroupRow(groupKeys) {
11583
+ if (this.onlyUsePrimaryKeys) {
11584
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
11585
+ keys.forEach((key) => {
11586
+ if (this.defaultSelection === true) {
11587
+ this.deselectedMap.delete([key]);
11588
+ } else {
11589
+ this._selectedMapSet(key);
11590
+ }
11591
+ });
11592
+ this.xcache();
11593
+ return;
11594
+ }
11595
+ const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
11596
+ selectedKeys.forEach((groupKeys2) => {
11597
+ this.selectedMap.delete(groupKeys2);
11598
+ });
11599
+ if (groupKeys.length === 1 && this.defaultSelection === true) {
11600
+ } else {
11601
+ this._selectedMapSet(groupKeys);
11602
+ }
11603
+ const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
11604
+ deselectedKeys.forEach((groupKeys2) => {
11605
+ this.deselectedMap.delete(groupKeys2);
11606
+ });
11607
+ }
11608
+ deselectGroupRow(groupKeys) {
11609
+ if (this.onlyUsePrimaryKeys) {
11610
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
11611
+ keys.forEach((key) => {
11612
+ if (this.defaultSelection === false) {
11613
+ this.selectedMap.delete([key]);
11614
+ } else {
11615
+ this._deselectedMapSet(key);
11616
+ }
11617
+ });
11618
+ this.xcache();
11619
+ return;
11620
+ }
11621
+ const deselectedKeys = this.deselectedMap.getKeysStartingWith(
11622
+ groupKeys,
11623
+ true
11947
11624
  );
11948
- groupKeys.push(key);
11949
- return groupKeys;
11950
- }, []);
11951
- }
11952
-
11953
- // src/components/InfiniteTable/api/getRowSelectionApi.ts
11954
- function cloneRowSelection(rowSelection, stateOrGetDataSourceState) {
11955
- return new RowSelectionState(
11956
- rowSelection,
11957
- rowSelectionStateConfigGetter(stateOrGetDataSourceState)
11958
- );
11959
- }
11960
- function rowSelectionStateConfigGetter(stateOrStateGetter) {
11961
- return () => {
11962
- const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
11963
- return {
11964
- lazyLoad: !!state.lazyLoad,
11965
- toPrimaryKey: state.toPrimaryKey,
11966
- onlyUsePrimaryKeys: !state.useGroupKeysForMultiRowSelection,
11967
- groupBy: state.groupBy,
11968
- groupDeepMap: state.groupDeepMap,
11969
- indexer: state.indexer,
11970
- totalCount: state.unfilteredCount
11971
- };
11972
- };
11973
- }
11974
- function getRowSelectionApi(param) {
11975
- const {
11976
- // getComputed,
11977
- // getState,
11978
- getDataSourceState,
11979
- // componentActions,
11980
- dataSourceActions
11981
- } = param;
11982
- const rowSelectionApi = {
11983
- get allRowsSelected() {
11984
- return getDataSourceState().allRowsSelected;
11985
- },
11986
- selectAll() {
11987
- const { rowSelection, selectionMode } = getDataSourceState();
11988
- if (selectionMode !== "multi-row") {
11989
- throw "Selection mode is not multi-row";
11625
+ deselectedKeys.forEach((groupKeys2) => {
11626
+ this.deselectedMap.delete(groupKeys2);
11627
+ });
11628
+ if (groupKeys.length === 1 && this.defaultSelection === false) {
11629
+ } else {
11630
+ this._deselectedMapSet(groupKeys);
11631
+ }
11632
+ const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
11633
+ selectedKeys.forEach((groupKeys2) => {
11634
+ this.selectedMap.delete(groupKeys2);
11635
+ });
11636
+ }
11637
+ setRowAsSelected(key, groupKeys) {
11638
+ if (this.onlyUsePrimaryKeys) {
11639
+ if (this.defaultSelection) {
11640
+ this.deselectedMap.delete([key]);
11641
+ } else {
11642
+ this._selectedMapSet(key);
11990
11643
  }
11991
- if (!(rowSelection instanceof RowSelectionState)) {
11992
- throw "Invalid row selection";
11644
+ this.xcache();
11645
+ return;
11646
+ }
11647
+ groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
11648
+ const finalKey = [...groupKeys, key];
11649
+ this.deselectedMap.delete(finalKey);
11650
+ this.xcache();
11651
+ if (this.getGroupRowSelectionState(groupKeys) !== true) {
11652
+ this._selectedMapSet(finalKey);
11653
+ if (this.getGroupRowSelectionState(groupKeys) === true) {
11654
+ this.selectGroupRow(groupKeys);
11993
11655
  }
11994
- const rowSelectionState = new RowSelectionState(
11995
- rowSelection,
11996
- rowSelectionStateConfigGetter(getDataSourceState)
11997
- );
11998
- rowSelectionState.selectAll();
11999
- dataSourceActions.rowSelection = rowSelectionState;
12000
- },
12001
- deselectAll() {
12002
- const { rowSelection, selectionMode } = getDataSourceState();
12003
- if (selectionMode !== "multi-row") {
12004
- throw "Selection mode is not multi-row";
12005
- }
12006
- if (!(rowSelection instanceof RowSelectionState)) {
12007
- throw "Invalid row selection";
12008
- }
12009
- const rowSelectionState = new RowSelectionState(
12010
- rowSelection,
12011
- rowSelectionStateConfigGetter(getDataSourceState)
12012
- );
12013
- rowSelectionState.deselectAll();
12014
- dataSourceActions.rowSelection = rowSelectionState;
12015
- },
12016
- isRowSelected(pk, groupKeys) {
12017
- const { rowSelection, selectionMode, indexer, groupBy } = getDataSourceState();
12018
- if (selectionMode === "single-row") {
12019
- return rowSelection === pk;
12020
- }
12021
- if (selectionMode !== "multi-row") {
12022
- throw "Selection mode is not multi-row or single-row";
12023
- }
12024
- if (!(rowSelection instanceof RowSelectionState)) {
12025
- throw "Invalid row selection";
12026
- }
12027
- if (!groupKeys) {
12028
- const data = indexer.getDataForPrimaryKey(pk);
12029
- groupKeys = data ? getGroupKeysForDataItem(data, groupBy) : [];
12030
- }
12031
- return rowSelection.isRowSelected(pk, groupKeys);
12032
- },
12033
- isRowDeselected(pk, groupKeys) {
12034
- return !this.isRowSelected(pk, groupKeys);
12035
- },
12036
- selectRow(pk, groupKeys) {
12037
- const { rowSelection, selectionMode, indexer, groupBy } = getDataSourceState();
12038
- if (selectionMode === "single-row") {
12039
- dataSourceActions.rowSelection = pk;
12040
- return;
12041
- }
12042
- if (selectionMode !== "multi-row") {
12043
- throw "Selection mode is not multi-row or single-row";
12044
- }
12045
- if (!(rowSelection instanceof RowSelectionState)) {
12046
- throw "Invalid row selection";
12047
- }
12048
- if (!groupKeys) {
12049
- const data = indexer.getDataForPrimaryKey(pk);
12050
- groupKeys = data ? getGroupKeysForDataItem(data, groupBy) : [];
12051
- }
12052
- const rowSelectionState = new RowSelectionState(
12053
- rowSelection,
12054
- rowSelectionStateConfigGetter(getDataSourceState)
12055
- );
12056
- rowSelectionState.selectRow(pk, groupKeys);
12057
- dataSourceActions.rowSelection = rowSelectionState;
12058
- },
12059
- deselectRow(pk, groupKeys) {
12060
- const { selectionMode, rowSelection, indexer, groupBy } = getDataSourceState();
12061
- if (selectionMode === "single-row") {
12062
- dataSourceActions.rowSelection = null;
12063
- return;
12064
- }
12065
- if (selectionMode !== "multi-row") {
12066
- throw "Selection mode is not multi-row or single-row";
12067
- }
12068
- if (!(rowSelection instanceof RowSelectionState)) {
12069
- throw "Invalid row selection";
12070
- }
12071
- if (selectionMode === "multi-row") {
12072
- if (!groupKeys) {
12073
- const data = indexer.getDataForPrimaryKey(pk);
12074
- groupKeys = data ? getGroupKeysForDataItem(data, groupBy) : [];
12075
- }
12076
- const rowSelectionState = new RowSelectionState(
12077
- rowSelection,
12078
- rowSelectionStateConfigGetter(getDataSourceState)
12079
- );
12080
- rowSelectionState.deselectRow(pk, groupKeys);
12081
- dataSourceActions.rowSelection = rowSelectionState;
12082
- }
12083
- },
12084
- toggleRowSelection(pk, groupKeys) {
12085
- if (this.isRowSelected(pk, groupKeys)) {
12086
- this.deselectRow(pk, groupKeys);
11656
+ }
11657
+ }
11658
+ setRowAsDeselected(key, groupKeys) {
11659
+ if (this.onlyUsePrimaryKeys) {
11660
+ if (this.defaultSelection) {
11661
+ this._deselectedMapSet(key);
12087
11662
  } else {
12088
- this.selectRow(pk, groupKeys);
12089
- }
12090
- },
12091
- selectGroupRow(groupKeys) {
12092
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
12093
- if (selectionMode !== "multi-row") {
12094
- throw 'Selection mode should be "multi-row"';
12095
- }
12096
- if (!groupBy) {
12097
- throw "No grouping specified";
12098
- }
12099
- if (!(rowSelection instanceof RowSelectionState)) {
12100
- throw "Invalid row selection";
12101
- }
12102
- const rowSelectionState = new RowSelectionState(
12103
- rowSelection,
12104
- rowSelectionStateConfigGetter(getDataSourceState)
12105
- );
12106
- rowSelectionState.selectGroupRow(groupKeys);
12107
- dataSourceActions.rowSelection = rowSelectionState;
12108
- },
12109
- deselectGroupRow(groupKeys) {
12110
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
12111
- if (selectionMode !== "multi-row") {
12112
- throw 'Selection mode should be "multi-row"';
12113
- }
12114
- if (!groupBy) {
12115
- throw "No grouping specified";
12116
- }
12117
- if (!(rowSelection instanceof RowSelectionState)) {
12118
- throw "Invalid row selection";
12119
- }
12120
- const rowSelectionState = new RowSelectionState(
12121
- rowSelection,
12122
- rowSelectionStateConfigGetter(getDataSourceState)
12123
- );
12124
- rowSelectionState.deselectGroupRow(groupKeys);
12125
- dataSourceActions.rowSelection = rowSelectionState;
12126
- },
12127
- toggleGroupRowSelection(groupKeys) {
12128
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
12129
- if (selectionMode !== "multi-row") {
12130
- throw 'Selection mode should be "multi-row"';
12131
- }
12132
- if (!groupBy) {
12133
- throw "No grouping specified";
12134
- }
12135
- if (!(rowSelection instanceof RowSelectionState)) {
12136
- throw "Invalid row selection";
12137
- }
12138
- const rowSelectionState = new RowSelectionState(
12139
- rowSelection,
12140
- rowSelectionStateConfigGetter(getDataSourceState)
12141
- );
12142
- rowSelectionState.toggleGroupRowSelection(groupKeys);
12143
- dataSourceActions.rowSelection = rowSelectionState;
12144
- },
12145
- getGroupRowSelectionState(groupKeys, rowSelection) {
12146
- const state = getDataSourceState();
12147
- const { selectionMode, groupBy } = state;
12148
- const rowSelectionState = rowSelection ? new RowSelectionState(
12149
- rowSelection,
12150
- rowSelectionStateConfigGetter(state)
12151
- ) : state.rowSelection;
12152
- if (selectionMode !== "multi-row") {
12153
- throw 'Selection mode should be "multi-row"';
12154
- }
12155
- if (!groupBy) {
12156
- throw "No grouping specified";
12157
- }
12158
- if (!(rowSelectionState instanceof RowSelectionState)) {
12159
- throw "Invalid row selection";
11663
+ this.selectedMap.delete([key]);
12160
11664
  }
12161
- return rowSelectionState.getGroupRowSelectionState(groupKeys);
12162
- },
12163
- getSelectedPrimaryKeys: (rowSelection) => {
12164
- const state = getDataSourceState();
12165
- const rowSelectionState = rowSelection ? new RowSelectionState(
12166
- rowSelection,
12167
- rowSelectionStateConfigGetter(state)
12168
- ) : state.rowSelection;
12169
- const selected = [];
12170
- if (state.lazyLoad) {
12171
- console.error(
12172
- `getSelectedPrimaryKeys should not be called for lazy-loaded datasources as it wont return reliable results`
12173
- );
11665
+ this.xcache();
11666
+ return;
11667
+ }
11668
+ groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
11669
+ const finalKey = [...groupKeys, key];
11670
+ this.selectedMap.delete(finalKey);
11671
+ this.xcache();
11672
+ if (this.getGroupRowSelectionState(groupKeys) !== false) {
11673
+ this._deselectedMapSet(finalKey);
11674
+ if (this.getGroupRowSelectionState(groupKeys) === false) {
11675
+ this.deselectGroupRow(groupKeys);
12174
11676
  }
12175
- state.originalDataArray.forEach((data) => {
12176
- const id = state.toPrimaryKey(data);
12177
- if (rowSelectionState.isRowSelected(id)) {
12178
- selected.push(id);
12179
- }
12180
- });
12181
- return selected;
12182
11677
  }
12183
- };
12184
- if (false) {
12185
- globalThis.rowSelectionApi = rowSelectionApi;
12186
11678
  }
12187
- return rowSelectionApi;
12188
- }
12189
-
12190
- // src/components/DataSource/CellSelectionState.ts
12191
- var debug3 = dbg("CellSelectionState");
12192
- var WILDCARD = "*";
12193
- var CellSelectionState = class {
12194
- constructor(clone) {
12195
- this.wildcard = WILDCARD;
12196
- this.cache = new DeepMap();
12197
- this.selectedRowsToColumns = /* @__PURE__ */ new Map();
12198
- this.selectedColumnsToRows = /* @__PURE__ */ new Map();
12199
- this.deselectedRowsToColumns = /* @__PURE__ */ new Map();
12200
- this.deselectedColumnsToRows = /* @__PURE__ */ new Map();
12201
- this.defaultSelection = false;
12202
- this.deselectAll = () => {
12203
- this.update({
12204
- defaultSelection: false,
12205
- selectedCells: []
12206
- });
12207
- };
12208
- this.selectAll = () => {
12209
- this.update({
12210
- defaultSelection: true,
12211
- deselectedCells: []
12212
- });
12213
- };
12214
- const stateObject = clone && clone instanceof Object.getPrototypeOf(this).constructor ? clone.getState() : clone;
12215
- if (stateObject) {
12216
- this.update(stateObject);
12217
- }
11679
+ deselectRow(key, groupKeys) {
11680
+ this.setRowSelected(key, false, groupKeys);
12218
11681
  }
12219
- selectCell(rowId, colId) {
12220
- this.setCellSelected(rowId, colId, true);
11682
+ selectRow(key, groupKeys) {
11683
+ this.setRowSelected(key, true, groupKeys);
12221
11684
  }
12222
- deselectCell(rowId, colId) {
12223
- this.setCellSelected(rowId, colId, false);
11685
+ toggleGroupRowSelection(groupKeys) {
11686
+ const groupRowSelectionState = this.getGroupRowSelectionState(groupKeys);
11687
+ if (groupRowSelectionState === true) {
11688
+ this.deselectGroupRow(groupKeys);
11689
+ } else {
11690
+ this.selectGroupRow(groupKeys);
11691
+ }
12224
11692
  }
12225
- selectColumn(colId) {
12226
- this.setCellSelected(this.wildcard, colId, true);
11693
+ toggleRowSelection(key, groupKeys) {
11694
+ if (this.isRowSelected(key, groupKeys)) {
11695
+ this.deselectRow(key, groupKeys);
11696
+ } else {
11697
+ this.selectRow(key, groupKeys);
11698
+ }
12227
11699
  }
12228
- deselectColumn(colId) {
12229
- this.setCellSelected(this.wildcard, colId, false);
11700
+ getSelectedCount() {
11701
+ return this.getSelectionCountFor([]).selectedCount;
11702
+ }
11703
+ getDeselectedCount() {
11704
+ return this.getSelectionCountFor([]).deselectedCount;
11705
+ }
11706
+ getSelectionCountFor(groupKeys = [], parentSelected) {
11707
+ var _a, _b;
11708
+ const cachedResult = this.selectionCountCache.get(groupKeys);
11709
+ if (cachedResult != null) {
11710
+ return cachedResult;
11711
+ }
11712
+ const groupByLength = this.getGroupByLength();
11713
+ if (groupKeys.length > groupByLength) {
11714
+ const result2 = this.isRowSelected(groupKeys) ? { selectedCount: 1, deselectedCount: 0 } : {
11715
+ selectedCount: 0,
11716
+ deselectedCount: 1
11717
+ };
11718
+ this.selectionCountCache.set(groupKeys, result2);
11719
+ return result2;
11720
+ }
11721
+ if (groupByLength && this.onlyUsePrimaryKeys) {
11722
+ const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
11723
+ let selectedCount2 = 0;
11724
+ let deselectedCount2 = 0;
11725
+ allKeys2.forEach((key) => {
11726
+ if (this.defaultSelection) {
11727
+ if (this.deselectedMap.has([key])) {
11728
+ deselectedCount2++;
11729
+ return;
11730
+ }
11731
+ selectedCount2++;
11732
+ } else {
11733
+ if (this.selectedMap.has([key])) {
11734
+ selectedCount2++;
11735
+ return;
11736
+ }
11737
+ deselectedCount2++;
11738
+ }
11739
+ });
11740
+ const result2 = {
11741
+ selectedCount: selectedCount2,
11742
+ deselectedCount: deselectedCount2
11743
+ };
11744
+ this.selectionCountCache.set(groupKeys, result2);
11745
+ return result2;
11746
+ }
11747
+ parentSelected = parentSelected != null ? parentSelected : this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
11748
+ let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
11749
+ if (groupKeys.length === this.getGroupByLength()) {
11750
+ const selectionState = this.selectedMap.has(groupKeys) ? true : this.deselectedMap.has(groupKeys) ? false : parentSelected;
11751
+ const totalCount = this.getGroupCount(groupKeys);
11752
+ let selectedCount2 = this.selectedMap.getKeysStartingWith(
11753
+ groupKeys,
11754
+ true,
11755
+ 1
11756
+ ).length;
11757
+ let deselectedCount2 = this.deselectedMap.getKeysStartingWith(
11758
+ groupKeys,
11759
+ true,
11760
+ 1
11761
+ ).length;
11762
+ const notSpecifiedCount = totalCount - (selectedCount2 + deselectedCount2);
11763
+ const result2 = {
11764
+ selectedCount: selectedCount2 + (selectionState ? notSpecifiedCount : 0),
11765
+ deselectedCount: deselectedCount2 + (selectionState ? 0 : notSpecifiedCount)
11766
+ };
11767
+ this.selectionCountCache.set(groupKeys, result2);
11768
+ return result2;
11769
+ }
11770
+ let selectedCount = 0;
11771
+ let deselectedCount = 0;
11772
+ if (this.getConfig().lazyLoad && !allKeys.length) {
11773
+ const totalChildrenCount = ((_b = (_a = this.getConfig().groupDeepMap) == null ? void 0 : _a.get(groupKeys)) == null ? void 0 : _b.totalChildrenCount) || 0;
11774
+ if (parentSelected) {
11775
+ selectedCount = totalChildrenCount;
11776
+ deselectedCount = this.deselectedMap.getAllChildrenSizeFor(groupKeys);
11777
+ if (deselectedCount === totalChildrenCount) {
11778
+ selectedCount = 0;
11779
+ }
11780
+ } else {
11781
+ deselectedCount = totalChildrenCount;
11782
+ selectedCount = this.selectedMap.getAllChildrenSizeFor(groupKeys);
11783
+ if (selectedCount === totalChildrenCount) {
11784
+ deselectedCount = 0;
11785
+ }
11786
+ }
11787
+ }
11788
+ allKeys.forEach((keys) => {
11789
+ let isSelected = this.selectedMap.get(keys);
11790
+ let isDeselected = this.deselectedMap.get(keys);
11791
+ const selected = isSelected ? true : isDeselected ? false : parentSelected;
11792
+ const { selectedCount: selCount, deselectedCount: deselCount } = this.getSelectionCountFor(keys, selected);
11793
+ selectedCount += selCount;
11794
+ deselectedCount += deselCount;
11795
+ });
11796
+ const result = {
11797
+ selectedCount,
11798
+ deselectedCount
11799
+ };
11800
+ this.selectionCountCache.set(groupKeys, result);
11801
+ return result;
11802
+ }
11803
+ };
11804
+
11805
+ // src/components/DataSource/CellSelectionState.ts
11806
+ var debug3 = dbg("CellSelectionState");
11807
+ var WILDCARD = "*";
11808
+ var CellSelectionState = class {
11809
+ constructor(clone) {
11810
+ this.wildcard = WILDCARD;
11811
+ this.cache = new DeepMap();
11812
+ this.selectedRowsToColumns = /* @__PURE__ */ new Map();
11813
+ this.selectedColumnsToRows = /* @__PURE__ */ new Map();
11814
+ this.deselectedRowsToColumns = /* @__PURE__ */ new Map();
11815
+ this.deselectedColumnsToRows = /* @__PURE__ */ new Map();
11816
+ this.defaultSelection = false;
11817
+ this.deselectAll = () => {
11818
+ this.update({
11819
+ defaultSelection: false,
11820
+ selectedCells: []
11821
+ });
11822
+ };
11823
+ this.selectAll = () => {
11824
+ this.update({
11825
+ defaultSelection: true,
11826
+ deselectedCells: []
11827
+ });
11828
+ };
11829
+ const stateObject = clone && clone instanceof Object.getPrototypeOf(this).constructor ? clone.getState() : clone;
11830
+ if (stateObject) {
11831
+ this.update(stateObject);
11832
+ }
11833
+ }
11834
+ selectCell(rowId, colId) {
11835
+ this.setCellSelected(rowId, colId, true);
11836
+ }
11837
+ deselectCell(rowId, colId) {
11838
+ this.setCellSelected(rowId, colId, false);
11839
+ }
11840
+ selectColumn(colId) {
11841
+ this.setCellSelected(this.wildcard, colId, true);
11842
+ }
11843
+ deselectColumn(colId) {
11844
+ this.setCellSelected(this.wildcard, colId, false);
12230
11845
  }
12231
11846
  setCellSelected(rowId, colId, selected) {
12232
11847
  const wildcardRow = rowId === this.wildcard;
@@ -12531,493 +12146,1038 @@ var CellSelectionState = class {
12531
12146
  }
12532
12147
  };
12533
12148
 
12534
- // src/components/DataSource/RowSelectionState.ts
12535
- var RowSelectionState = class {
12536
- constructor(state, getConfig, _forTestingOnly) {
12537
- this.selectedRows = null;
12538
- this.deselectedRows = null;
12539
- this.defaultSelection = false;
12540
- this.selectedMap = new DeepMap();
12541
- this.deselectedMap = new DeepMap();
12542
- this.onlyUsePrimaryKeys = false;
12543
- // TODO make it easy to share the cache with another instance
12544
- this.selectionCache = new DeepMap();
12545
- this.selectionCountCache = new DeepMap();
12546
- this.mapSet = (name, key) => {
12547
- if (!Array.isArray(key)) {
12548
- if (this.onlyUsePrimaryKeys) {
12549
- key = [key];
12550
- } else {
12551
- key = [...this.getGroupKeysForPrimaryKey(key), key];
12552
- }
12149
+ // src/utils/logger.ts
12150
+ var log = debug("InfiniteTable");
12151
+ var COLOR_WARN_VALUE = `#eb9316`;
12152
+ var warnChannel = "Warn";
12153
+ var errorChannel = "Error";
12154
+ var infoChannel = "Info";
12155
+ var successChannel = "Success";
12156
+ var logChannel = "Logs";
12157
+ var logger = log.extend(logChannel);
12158
+ var infoLogger = logger.extend(infoChannel);
12159
+ var warnLogger = logger.extend(warnChannel);
12160
+ var errorLogger = logger.extend(errorChannel);
12161
+ var successLogger = logger.extend(successChannel);
12162
+ var logColorWarn = COLOR_WARN_VALUE;
12163
+ var warn = (message, logger3) => {
12164
+ logger3 = logger3 ? logger3.extend(warnChannel) : warnLogger;
12165
+ logger3(log.color(logColorWarn, message));
12166
+ };
12167
+ var doOnceFlags = new DeepMap();
12168
+ var doOnce = (func, ...keys) => {
12169
+ if (doOnceFlags.has(keys)) {
12170
+ return;
12171
+ }
12172
+ doOnceFlags.set(keys, true);
12173
+ func();
12174
+ };
12175
+ var warnOnce = (message, key = message, logger3) => {
12176
+ doOnce(() => warn(message, logger3), key, "warn");
12177
+ };
12178
+
12179
+ // src/components/InfiniteTable/api/getRowSelectionApi.ts
12180
+ function cloneRowSelection(rowSelection, stateOrGetDataSourceState) {
12181
+ return new RowSelectionState(
12182
+ rowSelection,
12183
+ rowSelectionStateConfigGetter(stateOrGetDataSourceState)
12184
+ );
12185
+ }
12186
+ function rowSelectionStateConfigGetter(stateOrStateGetter) {
12187
+ return () => {
12188
+ const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
12189
+ return {
12190
+ lazyLoad: !!state.lazyLoad,
12191
+ toPrimaryKey: state.toPrimaryKey,
12192
+ onlyUsePrimaryKeys: !state.useGroupKeysForMultiRowSelection,
12193
+ groupBy: state.groupBy,
12194
+ groupDeepMap: state.groupDeepMap,
12195
+ indexer: state.indexer,
12196
+ totalCount: state.unfilteredCount
12197
+ };
12198
+ };
12199
+ }
12200
+ function getRowSelectionApi(param) {
12201
+ const {
12202
+ // getComputed,
12203
+ // getState,
12204
+ getDataSourceState,
12205
+ // componentActions,
12206
+ dataSourceActions
12207
+ } = param;
12208
+ const rowSelectionApi = {
12209
+ get allRowsSelected() {
12210
+ return getDataSourceState().allRowsSelected;
12211
+ },
12212
+ selectAll() {
12213
+ const { rowSelection, selectionMode } = getDataSourceState();
12214
+ if (selectionMode !== "multi-row") {
12215
+ throw "Selection mode is not multi-row";
12553
12216
  }
12554
- this.xcache();
12555
- if (name === "selected") {
12556
- this.selectedMap.set(key, true);
12557
- } else {
12558
- this.deselectedMap.set(key, true);
12217
+ if (!(rowSelection instanceof RowSelectionState)) {
12218
+ throw "Invalid row selection";
12559
12219
  }
12560
- };
12561
- this._selectedMapSet = (key) => {
12562
- this.mapSet("selected", key);
12563
- };
12564
- this._deselectedMapSet = (key) => {
12565
- this.mapSet("deselected", key);
12566
- };
12567
- const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? (
12568
- //@ts-ignore
12569
- state.getState()
12570
- ) : state;
12571
- this.getConfig = getConfig;
12572
- this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
12573
- if (_forTestingOnly) {
12574
- Object.assign(this, _forTestingOnly);
12575
- }
12576
- this.update(stateObject);
12577
- }
12578
- getGroupKeysForPrimaryKey(pk) {
12579
- const { indexer, groupBy } = this.getConfig();
12580
- const data = indexer.getDataForPrimaryKey(pk);
12581
- return data ? getGroupKeysForDataItem(data, groupBy) : [];
12582
- }
12583
- getGroupDeepMap() {
12584
- return this.getConfig().groupDeepMap;
12585
- }
12586
- getGroupCount(groupKeys) {
12587
- var _a;
12588
- if (groupKeys.length == 0) {
12589
- return this.getConfig().totalCount;
12590
- }
12591
- const groupDeepMap = this.getGroupDeepMap();
12592
- const deepMapValue = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
12593
- if (!deepMapValue) {
12594
- return 0;
12220
+ const rowSelectionState = new RowSelectionState(
12221
+ rowSelection,
12222
+ rowSelectionStateConfigGetter(getDataSourceState)
12223
+ );
12224
+ rowSelectionState.selectAll();
12225
+ dataSourceActions.rowSelection = rowSelectionState;
12226
+ },
12227
+ deselectAll() {
12228
+ const { rowSelection, selectionMode } = getDataSourceState();
12229
+ if (selectionMode !== "multi-row") {
12230
+ throw "Selection mode is not multi-row";
12231
+ }
12232
+ if (!(rowSelection instanceof RowSelectionState)) {
12233
+ throw "Invalid row selection";
12234
+ }
12235
+ const rowSelectionState = new RowSelectionState(
12236
+ rowSelection,
12237
+ rowSelectionStateConfigGetter(getDataSourceState)
12238
+ );
12239
+ rowSelectionState.deselectAll();
12240
+ dataSourceActions.rowSelection = rowSelectionState;
12241
+ },
12242
+ isRowSelected(pk, groupKeys) {
12243
+ const { rowSelection, selectionMode, indexer, groupBy } = getDataSourceState();
12244
+ if (selectionMode === "single-row") {
12245
+ return rowSelection === pk;
12246
+ }
12247
+ if (selectionMode !== "multi-row") {
12248
+ throw "Selection mode is not multi-row or single-row";
12249
+ }
12250
+ if (!(rowSelection instanceof RowSelectionState)) {
12251
+ throw "Invalid row selection";
12252
+ }
12253
+ if (!groupKeys) {
12254
+ const data = indexer.getDataForPrimaryKey(pk);
12255
+ groupKeys = data ? getGroupKeysForDataItem(data, groupBy) : [];
12256
+ }
12257
+ return rowSelection.isRowSelected(pk, groupKeys);
12258
+ },
12259
+ isRowDeselected(pk, groupKeys) {
12260
+ return !this.isRowSelected(pk, groupKeys);
12261
+ },
12262
+ selectRow(pk, groupKeys) {
12263
+ const { rowSelection, selectionMode, indexer, groupBy } = getDataSourceState();
12264
+ if (selectionMode === "single-row") {
12265
+ dataSourceActions.rowSelection = pk;
12266
+ return;
12267
+ }
12268
+ if (selectionMode !== "multi-row") {
12269
+ throw "Selection mode is not multi-row or single-row";
12270
+ }
12271
+ if (!(rowSelection instanceof RowSelectionState)) {
12272
+ throw "Invalid row selection";
12273
+ }
12274
+ if (!groupKeys) {
12275
+ const data = indexer.getDataForPrimaryKey(pk);
12276
+ groupKeys = data ? getGroupKeysForDataItem(data, groupBy) : [];
12277
+ }
12278
+ const rowSelectionState = new RowSelectionState(
12279
+ rowSelection,
12280
+ rowSelectionStateConfigGetter(getDataSourceState)
12281
+ );
12282
+ rowSelectionState.selectRow(pk, groupKeys);
12283
+ dataSourceActions.rowSelection = rowSelectionState;
12284
+ },
12285
+ deselectRow(pk, groupKeys) {
12286
+ const { selectionMode, rowSelection, indexer, groupBy } = getDataSourceState();
12287
+ if (selectionMode === "single-row") {
12288
+ dataSourceActions.rowSelection = null;
12289
+ return;
12290
+ }
12291
+ if (selectionMode !== "multi-row") {
12292
+ throw "Selection mode is not multi-row or single-row";
12293
+ }
12294
+ if (!(rowSelection instanceof RowSelectionState)) {
12295
+ throw "Invalid row selection";
12296
+ }
12297
+ if (selectionMode === "multi-row") {
12298
+ if (!groupKeys) {
12299
+ const data = indexer.getDataForPrimaryKey(pk);
12300
+ groupKeys = data ? getGroupKeysForDataItem(data, groupBy) : [];
12301
+ }
12302
+ const rowSelectionState = new RowSelectionState(
12303
+ rowSelection,
12304
+ rowSelectionStateConfigGetter(getDataSourceState)
12305
+ );
12306
+ rowSelectionState.deselectRow(pk, groupKeys);
12307
+ dataSourceActions.rowSelection = rowSelectionState;
12308
+ }
12309
+ },
12310
+ toggleRowSelection(pk, groupKeys) {
12311
+ if (this.isRowSelected(pk, groupKeys)) {
12312
+ this.deselectRow(pk, groupKeys);
12313
+ } else {
12314
+ this.selectRow(pk, groupKeys);
12315
+ }
12316
+ },
12317
+ selectGroupRow(groupKeys) {
12318
+ const { selectionMode, rowSelection, groupBy } = getDataSourceState();
12319
+ if (selectionMode !== "multi-row") {
12320
+ throw 'Selection mode should be "multi-row"';
12321
+ }
12322
+ if (!groupBy) {
12323
+ throw "No grouping specified";
12324
+ }
12325
+ if (!(rowSelection instanceof RowSelectionState)) {
12326
+ throw "Invalid row selection";
12327
+ }
12328
+ const rowSelectionState = new RowSelectionState(
12329
+ rowSelection,
12330
+ rowSelectionStateConfigGetter(getDataSourceState)
12331
+ );
12332
+ rowSelectionState.selectGroupRow(groupKeys);
12333
+ dataSourceActions.rowSelection = rowSelectionState;
12334
+ },
12335
+ deselectGroupRow(groupKeys) {
12336
+ const { selectionMode, rowSelection, groupBy } = getDataSourceState();
12337
+ if (selectionMode !== "multi-row") {
12338
+ throw 'Selection mode should be "multi-row"';
12339
+ }
12340
+ if (!groupBy) {
12341
+ throw "No grouping specified";
12342
+ }
12343
+ if (!(rowSelection instanceof RowSelectionState)) {
12344
+ throw "Invalid row selection";
12345
+ }
12346
+ const rowSelectionState = new RowSelectionState(
12347
+ rowSelection,
12348
+ rowSelectionStateConfigGetter(getDataSourceState)
12349
+ );
12350
+ rowSelectionState.deselectGroupRow(groupKeys);
12351
+ dataSourceActions.rowSelection = rowSelectionState;
12352
+ },
12353
+ toggleGroupRowSelection(groupKeys) {
12354
+ const { selectionMode, rowSelection, groupBy } = getDataSourceState();
12355
+ if (selectionMode !== "multi-row") {
12356
+ throw 'Selection mode should be "multi-row"';
12357
+ }
12358
+ if (!groupBy) {
12359
+ throw "No grouping specified";
12360
+ }
12361
+ if (!(rowSelection instanceof RowSelectionState)) {
12362
+ throw "Invalid row selection";
12363
+ }
12364
+ const rowSelectionState = new RowSelectionState(
12365
+ rowSelection,
12366
+ rowSelectionStateConfigGetter(getDataSourceState)
12367
+ );
12368
+ rowSelectionState.toggleGroupRowSelection(groupKeys);
12369
+ dataSourceActions.rowSelection = rowSelectionState;
12370
+ },
12371
+ getGroupRowSelectionState(groupKeys, rowSelection) {
12372
+ const state = getDataSourceState();
12373
+ const { selectionMode, groupBy } = state;
12374
+ const rowSelectionState = rowSelection ? new RowSelectionState(
12375
+ rowSelection,
12376
+ rowSelectionStateConfigGetter(state)
12377
+ ) : state.rowSelection;
12378
+ if (selectionMode !== "multi-row") {
12379
+ throw 'Selection mode should be "multi-row"';
12380
+ }
12381
+ if (!groupBy) {
12382
+ throw "No grouping specified";
12383
+ }
12384
+ if (!(rowSelectionState instanceof RowSelectionState)) {
12385
+ throw "Invalid row selection";
12386
+ }
12387
+ return rowSelectionState.getGroupRowSelectionState(groupKeys);
12388
+ },
12389
+ getSelectedPrimaryKeys: (rowSelection) => {
12390
+ const state = getDataSourceState();
12391
+ const rowSelectionState = rowSelection ? new RowSelectionState(
12392
+ rowSelection,
12393
+ rowSelectionStateConfigGetter(state)
12394
+ ) : state.rowSelection;
12395
+ const selected = [];
12396
+ if (state.lazyLoad) {
12397
+ console.error(
12398
+ `getSelectedPrimaryKeys should not be called for lazy-loaded datasources as it wont return reliable results`
12399
+ );
12400
+ }
12401
+ state.originalDataArray.forEach((data) => {
12402
+ const id = state.toPrimaryKey(data);
12403
+ if (rowSelectionState.isRowSelected(id)) {
12404
+ selected.push(id);
12405
+ }
12406
+ });
12407
+ return selected;
12595
12408
  }
12596
- return (_a = deepMapValue.totalChildrenCount) != null ? _a : deepMapValue.items.length || 0;
12597
- }
12598
- getGroupKeysDirectlyInsideGroup(groupKeys) {
12599
- const { groupDeepMap } = this.getConfig();
12600
- return (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith(groupKeys, true, 1)) || [];
12409
+ };
12410
+ if (false) {
12411
+ globalThis.rowSelectionApi = rowSelectionApi;
12601
12412
  }
12602
- getAllPrimaryKeysInsideGroup(groupKeys) {
12603
- const { groupDeepMap } = this.getConfig();
12604
- if (!groupKeys.length) {
12605
- const topLevelKeys = (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith([], true, 1)) || [];
12606
- return topLevelKeys.map((groupKeys2) => this.getAllPrimaryKeysInsideGroup(groupKeys2)).flat();
12413
+ return rowSelectionApi;
12414
+ }
12415
+
12416
+ // src/components/utils/discardCallsWithEqualArg.ts
12417
+ var map = /* @__PURE__ */ new WeakMap();
12418
+ var getCompareDefault = (a) => a;
12419
+ function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject) {
12420
+ map.set(fn, {
12421
+ lastCallTime: 0,
12422
+ lastCallArg: null
12423
+ });
12424
+ const getCompare = getCompareObject != null ? getCompareObject : getCompareDefault;
12425
+ return (arg) => {
12426
+ const { lastCallTime, lastCallArg } = map.get(fn) || {
12427
+ lastCallTime: 0,
12428
+ lastCallArg: null
12429
+ };
12430
+ const now = Date.now();
12431
+ const diff = now - lastCallTime;
12432
+ const objectsEqual = shallowEqualObjects(
12433
+ getCompare(lastCallArg),
12434
+ getCompare(arg)
12435
+ );
12436
+ if (diff < timeframe && objectsEqual) {
12437
+ return;
12607
12438
  }
12608
- const group2 = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
12609
- return group2 ? group2.items.map(this.getConfig().toPrimaryKey) : [];
12610
- }
12611
- getGroupByLength() {
12612
- return this.getConfig().groupBy.length;
12613
- }
12614
- static from(rowSeleStateObject, getConfig, overrides) {
12615
- return new RowSelectionState(rowSeleStateObject, getConfig, overrides);
12616
- }
12617
- update(stateObject) {
12618
- var _a, _b;
12619
- this.selectedRows = stateObject.selectedRows || null;
12620
- this.deselectedRows = stateObject.deselectedRows || null;
12621
- this.selectedMap.clear();
12622
- this.deselectedMap.clear();
12623
- (_a = this.selectedRows) == null ? void 0 : _a.forEach(this._selectedMapSet);
12624
- (_b = this.deselectedRows) == null ? void 0 : _b.forEach(this._deselectedMapSet);
12625
- this.defaultSelection = stateObject.defaultSelection;
12626
- this.xcache();
12627
- }
12628
- xcache() {
12629
- this.selectionCache.clear();
12630
- this.selectionCountCache.clear();
12631
- }
12632
- getState() {
12633
- const normalize = (allKeys) => {
12634
- const groupByLength = this.getGroupByLength();
12635
- return allKeys.map((keys) => {
12636
- if (this.onlyUsePrimaryKeys) {
12637
- return keys[0];
12638
- }
12639
- return keys.length > groupByLength ? keys.pop() : keys;
12640
- });
12439
+ map.set(fn, {
12440
+ lastCallTime: now,
12441
+ lastCallArg: arg
12442
+ });
12443
+ fn(arg);
12444
+ };
12445
+ }
12446
+
12447
+ // src/components/DataSource/Indexer.ts
12448
+ var Indexer = class {
12449
+ constructor() {
12450
+ this.primaryKeyToData = /* @__PURE__ */ new Map();
12451
+ this.add = (primaryKey, data) => {
12452
+ this.primaryKeyToData.set(primaryKey, data);
12641
12453
  };
12642
- const selectedRows = normalize(this.selectedMap.topDownKeys());
12643
- const deselectedRows = normalize(this.deselectedMap.topDownKeys());
12644
- return {
12645
- defaultSelection: this.defaultSelection,
12646
- selectedRows,
12647
- deselectedRows
12454
+ this.clear = () => {
12455
+ this.primaryKeyToData.clear();
12648
12456
  };
12649
- }
12650
- deselectAll() {
12651
- this.update({
12652
- defaultSelection: false,
12653
- selectedRows: [],
12654
- deselectedRows: []
12655
- });
12656
- }
12657
- selectAll() {
12658
- this.update({
12659
- defaultSelection: true,
12660
- deselectedRows: [],
12661
- selectedRows: []
12662
- });
12663
- }
12664
- isRowDefaultSelected() {
12665
- return this.defaultSelection === true;
12666
- }
12667
- isRowDefaultDeselected() {
12668
- return this.defaultSelection === false;
12669
- }
12670
- /**
12671
- *
12672
- * @param key the id of the row - if a row in a grouped datasource, this is the final row id, without the group keys
12673
- * @param groupKeys the keys of row parents, in order
12674
- * @returns Whether the row is selected or not.
12675
- */
12676
- isRowSelected(key, groupKeys) {
12677
- if (this.onlyUsePrimaryKeys) {
12678
- return this.defaultSelection ? !this.deselectedMap.has([key]) : this.selectedMap.has([key]);
12679
- }
12680
- groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
12681
- const finalKey = [...groupKeys, key];
12682
- const cachedResult = this.selectionCache.get(finalKey);
12683
- if (cachedResult !== void 0) {
12684
- return cachedResult;
12685
- }
12686
- const inSelected = this.selectedMap.has(finalKey);
12687
- const inDeselected = this.deselectedMap.has(finalKey);
12688
- if (inSelected) {
12689
- this.selectionCache.set(finalKey, true);
12690
- return true;
12691
- }
12692
- if (inDeselected) {
12693
- this.selectionCache.set(finalKey, false);
12694
- return false;
12695
- }
12696
- if (this.selectedMap.has(groupKeys)) {
12697
- this.selectionCache.set(finalKey, true);
12698
- return true;
12699
- }
12700
- if (this.deselectedMap.has(groupKeys)) {
12701
- this.selectionCache.set(finalKey, false);
12702
- return false;
12703
- }
12704
- groupKeys = [...groupKeys];
12705
- while (groupKeys.length) {
12706
- groupKeys.pop();
12707
- const inSelected2 = this.selectedMap.has(groupKeys);
12708
- const inDeselected2 = this.deselectedMap.has(groupKeys);
12709
- if (inSelected2) {
12710
- this.selectionCache.set(finalKey, true);
12711
- return true;
12457
+ this.getDataForPrimaryKey = (primaryKey) => {
12458
+ return this.primaryKeyToData.get(primaryKey);
12459
+ };
12460
+ this.indexArray = (arr, options) => {
12461
+ const { cache, toPrimaryKey } = options;
12462
+ if (cache && !cache.isEmpty()) {
12463
+ arr = arr.concat();
12712
12464
  }
12713
- if (inDeselected2) {
12714
- this.selectionCache.set(finalKey, false);
12715
- return false;
12465
+ if (!arr.length && cache) {
12466
+ const cacheInfo = [...cache.getMutations().values()].flatMap((x) => x);
12467
+ if (cacheInfo && cacheInfo.length) {
12468
+ for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
12469
+ const info = cacheInfo[cacheIndex];
12470
+ if (info.type === "insert") {
12471
+ const insertPK = toPrimaryKey(info.data);
12472
+ this.add(insertPK, info.data);
12473
+ arr.push(info.data);
12474
+ }
12475
+ }
12476
+ cache == null ? void 0 : cache.removeInfo(void 0);
12477
+ }
12478
+ } else {
12479
+ for (let i = 0; i < arr.length; i++) {
12480
+ let item = arr[i];
12481
+ let deleted = false;
12482
+ if (item != null) {
12483
+ const pk = toPrimaryKey(item);
12484
+ const cacheInfo = cache == null ? void 0 : cache.getMutationsForPrimaryKey(pk);
12485
+ if (cacheInfo && cacheInfo.length) {
12486
+ for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
12487
+ const info = cacheInfo[cacheIndex];
12488
+ if (info.type === "delete" && !deleted) {
12489
+ this.primaryKeyToData.delete(pk);
12490
+ deleted = true;
12491
+ arr.splice(i, 1);
12492
+ }
12493
+ if (info.type === "update" && !deleted) {
12494
+ item = __spreadValues(__spreadValues({}, item), info.data);
12495
+ arr[i] = item;
12496
+ }
12497
+ if (info.type === "insert") {
12498
+ const insertPK = toPrimaryKey(info.data);
12499
+ this.add(insertPK, info.data);
12500
+ if (info.position === "before") {
12501
+ arr.splice(i, 0, info.data);
12502
+ i--;
12503
+ } else {
12504
+ arr.splice(i + 1, 0, info.data);
12505
+ }
12506
+ }
12507
+ }
12508
+ cache == null ? void 0 : cache.removeInfo(pk);
12509
+ }
12510
+ if (!deleted) {
12511
+ this.add(pk, item);
12512
+ }
12513
+ }
12514
+ }
12515
+ }
12516
+ return arr;
12517
+ };
12518
+ }
12519
+ };
12520
+
12521
+ // src/components/DataSource/privateHooks/useLoadData.ts
12522
+ var import_react35 = require("react");
12523
+
12524
+ // src/components/hooks/useEffectWithChanges.ts
12525
+ var import_react34 = require("react");
12526
+ function useEffectWithChanges(fn, deps) {
12527
+ const prevRef = (0, import_react34.useRef)({});
12528
+ const oldValuesRef = (0, import_react34.useRef)({});
12529
+ const oldValues = oldValuesRef.current;
12530
+ const changesRef = (0, import_react34.useRef)({});
12531
+ const changes = changesRef.current;
12532
+ const useEffectDeps = [];
12533
+ for (const k in deps) {
12534
+ if (deps.hasOwnProperty(k)) {
12535
+ if (deps[k] !== prevRef.current[k]) {
12536
+ changes[k] = deps[k];
12537
+ oldValues[k] = prevRef.current[k];
12716
12538
  }
12539
+ useEffectDeps.push(deps[k]);
12717
12540
  }
12718
- this.selectionCache.set(finalKey, this.defaultSelection);
12719
- return this.defaultSelection;
12720
12541
  }
12721
- isRowDeselected(key, groupKeys) {
12722
- return !this.isRowSelected(key, groupKeys);
12542
+ prevRef.current = deps;
12543
+ (0, import_react34.useEffect)(() => {
12544
+ const changes2 = changesRef.current;
12545
+ let result = void 0;
12546
+ if (Object.keys(changes2).length !== 0) {
12547
+ result = fn(changes2, oldValues);
12548
+ }
12549
+ changesRef.current = {};
12550
+ oldValuesRef.current = {};
12551
+ return result;
12552
+ }, useEffectDeps);
12553
+ }
12554
+ function useEffectWithObject(fn, deps) {
12555
+ const useEffectDeps = [];
12556
+ for (const k in deps) {
12557
+ if (deps.hasOwnProperty(k)) {
12558
+ useEffectDeps.push(deps[k]);
12559
+ }
12723
12560
  }
12724
- setRowSelected(key, selected, groupKeys) {
12725
- if (selected) {
12726
- this.setRowAsSelected(key, groupKeys);
12561
+ (0, import_react34.useEffect)(fn, useEffectDeps);
12562
+ }
12563
+
12564
+ // src/utils/composeFunctions.ts
12565
+ function composeFunctions(...fns) {
12566
+ const f = (...args) => {
12567
+ fns.forEach((fn) => {
12568
+ if (typeof fn === "function") {
12569
+ fn(...args);
12570
+ }
12571
+ });
12572
+ };
12573
+ return f;
12574
+ }
12575
+
12576
+ // src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts
12577
+ function prepareColumn(column) {
12578
+ const { pivotByAtIndex: pivotByForColumn, pivotAggregator } = column;
12579
+ if (pivotByForColumn == null ? void 0 : pivotByForColumn.column) {
12580
+ if (typeof pivotByForColumn.column === "function") {
12581
+ Object.assign(column, pivotByForColumn.column({ column }));
12727
12582
  } else {
12728
- this.setRowAsDeselected(key, groupKeys);
12583
+ Object.assign(column, pivotByForColumn.column);
12729
12584
  }
12730
12585
  }
12731
- /**
12732
- * Returns if the selection state ('full','partial','none') for the current group
12733
- *
12734
- * The selection state will be full (true) if either of those are true:
12735
- * * the group keys are specified as selected
12736
- * * all the children are specified as selected
12737
- *
12738
- * The selection state will be partial (null) if either of those are true:
12739
- * * the group keys are partially selected
12740
- * * some of the children are specified as selected
12741
- *
12742
- *
12743
- * @param groupKeys the keys of the group row
12744
- * @param children leaf children that belong to the group
12745
- * @returns boolean
12746
- */
12747
- getGroupRowSelectionState(initialGroupKeys) {
12748
- const cachedResult = this.selectionCache.get(initialGroupKeys);
12749
- if (cachedResult !== void 0) {
12750
- return cachedResult;
12586
+ if (pivotAggregator == null ? void 0 : pivotAggregator.pivotColumn) {
12587
+ if (typeof pivotAggregator.pivotColumn === "function") {
12588
+ Object.assign(column, pivotAggregator.pivotColumn({ column }));
12589
+ } else {
12590
+ Object.assign(column, pivotAggregator.pivotColumn);
12751
12591
  }
12752
- const { selectedCount, deselectedCount } = this.getSelectionCountFor(
12753
- initialGroupKeys,
12754
- this.onlyUsePrimaryKeys ? (
12755
- // there is no need for the state from the parent group
12756
- // when we are in this case, so don't do that
12757
- void 0
12758
- ) : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys)
12759
- );
12760
- const result = selectedCount && deselectedCount ? null : selectedCount ? true : false;
12761
- this.selectionCache.set(initialGroupKeys, result);
12762
- return result;
12763
12592
  }
12764
- getGroupRowBooleanSelectionStateFromParent(initialGroupKeys) {
12765
- if (!initialGroupKeys.length) {
12766
- return this.defaultSelection;
12593
+ return column;
12594
+ }
12595
+ function prepareColumnGroup(columnGroup) {
12596
+ const { pivotByAtIndex: pivotByForColumnGroup } = columnGroup;
12597
+ if (pivotByForColumnGroup == null ? void 0 : pivotByForColumnGroup.columnGroup) {
12598
+ if (typeof pivotByForColumnGroup.columnGroup === "function") {
12599
+ Object.assign(
12600
+ columnGroup,
12601
+ pivotByForColumnGroup.columnGroup({ columnGroup })
12602
+ );
12603
+ } else {
12604
+ Object.assign(columnGroup, pivotByForColumnGroup.columnGroup);
12767
12605
  }
12768
- const groupKeys = [...initialGroupKeys];
12769
- const selfDeselected = this.deselectedMap.has(groupKeys);
12770
- const selfSelected = this.selectedMap.has(groupKeys);
12771
- let selectionState = selfSelected && !selfDeselected ? true : selfDeselected && !selfSelected ? false : void 0;
12772
- if (selectionState === void 0) {
12773
- while (groupKeys.length) {
12774
- groupKeys.pop();
12775
- if (this.deselectedMap.has(groupKeys)) {
12776
- selectionState = false;
12777
- break;
12606
+ }
12607
+ return columnGroup;
12608
+ }
12609
+ function getPivotColumnsAndColumnGroups({
12610
+ deepMap,
12611
+ pivotBy,
12612
+ pivotTotalColumnPosition,
12613
+ pivotGrandTotalColumnPosition,
12614
+ reducers = {},
12615
+ showSeparatePivotColumnForSingleAggregation = false
12616
+ }) {
12617
+ const pivotLength = pivotBy.length;
12618
+ const aggregationReducers = Object.keys(
12619
+ reducers
12620
+ ).map((key) => {
12621
+ return __spreadProps(__spreadValues({}, reducers[key]), { id: key });
12622
+ });
12623
+ if (!aggregationReducers.length) {
12624
+ showSeparatePivotColumnForSingleAggregation = true;
12625
+ pivotGrandTotalColumnPosition = false;
12626
+ pivotTotalColumnPosition = false;
12627
+ aggregationReducers.push({
12628
+ id: "__empty-aggregation-reducer__",
12629
+ name: "-",
12630
+ initialValue: null,
12631
+ reducer: () => null
12632
+ });
12633
+ }
12634
+ const columns = {};
12635
+ const columnGroups = {};
12636
+ const addGrandTotalColumns = once(function() {
12637
+ aggregationReducers.forEach((reducer, index) => {
12638
+ columns[`total:${reducer.id}`] = prepareColumn({
12639
+ header: `${reducer.name || reducer.id} total`,
12640
+ pivotBy,
12641
+ pivotColumn: true,
12642
+ pivotTotalColumn: true,
12643
+ pivotAggregator: reducer,
12644
+ pivotAggregatorIndex: index,
12645
+ pivotGroupKeys: [],
12646
+ pivotGroupKey: "",
12647
+ pivotIndex: -1,
12648
+ valueFormatter: ({ rowInfo }) => {
12649
+ var _a;
12650
+ return rowInfo.isGroupRow ? (_a = rowInfo.reducerResults) == null ? void 0 : _a[reducer.id] : null;
12778
12651
  }
12779
- if (this.selectedMap.has(groupKeys)) {
12780
- selectionState = true;
12781
- break;
12652
+ });
12653
+ });
12654
+ });
12655
+ if (!pivotLength && pivotTotalColumnPosition === "start" || pivotGrandTotalColumnPosition === "start") {
12656
+ addGrandTotalColumns();
12657
+ }
12658
+ const isSingleAggregationColumn = !showSeparatePivotColumnForSingleAggregation && aggregationReducers.length === 1;
12659
+ deepMap.visitDepthFirst((_value, keys, _indexInGroup, next) => {
12660
+ keys = [...keys];
12661
+ if (pivotTotalColumnPosition === "end") {
12662
+ next == null ? void 0 : next();
12663
+ }
12664
+ if (keys.length === pivotLength) {
12665
+ const pivotByForColumn = pivotBy[keys.length - 1];
12666
+ const parentKeys = keys.slice(0, -1);
12667
+ let parentColumnGroupId = parentKeys.join("/");
12668
+ if (!isSingleAggregationColumn) {
12669
+ const columnGroupId = parentColumnGroupId;
12670
+ parentColumnGroupId = keys.join("/");
12671
+ const pivotGroupKey = keys[keys.length - 1];
12672
+ columnGroups[parentColumnGroupId] = prepareColumnGroup({
12673
+ header: `${pivotGroupKey}`,
12674
+ columnGroup: columnGroupId,
12675
+ pivotBy,
12676
+ pivotGroupKeys: keys,
12677
+ pivotByAtIndex: pivotByForColumn,
12678
+ pivotIndex: keys.length - 1,
12679
+ pivotGroupKey
12680
+ });
12681
+ }
12682
+ aggregationReducers.forEach((reducer, index) => {
12683
+ const header = isSingleAggregationColumn ? `${keys[keys.length - 1]}` : reducer.name || reducer.id;
12684
+ const computedPivotColumn = prepareColumn({
12685
+ pivotBy,
12686
+ pivotColumn: true,
12687
+ pivotTotalColumn: false,
12688
+ pivotAggregator: reducer,
12689
+ pivotAggregatorIndex: index,
12690
+ pivotGroupKeys: keys,
12691
+ pivotGroupKey: keys[keys.length - 1],
12692
+ pivotIndex: keys.length - 1,
12693
+ pivotByAtIndex: pivotByForColumn,
12694
+ defaultSortable: false,
12695
+ columnGroup: parentColumnGroupId,
12696
+ header,
12697
+ valueFormatter: ({ rowInfo }) => {
12698
+ var _a, _b;
12699
+ if (!rowInfo.isGroupRow) {
12700
+ return null;
12701
+ }
12702
+ return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
12703
+ }
12704
+ });
12705
+ const columnId = `${reducer.id}:${keys.join("/")}`;
12706
+ columns[columnId] = computedPivotColumn;
12707
+ });
12708
+ } else {
12709
+ const colGroupId = keys.join("/");
12710
+ const parentKeys = keys.slice(0, -1);
12711
+ columnGroups[colGroupId] = prepareColumnGroup({
12712
+ columnGroup: parentKeys.length ? parentKeys.join("/") : void 0,
12713
+ header: `${keys[keys.length - 1]}`,
12714
+ pivotBy,
12715
+ pivotGroupKeys: keys,
12716
+ pivotIndex: keys.length - 1,
12717
+ pivotByAtIndex: pivotBy[keys.length - 1],
12718
+ pivotGroupKey: keys[keys.length - 1]
12719
+ });
12720
+ if (pivotTotalColumnPosition !== false) {
12721
+ const pivotByForColumn = pivotBy[keys.length - 1];
12722
+ let columnGroupId = parentKeys.length ? parentKeys.join("/") : void 0;
12723
+ if (!isSingleAggregationColumn) {
12724
+ const parentGroupForTotalsGroup = columnGroupId;
12725
+ columnGroupId = `total:${keys.join("/")}`;
12726
+ columnGroups[columnGroupId] = prepareColumnGroup({
12727
+ header: `${keys[keys.length - 1]} total`,
12728
+ columnGroup: parentGroupForTotalsGroup,
12729
+ pivotBy,
12730
+ pivotTotalColumnGroup: true,
12731
+ pivotGroupKeys: keys,
12732
+ pivotIndex: keys.length - 1,
12733
+ pivotByAtIndex: pivotByForColumn,
12734
+ pivotGroupKey: keys[keys.length - 1]
12735
+ });
12782
12736
  }
12737
+ aggregationReducers.forEach((reducer, index) => {
12738
+ const header = isSingleAggregationColumn ? `${keys[keys.length - 1]} total ` : `${reducer.name || reducer.id} total`;
12739
+ const computedPivotColumn = prepareColumn({
12740
+ columnGroup: columnGroupId,
12741
+ header,
12742
+ pivotAggregator: reducer,
12743
+ pivotAggregatorIndex: index,
12744
+ pivotColumn: true,
12745
+ pivotTotalColumn: true,
12746
+ pivotGroupKeys: keys,
12747
+ pivotGroupKey: keys[keys.length - 1],
12748
+ pivotByAtIndex: pivotByForColumn,
12749
+ pivotIndex: keys.length - 1,
12750
+ pivotBy,
12751
+ defaultSortable: false,
12752
+ valueFormatter: ({ rowInfo }) => {
12753
+ var _a, _b;
12754
+ if (!rowInfo.isGroupRow) {
12755
+ return null;
12756
+ }
12757
+ return (_b = (_a = rowInfo.pivotValuesMap) == null ? void 0 : _a.get(keys)) == null ? void 0 : _b.reducerResults[reducer.id];
12758
+ }
12759
+ });
12760
+ columns[`total:${reducer.id}:${keys.join("/")}`] = computedPivotColumn;
12761
+ });
12783
12762
  }
12784
12763
  }
12785
- if (selectionState === void 0) {
12786
- selectionState = this.defaultSelection;
12764
+ if (pivotTotalColumnPosition === "start" || pivotTotalColumnPosition === false) {
12765
+ next == null ? void 0 : next();
12787
12766
  }
12788
- return selectionState;
12789
- }
12790
- isGroupRowPartlySelected(groupKeys) {
12791
- return this.getGroupRowSelectionState(groupKeys) === null;
12767
+ });
12768
+ if (!pivotLength && pivotTotalColumnPosition === "end" || pivotGrandTotalColumnPosition === "end") {
12769
+ addGrandTotalColumns();
12792
12770
  }
12793
- isGroupRowSelected(groupKeys) {
12794
- return this.getGroupRowSelectionState(groupKeys) === true;
12771
+ const result = {
12772
+ columns,
12773
+ columnGroups
12774
+ };
12775
+ return result;
12776
+ }
12777
+
12778
+ // src/components/DataSource/DataSourceCache.ts
12779
+ var DataSourceCache = class {
12780
+ constructor() {
12781
+ this.affectedFields = /* @__PURE__ */ new Set();
12782
+ this.allFieldsAffected = false;
12783
+ this.primaryKeyToData = /* @__PURE__ */ new Map();
12784
+ this.getAffectedFields = () => {
12785
+ if (this.allFieldsAffected) {
12786
+ return true;
12787
+ }
12788
+ return this.affectedFields;
12789
+ };
12790
+ this.delete = (primaryKey, originalData, metadata) => {
12791
+ this.allFieldsAffected = true;
12792
+ const pk = primaryKey;
12793
+ const value = this.primaryKeyToData.get(pk) || [];
12794
+ value.push({
12795
+ type: "delete",
12796
+ primaryKey,
12797
+ originalData,
12798
+ metadata
12799
+ });
12800
+ this.primaryKeyToData.set(pk, value);
12801
+ };
12802
+ this.insert = (primaryKey, data, position2, metadata) => {
12803
+ const pk = primaryKey;
12804
+ const value = this.primaryKeyToData.get(pk) || [];
12805
+ this.allFieldsAffected = true;
12806
+ value.push({
12807
+ type: "insert",
12808
+ primaryKey,
12809
+ data,
12810
+ position: position2,
12811
+ originalData: null,
12812
+ metadata
12813
+ });
12814
+ this.primaryKeyToData.set(pk, value);
12815
+ };
12816
+ this.update = (primaryKey, data, originalData, metadata) => {
12817
+ if (!this.allFieldsAffected) {
12818
+ const keys = Object.keys(data);
12819
+ keys.forEach((key) => this.affectedFields.add(key));
12820
+ }
12821
+ const pk = primaryKey;
12822
+ const value = this.primaryKeyToData.get(pk) || [];
12823
+ value.push({
12824
+ type: "update",
12825
+ primaryKey,
12826
+ data,
12827
+ originalData,
12828
+ metadata
12829
+ });
12830
+ this.primaryKeyToData.set(primaryKey, value);
12831
+ };
12832
+ this.clear = () => {
12833
+ this.allFieldsAffected = false;
12834
+ this.affectedFields.clear();
12835
+ this.primaryKeyToData.clear();
12836
+ };
12837
+ this.isEmpty = () => {
12838
+ return this.primaryKeyToData.size === 0;
12839
+ };
12840
+ this.removeInfo = (primaryKey) => {
12841
+ this.primaryKeyToData.delete(primaryKey);
12842
+ };
12843
+ this.getMutationsForPrimaryKey = (primaryKey) => {
12844
+ const data = this.primaryKeyToData.get(primaryKey);
12845
+ return data;
12846
+ };
12847
+ this.getMutations = () => {
12848
+ return new Map(this.primaryKeyToData);
12849
+ };
12795
12850
  }
12796
- isGroupRowDeselected(groupKeys) {
12797
- return this.getGroupRowSelectionState(groupKeys) === false;
12851
+ static clone(cache, { light = false } = {}) {
12852
+ const clone = new DataSourceCache();
12853
+ clone.allFieldsAffected = cache.allFieldsAffected;
12854
+ clone.affectedFields = new Set(cache.affectedFields);
12855
+ clone.primaryKeyToData = light ? cache.primaryKeyToData : new Map(
12856
+ cache.primaryKeyToData
12857
+ );
12858
+ return clone;
12798
12859
  }
12799
- selectGroupRow(groupKeys) {
12800
- if (this.onlyUsePrimaryKeys) {
12801
- const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
12802
- keys.forEach((key) => {
12803
- if (this.defaultSelection === true) {
12804
- this.deselectedMap.delete([key]);
12860
+ };
12861
+
12862
+ // src/components/DataSource/dataSourceGetters.ts
12863
+ function getRowInfoAt(rowIndex, getState) {
12864
+ return getState().dataArray[rowIndex];
12865
+ }
12866
+ function getRowInfoArray(getState) {
12867
+ return getState().dataArray;
12868
+ }
12869
+
12870
+ // src/components/DataSource/getDataSourceApi.ts
12871
+ function getDataSourceApi(param) {
12872
+ return new DataSourceApiImpl(param);
12873
+ }
12874
+ var DataSourceApiImpl = class {
12875
+ constructor(param) {
12876
+ this.pendingOperations = [];
12877
+ this.pendingPromise = null;
12878
+ this.resolvePendingPromise = null;
12879
+ this.toPrimaryKey = (data) => {
12880
+ return this.getState().toPrimaryKey(data);
12881
+ };
12882
+ this.getRowInfoArray = () => {
12883
+ return getRowInfoArray(this.getState);
12884
+ };
12885
+ this.getRowInfoByIndex = (index) => {
12886
+ var _a;
12887
+ return (_a = getRowInfoAt(index, this.getState)) != null ? _a : null;
12888
+ };
12889
+ this.getRowInfoByPrimaryKey = (id) => {
12890
+ const index = this.getIndexByPrimaryKey(id);
12891
+ return this.getRowInfoByIndex(index);
12892
+ };
12893
+ this.getIndexByPrimaryKey = (id) => {
12894
+ var _a;
12895
+ const map2 = this.getState().idToIndexMap;
12896
+ return (_a = map2.get(id)) != null ? _a : -1;
12897
+ };
12898
+ this.getPrimaryKeyByIndex = (index) => {
12899
+ const rowInfo = this.getRowInfoByIndex(index);
12900
+ return rowInfo ? rowInfo.id : void 0;
12901
+ };
12902
+ this.getOriginalDataArray = () => {
12903
+ return this.getState().originalDataArray;
12904
+ };
12905
+ this.getDataByPrimaryKey = (id) => {
12906
+ var _a;
12907
+ const { indexer } = this.getState();
12908
+ return (_a = indexer.getDataForPrimaryKey(id)) != null ? _a : null;
12909
+ };
12910
+ this.updateData = (data, options) => {
12911
+ return this.updateDataArray([data], options);
12912
+ };
12913
+ this.updateDataArray = (data, options) => {
12914
+ const result = this.batchOperation({
12915
+ type: "update",
12916
+ array: data,
12917
+ primaryKeys: data.map((d) => {
12918
+ return this.toPrimaryKey(d);
12919
+ }),
12920
+ metadata: options == null ? void 0 : options.metadata
12921
+ });
12922
+ if (options == null ? void 0 : options.flush) {
12923
+ this.commit();
12924
+ }
12925
+ return result;
12926
+ };
12927
+ this.removeDataByPrimaryKey = (id, options) => {
12928
+ const result = this.batchOperation({
12929
+ type: "delete",
12930
+ primaryKeys: [id],
12931
+ metadata: options == null ? void 0 : options.metadata
12932
+ });
12933
+ if (options == null ? void 0 : options.flush) {
12934
+ this.commit();
12935
+ }
12936
+ return result;
12937
+ };
12938
+ this.removeData = (data, options) => {
12939
+ const result = this.batchOperation({
12940
+ type: "delete",
12941
+ primaryKeys: [this.toPrimaryKey(data)],
12942
+ metadata: options == null ? void 0 : options.metadata
12943
+ });
12944
+ if (options == null ? void 0 : options.flush) {
12945
+ this.commit();
12946
+ }
12947
+ return result;
12948
+ };
12949
+ this.removeDataArrayByPrimaryKeys = (ids, options) => {
12950
+ const result = this.batchOperation({
12951
+ type: "delete",
12952
+ primaryKeys: ids,
12953
+ metadata: options == null ? void 0 : options.metadata
12954
+ });
12955
+ if (options == null ? void 0 : options.flush) {
12956
+ this.commit();
12957
+ }
12958
+ return result;
12959
+ };
12960
+ this.removeDataArray = (data, options) => {
12961
+ const result = this.batchOperation({
12962
+ type: "delete",
12963
+ primaryKeys: data.map(this.toPrimaryKey),
12964
+ metadata: options == null ? void 0 : options.metadata
12965
+ });
12966
+ if (options == null ? void 0 : options.flush) {
12967
+ this.commit();
12968
+ }
12969
+ return result;
12970
+ };
12971
+ this.addData = (data, options) => {
12972
+ return this.addDataArray([data], options);
12973
+ };
12974
+ this.addDataArray = (data, options) => {
12975
+ return this.insertDataArray(data, __spreadProps(__spreadValues({}, options), {
12976
+ position: "end"
12977
+ }));
12978
+ };
12979
+ this.insertData = (data, options) => {
12980
+ return this.insertDataArray([data], options);
12981
+ };
12982
+ this.insertDataArray = (data, options) => {
12983
+ let position2 = "before";
12984
+ let primaryKey = void 0;
12985
+ if (options.position === "before" || options.position === "after") {
12986
+ position2 = options.position;
12987
+ primaryKey = options.primaryKey;
12988
+ } else {
12989
+ const arr = this.getOriginalDataArray();
12990
+ if (options.position === "start") {
12991
+ position2 = "before";
12992
+ primaryKey = !arr.length ? void 0 : this.toPrimaryKey(arr[0]);
12805
12993
  } else {
12806
- this._selectedMapSet(key);
12994
+ position2 = "after";
12995
+ primaryKey = !arr.length ? void 0 : this.toPrimaryKey(arr[arr.length - 1]);
12807
12996
  }
12997
+ }
12998
+ const result = this.batchOperation({
12999
+ type: "insert",
13000
+ array: data,
13001
+ position: position2,
13002
+ metadata: options == null ? void 0 : options.metadata,
13003
+ primaryKey
12808
13004
  });
12809
- this.xcache();
13005
+ if (options == null ? void 0 : options.flush) {
13006
+ this.commit();
13007
+ }
13008
+ return result;
13009
+ };
13010
+ this.setSortInfo = (sortInfo) => {
13011
+ const multiSort = this.getState().multiSort;
13012
+ if (Array.isArray(sortInfo)) {
13013
+ this.actions.sortInfo = sortInfo.length ? multiSort ? sortInfo : sortInfo[0] : null;
13014
+ return;
13015
+ }
13016
+ this.actions.sortInfo = sortInfo;
12810
13017
  return;
12811
- }
12812
- const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
12813
- selectedKeys.forEach((groupKeys2) => {
12814
- this.selectedMap.delete(groupKeys2);
12815
- });
12816
- if (groupKeys.length === 1 && this.defaultSelection === true) {
12817
- } else {
12818
- this._selectedMapSet(groupKeys);
12819
- }
12820
- const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
12821
- deselectedKeys.forEach((groupKeys2) => {
12822
- this.deselectedMap.delete(groupKeys2);
12823
- });
13018
+ };
13019
+ this.getState = param.getState;
13020
+ this.actions = param.actions;
12824
13021
  }
12825
- deselectGroupRow(groupKeys) {
12826
- if (this.onlyUsePrimaryKeys) {
12827
- const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
12828
- keys.forEach((key) => {
12829
- if (this.defaultSelection === false) {
12830
- this.selectedMap.delete([key]);
12831
- } else {
12832
- this._deselectedMapSet(key);
12833
- }
13022
+ batchOperation(operation) {
13023
+ if (!this.pendingPromise) {
13024
+ this.pendingPromise = new Promise((resolve) => {
13025
+ this.resolvePendingPromise = resolve;
13026
+ });
13027
+ raf(() => {
13028
+ this.commit();
12834
13029
  });
12835
- this.xcache();
12836
- return;
12837
- }
12838
- const deselectedKeys = this.deselectedMap.getKeysStartingWith(
12839
- groupKeys,
12840
- true
12841
- );
12842
- deselectedKeys.forEach((groupKeys2) => {
12843
- this.deselectedMap.delete(groupKeys2);
12844
- });
12845
- if (groupKeys.length === 1 && this.defaultSelection === false) {
12846
- } else {
12847
- this._deselectedMapSet(groupKeys);
12848
13030
  }
12849
- const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
12850
- selectedKeys.forEach((groupKeys2) => {
12851
- this.selectedMap.delete(groupKeys2);
12852
- });
13031
+ this.pendingOperations.push(operation);
13032
+ return this.pendingPromise;
12853
13033
  }
12854
- setRowAsSelected(key, groupKeys) {
12855
- if (this.onlyUsePrimaryKeys) {
12856
- if (this.defaultSelection) {
12857
- this.deselectedMap.delete([key]);
12858
- } else {
12859
- this._selectedMapSet(key);
12860
- }
12861
- this.xcache();
12862
- return;
12863
- }
12864
- groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
12865
- const finalKey = [...groupKeys, key];
12866
- this.deselectedMap.delete(finalKey);
12867
- this.xcache();
12868
- if (this.getGroupRowSelectionState(groupKeys) !== true) {
12869
- this._selectedMapSet(finalKey);
12870
- if (this.getGroupRowSelectionState(groupKeys) === true) {
12871
- this.selectGroupRow(groupKeys);
12872
- }
12873
- }
13034
+ batchOperations(operations) {
13035
+ this.pendingOperations.push(...operations);
12874
13036
  }
12875
- setRowAsDeselected(key, groupKeys) {
12876
- if (this.onlyUsePrimaryKeys) {
12877
- if (this.defaultSelection) {
12878
- this._deselectedMapSet(key);
12879
- } else {
12880
- this.selectedMap.delete([key]);
12881
- }
12882
- this.xcache();
13037
+ commitOperations(operations) {
13038
+ if (!operations.length) {
12883
13039
  return;
12884
13040
  }
12885
- groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
12886
- const finalKey = [...groupKeys, key];
12887
- this.selectedMap.delete(finalKey);
12888
- this.xcache();
12889
- if (this.getGroupRowSelectionState(groupKeys) !== false) {
12890
- this._deselectedMapSet(finalKey);
12891
- if (this.getGroupRowSelectionState(groupKeys) === false) {
12892
- this.deselectGroupRow(groupKeys);
13041
+ const currentCache = this.getState().cache;
13042
+ let cache = currentCache ? DataSourceCache.clone(currentCache, { light: true }) : new DataSourceCache();
13043
+ operations.forEach((operation) => {
13044
+ switch (operation.type) {
13045
+ case "update":
13046
+ operation.array.forEach((data, index) => {
13047
+ const key = operation.primaryKeys[index];
13048
+ const rowInfo = this.getRowInfoByPrimaryKey(key);
13049
+ if (rowInfo && !rowInfo.isGroupRow) {
13050
+ cache.update(
13051
+ operation.primaryKeys[index],
13052
+ data,
13053
+ rowInfo.data,
13054
+ operation.metadata
13055
+ );
13056
+ }
13057
+ });
13058
+ break;
13059
+ case "delete":
13060
+ operation.primaryKeys.forEach((key) => {
13061
+ const rowInfo = this.getRowInfoByPrimaryKey(key);
13062
+ if (rowInfo && !rowInfo.isGroupRow) {
13063
+ cache.delete(key, rowInfo.data, operation.metadata);
13064
+ }
13065
+ });
13066
+ break;
13067
+ case "insert":
13068
+ let pk = operation.primaryKey;
13069
+ let position2 = operation.position;
13070
+ operation.array.forEach((data) => {
13071
+ cache.insert(pk, data, position2, operation.metadata);
13072
+ pk = this.toPrimaryKey(data);
13073
+ position2 = "after";
13074
+ });
13075
+ break;
12893
13076
  }
12894
- }
12895
- }
12896
- deselectRow(key, groupKeys) {
12897
- this.setRowSelected(key, false, groupKeys);
12898
- }
12899
- selectRow(key, groupKeys) {
12900
- this.setRowSelected(key, true, groupKeys);
12901
- }
12902
- toggleGroupRowSelection(groupKeys) {
12903
- const groupRowSelectionState = this.getGroupRowSelectionState(groupKeys);
12904
- if (groupRowSelectionState === true) {
12905
- this.deselectGroupRow(groupKeys);
12906
- } else {
12907
- this.selectGroupRow(groupKeys);
12908
- }
13077
+ });
13078
+ this.actions.cache = cache;
12909
13079
  }
12910
- toggleRowSelection(key, groupKeys) {
12911
- if (this.isRowSelected(key, groupKeys)) {
12912
- this.deselectRow(key, groupKeys);
12913
- } else {
12914
- this.selectRow(key, groupKeys);
13080
+ commit() {
13081
+ this.commitOperations(this.pendingOperations);
13082
+ this.pendingOperations.length = 0;
13083
+ if (this.pendingPromise && this.resolvePendingPromise) {
13084
+ const resolve = this.resolvePendingPromise;
13085
+ requestAnimationFrame(() => {
13086
+ resolve(true);
13087
+ });
13088
+ this.pendingPromise = null;
13089
+ this.resolvePendingPromise = null;
12915
13090
  }
12916
13091
  }
12917
- getSelectedCount() {
12918
- return this.getSelectionCountFor([]).selectedCount;
12919
- }
12920
- getDeselectedCount() {
12921
- return this.getSelectionCountFor([]).deselectedCount;
12922
- }
12923
- getSelectionCountFor(groupKeys = [], parentSelected) {
12924
- var _a, _b;
12925
- const cachedResult = this.selectionCountCache.get(groupKeys);
12926
- if (cachedResult != null) {
12927
- return cachedResult;
12928
- }
12929
- const groupByLength = this.getGroupByLength();
12930
- if (groupKeys.length > groupByLength) {
12931
- const result2 = this.isRowSelected(groupKeys) ? { selectedCount: 1, deselectedCount: 0 } : {
12932
- selectedCount: 0,
12933
- deselectedCount: 1
12934
- };
12935
- this.selectionCountCache.set(groupKeys, result2);
12936
- return result2;
12937
- }
12938
- if (groupByLength && this.onlyUsePrimaryKeys) {
12939
- const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
12940
- let selectedCount2 = 0;
12941
- let deselectedCount2 = 0;
12942
- allKeys2.forEach((key) => {
12943
- if (this.defaultSelection) {
12944
- if (this.deselectedMap.has([key])) {
12945
- deselectedCount2++;
12946
- return;
12947
- }
12948
- selectedCount2++;
12949
- } else {
12950
- if (this.selectedMap.has([key])) {
12951
- selectedCount2++;
12952
- return;
13092
+ };
13093
+ function getCacheAffectedParts(state) {
13094
+ const cache = state.cache;
13095
+ if (!cache) {
13096
+ return {
13097
+ sortInfo: false,
13098
+ groupBy: false,
13099
+ filterValue: false,
13100
+ aggregationReducers: false
13101
+ };
13102
+ }
13103
+ let sortInfoAffected = false;
13104
+ let groupByAffected = false;
13105
+ let filterAffected = false;
13106
+ let aggregationsAffected = false;
13107
+ const keys = cache.getAffectedFields();
13108
+ const { sortInfo, groupBy, filterValue, aggregationReducers } = state;
13109
+ if (sortInfo && sortInfo.length) {
13110
+ if (keys === true) {
13111
+ sortInfoAffected = true;
13112
+ } else {
13113
+ for (const sort of sortInfo) {
13114
+ let field = sort.field;
13115
+ if (field) {
13116
+ field = Array.isArray(field) ? field : [field];
13117
+ sortInfoAffected = field.reduce((result, f) => {
13118
+ return result || typeof f !== "function" ? keys.has(f) : false;
13119
+ }, false);
13120
+ if (sortInfoAffected) {
13121
+ break;
12953
13122
  }
12954
- deselectedCount2++;
12955
13123
  }
12956
- });
12957
- const result2 = {
12958
- selectedCount: selectedCount2,
12959
- deselectedCount: deselectedCount2
12960
- };
12961
- this.selectionCountCache.set(groupKeys, result2);
12962
- return result2;
13124
+ }
12963
13125
  }
12964
- parentSelected = parentSelected != null ? parentSelected : this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
12965
- let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
12966
- if (groupKeys.length === this.getGroupByLength()) {
12967
- const selectionState = this.selectedMap.has(groupKeys) ? true : this.deselectedMap.has(groupKeys) ? false : parentSelected;
12968
- const totalCount = this.getGroupCount(groupKeys);
12969
- let selectedCount2 = this.selectedMap.getKeysStartingWith(
12970
- groupKeys,
12971
- true,
12972
- 1
12973
- ).length;
12974
- let deselectedCount2 = this.deselectedMap.getKeysStartingWith(
12975
- groupKeys,
12976
- true,
12977
- 1
12978
- ).length;
12979
- const notSpecifiedCount = totalCount - (selectedCount2 + deselectedCount2);
12980
- const result2 = {
12981
- selectedCount: selectedCount2 + (selectionState ? notSpecifiedCount : 0),
12982
- deselectedCount: deselectedCount2 + (selectionState ? 0 : notSpecifiedCount)
12983
- };
12984
- this.selectionCountCache.set(groupKeys, result2);
12985
- return result2;
13126
+ }
13127
+ if (groupBy && groupBy.length) {
13128
+ if (keys === true) {
13129
+ groupByAffected = true;
13130
+ } else {
13131
+ for (const group2 of groupBy) {
13132
+ if (group2.field && keys.has(group2.field)) {
13133
+ groupByAffected = true;
13134
+ break;
13135
+ }
13136
+ }
12986
13137
  }
12987
- let selectedCount = 0;
12988
- let deselectedCount = 0;
12989
- if (this.getConfig().lazyLoad && !allKeys.length) {
12990
- const totalChildrenCount = ((_b = (_a = this.getConfig().groupDeepMap) == null ? void 0 : _a.get(groupKeys)) == null ? void 0 : _b.totalChildrenCount) || 0;
12991
- if (parentSelected) {
12992
- selectedCount = totalChildrenCount;
12993
- deselectedCount = this.deselectedMap.getAllChildrenSizeFor(groupKeys);
12994
- if (deselectedCount === totalChildrenCount) {
12995
- selectedCount = 0;
13138
+ }
13139
+ if (filterValue && filterValue.length) {
13140
+ if (keys === true) {
13141
+ filterAffected = true;
13142
+ } else {
13143
+ for (const filter of filterValue) {
13144
+ if (filter.id) {
13145
+ filterAffected = true;
13146
+ break;
12996
13147
  }
12997
- } else {
12998
- deselectedCount = totalChildrenCount;
12999
- selectedCount = this.selectedMap.getAllChildrenSizeFor(groupKeys);
13000
- if (selectedCount === totalChildrenCount) {
13001
- deselectedCount = 0;
13148
+ if (filter.field && keys.has(filter.field)) {
13149
+ filterAffected = true;
13150
+ break;
13002
13151
  }
13003
13152
  }
13004
13153
  }
13005
- allKeys.forEach((keys) => {
13006
- let isSelected = this.selectedMap.get(keys);
13007
- let isDeselected = this.deselectedMap.get(keys);
13008
- const selected = isSelected ? true : isDeselected ? false : parentSelected;
13009
- const { selectedCount: selCount, deselectedCount: deselCount } = this.getSelectionCountFor(keys, selected);
13010
- selectedCount += selCount;
13011
- deselectedCount += deselCount;
13012
- });
13013
- const result = {
13014
- selectedCount,
13015
- deselectedCount
13016
- };
13017
- this.selectionCountCache.set(groupKeys, result);
13018
- return result;
13019
13154
  }
13020
- };
13155
+ if (aggregationReducers && Object.keys(aggregationReducers).length) {
13156
+ if (keys === true) {
13157
+ aggregationsAffected = true;
13158
+ } else {
13159
+ for (const key in aggregationReducers)
13160
+ if (aggregationReducers.hasOwnProperty(key)) {
13161
+ const reducer = aggregationReducers[key];
13162
+ if (!reducer.field) {
13163
+ aggregationsAffected = true;
13164
+ break;
13165
+ } else {
13166
+ if (keys.has(reducer.field)) {
13167
+ aggregationsAffected = true;
13168
+ break;
13169
+ }
13170
+ }
13171
+ }
13172
+ }
13173
+ }
13174
+ return {
13175
+ sortInfo: sortInfoAffected,
13176
+ groupBy: groupByAffected,
13177
+ filterValue: filterAffected,
13178
+ aggregationReducers: aggregationsAffected
13179
+ };
13180
+ }
13021
13181
 
13022
13182
  // src/components/DataSource/state/initRowInfoReducers.ts
13023
13183
  function initRowInfoReducers(reducers) {
@@ -13196,11 +13356,7 @@ function concludeReducer(params) {
13196
13356
  "originalDataArray",
13197
13357
  "originalLazyGroupDataChangeDetect"
13198
13358
  ]);
13199
- const dataSourceChange = previousState && state.data !== previousState.data;
13200
- let lazyLoadGroupDataChange = state.lazyLoad && previousState && (previousState.groupBy !== state.groupBy || previousState.sortInfo !== state.sortInfo);
13201
- if (dataSourceChange) {
13202
- lazyLoadGroupDataChange = true;
13203
- }
13359
+ const lazyLoadGroupDataChange = false;
13204
13360
  if (lazyLoadGroupDataChange) {
13205
13361
  state.originalLazyGroupData = new DeepMap();
13206
13362
  originalDataArrayChanged = true;
@@ -13629,7 +13785,7 @@ function loadData(data, componentState, actions, overrides, masterContext) {
13629
13785
  //@ts-ignore
13630
13786
  typeof data === "object" && typeof data.then === "function"
13631
13787
  );
13632
- if (dataIsPromise && !componentState.lazyLoad) {
13788
+ if (dataIsPromise && (!componentState.lazyLoad || componentState.lazyLoad && !append)) {
13633
13789
  actions.loading = true;
13634
13790
  }
13635
13791
  return Promise.resolve(data).then((dataParam) => {
@@ -13738,7 +13894,7 @@ function loadData(data, componentState, actions, overrides, masterContext) {
13738
13894
  if (!skipAssign) {
13739
13895
  actions.originalDataArray = append ? componentState.originalDataArray.concat(dataArray) : dataArray;
13740
13896
  }
13741
- if (dataIsPromise && !componentState.lazyLoad) {
13897
+ if (dataIsPromise && (!componentState.lazyLoad || componentState.lazyLoad && !append)) {
13742
13898
  actions.loading = false;
13743
13899
  }
13744
13900
  });
@@ -13767,12 +13923,12 @@ function getDetailReady(masterContext, getDataSourceState) {
13767
13923
  isDetailReady
13768
13924
  };
13769
13925
  }
13770
- function useLoadData() {
13926
+ function useLoadData(options) {
13771
13927
  const {
13772
13928
  getComponentState,
13773
13929
  componentActions: actions,
13774
13930
  componentState
13775
- } = useComponentState();
13931
+ } = options;
13776
13932
  const {
13777
13933
  data,
13778
13934
  dataArray,
@@ -13859,8 +14015,16 @@ function useLoadData() {
13859
14015
  cursorId: livePagination ? stateCursorId : null
13860
14016
  };
13861
14017
  const initialRef = (0, import_react35.useRef)(true);
13862
- useLazyLoadRange();
14018
+ useLazyLoadRange(options, {
14019
+ sortInfo,
14020
+ groupBy,
14021
+ pivotBy,
14022
+ filterValue,
14023
+ refetchKey,
14024
+ cursorId: livePagination ? stateCursorId : null
14025
+ });
13863
14026
  const getMasterContext = useLatest(useMasterDetailContext());
14027
+ const dataChangeTimestampsRef = (0, import_react35.useRef)([]);
13864
14028
  useEffectWithChanges(
13865
14029
  () => {
13866
14030
  const componentState2 = getComponentState();
@@ -13872,6 +14036,20 @@ function useLoadData() {
13872
14036
  if (isDetail && !isDetailReady) {
13873
14037
  return;
13874
14038
  }
14039
+ const now = Date.now();
14040
+ const timestamps = dataChangeTimestampsRef.current;
14041
+ if (timestamps.length >= 10) {
14042
+ timestamps.splice(0, 1);
14043
+ }
14044
+ timestamps.push(now);
14045
+ const timeDiff = now - timestamps[0];
14046
+ if (timeDiff < 200 && timestamps.length >= 10) {
14047
+ console.warn(
14048
+ `The "data" prop of your DataSource seems to be updating too frequently.
14049
+ Make sure you don't pass a new reference on every render. ERROR_CODE = DS001
14050
+ See http://infinite-table.com/docs/reference/error-codes#DS001 for more info.`
14051
+ );
14052
+ }
13875
14053
  if (typeof componentState2.data !== "function") {
13876
14054
  loadData(
13877
14055
  componentState2.data,
@@ -13930,12 +14108,12 @@ function useLoadData() {
13930
14108
  }
13931
14109
  }, depsObject);
13932
14110
  }
13933
- function useLazyLoadRange() {
14111
+ function useLazyLoadRange(options, dependencies) {
13934
14112
  const {
13935
14113
  getComponentState,
13936
14114
  componentActions: actions,
13937
14115
  componentState
13938
- } = useComponentState();
14116
+ } = options;
13939
14117
  (0, import_react35.useEffect)(() => {
13940
14118
  actions.lazyLoadCacheOfLoadedBatches = new DeepMap();
13941
14119
  }, [componentState.data, componentState.dataParams]);
@@ -13949,7 +14127,8 @@ function useLazyLoadRange() {
13949
14127
  scrollStopDelayUpdatedByTable
13950
14128
  } = componentState;
13951
14129
  const latestRenderRangeRef = (0, import_react35.useRef)(null);
13952
- const loadRange = (renderRange, cache = getComponentState().lazyLoadCacheOfLoadedBatches) => {
14130
+ const loadRange = (renderRange, options2, cache = getComponentState().lazyLoadCacheOfLoadedBatches) => {
14131
+ var _a;
13953
14132
  const componentState2 = getComponentState();
13954
14133
  renderRange = renderRange || latestRenderRangeRef.current;
13955
14134
  if (!renderRange) {
@@ -13971,7 +14150,8 @@ function useLazyLoadRange() {
13971
14150
  endIndex,
13972
14151
  lazyLoadBatchSize: lazyLoadBatchSize2,
13973
14152
  componentState: componentState2,
13974
- componentActions: actions
14153
+ componentActions: actions,
14154
+ dismissLoadedRows: (_a = options2 == null ? void 0 : options2.dismissLoadedRows) != null ? _a : false
13975
14155
  },
13976
14156
  cache
13977
14157
  );
@@ -13983,8 +14163,16 @@ function useLazyLoadRange() {
13983
14163
  useEffectWithChanges(
13984
14164
  (changes) => {
13985
14165
  if (lazyLoad) {
13986
- if (changes.originalLazyGroupDataChangeDetect || changes.groupRowsState) {
13987
- loadRange(notifyRenderRangeChange.get());
14166
+ if (changes.sortInfo || changes.filterValue || changes.groupBy || changes.pivotBy || changes.refetchKey || changes.cursorId) {
14167
+ getComponentState().lazyLoadCacheOfLoadedBatches.clear();
14168
+ getComponentState().originalLazyGroupData.clear();
14169
+ loadRange(notifyRenderRangeChange.get(), {
14170
+ dismissLoadedRows: true
14171
+ });
14172
+ } else {
14173
+ if (changes.originalLazyGroupDataChangeDetect || changes.groupRowsState) {
14174
+ loadRange(notifyRenderRangeChange.get());
14175
+ }
13988
14176
  }
13989
14177
  return notifyRenderRangeChange.onChange(
13990
14178
  (renderRange) => {
@@ -13996,6 +14184,12 @@ function useLazyLoadRange() {
13996
14184
  return;
13997
14185
  },
13998
14186
  {
14187
+ sortInfo: dependencies.sortInfo,
14188
+ filterValue: dependencies.filterValue,
14189
+ groupBy: dependencies.groupBy,
14190
+ pivotBy: dependencies.pivotBy,
14191
+ refetchKey: dependencies.refetchKey,
14192
+ cursorId: dependencies.cursorId,
13999
14193
  lazyLoadBatchSize,
14000
14194
  lazyLoad,
14001
14195
  originalLazyGroupDataChangeDetect,
@@ -14014,13 +14208,15 @@ function lazyLoadRange(options, cache) {
14014
14208
  endIndex,
14015
14209
  lazyLoadBatchSize,
14016
14210
  componentState,
14017
- componentActions
14211
+ componentActions,
14212
+ dismissLoadedRows
14018
14213
  } = options;
14019
14214
  const { dataArray } = componentState;
14020
- const isRowLoaded = (index) => {
14215
+ const isRowLoaded = dismissLoadedRows ? () => false : (index) => {
14021
14216
  const rowInfo = dataArray[index];
14022
14217
  return rowInfo.data != null;
14023
14218
  };
14219
+ const append = !dismissLoadedRows;
14024
14220
  const perGroupFnCalls = new DeepMap();
14025
14221
  const rootGroupKeys = ["_______xxx______"];
14026
14222
  for (let i = startIndex; i <= endIndex; i++) {
@@ -14039,7 +14235,8 @@ function lazyLoadRange(options, cache) {
14039
14235
  const currentFnCall = {
14040
14236
  lazyLoadStartIndex: 0,
14041
14237
  lazyLoadBatchSize,
14042
- groupKeys: rowInfo.groupKeys
14238
+ groupKeys: rowInfo.groupKeys,
14239
+ append
14043
14240
  };
14044
14241
  const cacheKeys2 = rowInfo.groupKeys;
14045
14242
  let cachedFnCalls = perGroupFnCalls.get(cacheKeys2);
@@ -14069,7 +14266,8 @@ function lazyLoadRange(options, cache) {
14069
14266
  const currentFnCall = {
14070
14267
  lazyLoadStartIndex: batchStartIndexInGroup,
14071
14268
  lazyLoadBatchSize,
14072
- groupKeys: theGroupKeys
14269
+ groupKeys: theGroupKeys,
14270
+ append
14073
14271
  };
14074
14272
  if (!cachedFnCalls[batchStartRowId]) {
14075
14273
  cachedFnCalls[batchStartRowId] = currentFnCall;
@@ -14077,143 +14275,23 @@ function lazyLoadRange(options, cache) {
14077
14275
  if (shouldSetFnCalls) {
14078
14276
  perGroupFnCalls.set(cacheKeys, cachedFnCalls);
14079
14277
  }
14080
- }
14081
- }
14082
- const initialPromise = Promise.resolve(true);
14083
- const allFnCalls = [];
14084
- perGroupFnCalls.topDownValues().forEach((record) => {
14085
- allFnCalls.push(...Object.values(record));
14086
- });
14087
- allFnCalls.reduce((promise, fnCall) => {
14088
- const cacheKey = [...fnCall.groupKeys, fnCall.lazyLoadStartIndex];
14089
- if (cache && cache.has(cacheKey)) {
14090
- return promise;
14091
- }
14092
- cache == null ? void 0 : cache.set(cacheKey, true);
14093
- const args = [componentState.data, componentState, componentActions, fnCall];
14094
- return promise.then(() => getRafPromise()).then(() => loadData(...args));
14095
- }, initialPromise);
14096
- }
14097
-
14098
- // src/utils/logger.ts
14099
- var log = debug("InfiniteTable");
14100
- var COLOR_WARN_VALUE = `#eb9316`;
14101
- var warnChannel = "Warn";
14102
- var errorChannel = "Error";
14103
- var infoChannel = "Info";
14104
- var successChannel = "Success";
14105
- var logChannel = "Logs";
14106
- var logger = log.extend(logChannel);
14107
- var infoLogger = logger.extend(infoChannel);
14108
- var warnLogger = logger.extend(warnChannel);
14109
- var errorLogger = logger.extend(errorChannel);
14110
- var successLogger = logger.extend(successChannel);
14111
- var logColorWarn = COLOR_WARN_VALUE;
14112
- var warn = (message, logger2) => {
14113
- logger2 = logger2 ? logger2.extend(warnChannel) : warnLogger;
14114
- logger2(log.color(logColorWarn, message));
14115
- };
14116
- var doOnceFlags = new DeepMap();
14117
- var doOnce = (func, ...keys) => {
14118
- if (doOnceFlags.has(keys)) {
14119
- return;
14120
- }
14121
- doOnceFlags.set(keys, true);
14122
- func();
14123
- };
14124
- var warnOnce = (message, key = message, logger2) => {
14125
- doOnce(() => warn(message, logger2), key, "warn");
14126
- };
14127
-
14128
- // src/components/utils/discardCallsWithEqualArg.ts
14129
- var map = /* @__PURE__ */ new WeakMap();
14130
- var getCompareDefault = (a) => a;
14131
- function discardCallsWithEqualArg(fn, timeframe = 50, getCompareObject) {
14132
- map.set(fn, {
14133
- lastCallTime: 0,
14134
- lastCallArg: null
14135
- });
14136
- const getCompare = getCompareObject != null ? getCompareObject : getCompareDefault;
14137
- return (arg) => {
14138
- const { lastCallTime, lastCallArg } = map.get(fn) || {
14139
- lastCallTime: 0,
14140
- lastCallArg: null
14141
- };
14142
- const now = Date.now();
14143
- const diff = now - lastCallTime;
14144
- const objectsEqual = shallowEqualObjects(
14145
- getCompare(lastCallArg),
14146
- getCompare(arg)
14147
- );
14148
- if (diff < timeframe && objectsEqual) {
14149
- return;
14150
- }
14151
- map.set(fn, {
14152
- lastCallTime: now,
14153
- lastCallArg: arg
14154
- });
14155
- fn(arg);
14156
- };
14157
- }
14158
-
14159
- // src/components/DataSource/Indexer.ts
14160
- var Indexer = class {
14161
- constructor() {
14162
- this.primaryKeyToData = /* @__PURE__ */ new Map();
14163
- this.add = (primaryKey, data) => {
14164
- this.primaryKeyToData.set(primaryKey, data);
14165
- };
14166
- this.clear = () => {
14167
- this.primaryKeyToData.clear();
14168
- };
14169
- this.getDataForPrimaryKey = (primaryKey) => {
14170
- return this.primaryKeyToData.get(primaryKey);
14171
- };
14172
- this.indexArray = (arr, options) => {
14173
- const { cache, toPrimaryKey } = options;
14174
- if (cache && !cache.isEmpty()) {
14175
- arr = arr.concat();
14176
- }
14177
- for (let i = 0; i < arr.length; i++) {
14178
- let item = arr[i];
14179
- let deleted = false;
14180
- if (item != null) {
14181
- const pk = toPrimaryKey(item);
14182
- const cacheInfo = cache == null ? void 0 : cache.getMutationsForPrimaryKey(pk);
14183
- if (cacheInfo && cacheInfo.length) {
14184
- for (let cacheIndex = 0, cacheLength = cacheInfo.length; cacheIndex < cacheLength; cacheIndex++) {
14185
- const info = cacheInfo[cacheIndex];
14186
- if (info.type === "delete" && !deleted) {
14187
- this.primaryKeyToData.delete(pk);
14188
- deleted = true;
14189
- arr.splice(i, 1);
14190
- }
14191
- if (info.type === "update" && !deleted) {
14192
- item = __spreadValues(__spreadValues({}, item), info.data);
14193
- arr[i] = item;
14194
- }
14195
- if (info.type === "insert") {
14196
- const insertPK = toPrimaryKey(info.data);
14197
- this.add(insertPK, info.data);
14198
- if (info.position === "before") {
14199
- arr.splice(i, 0, info.data);
14200
- i--;
14201
- } else {
14202
- arr.splice(i + 1, 0, info.data);
14203
- }
14204
- }
14205
- }
14206
- cache == null ? void 0 : cache.removeInfo(pk);
14207
- }
14208
- if (!deleted) {
14209
- this.add(pk, item);
14210
- }
14211
- }
14212
- }
14213
- return arr;
14214
- };
14278
+ }
14215
14279
  }
14216
- };
14280
+ const initialPromise = Promise.resolve(true);
14281
+ const allFnCalls = [];
14282
+ perGroupFnCalls.topDownValues().forEach((record) => {
14283
+ allFnCalls.push(...Object.values(record));
14284
+ });
14285
+ allFnCalls.reduce((promise, fnCall) => {
14286
+ const cacheKey = [...fnCall.groupKeys, fnCall.lazyLoadStartIndex];
14287
+ if (cache && cache.has(cacheKey)) {
14288
+ return promise;
14289
+ }
14290
+ cache == null ? void 0 : cache.set(cacheKey, true);
14291
+ const args = [componentState.data, componentState, componentActions, fnCall];
14292
+ return promise.then(() => getRafPromise()).then(() => loadData(...args));
14293
+ }, initialPromise);
14294
+ }
14217
14295
 
14218
14296
  // src/components/DataSource/state/normalizeSortInfo.ts
14219
14297
  var EMPTY_ARRAY = Object.freeze(
@@ -14698,6 +14776,102 @@ function getDataSourceStateRestoreForDetails(state) {
14698
14776
  };
14699
14777
  }
14700
14778
 
14779
+ // src/components/DataSource/privateHooks/useDataSource.tsx
14780
+ var import_react36 = __toESM(require("react"));
14781
+ function useDataSourceInternal(props) {
14782
+ const masterContext = useMasterDetailContext();
14783
+ const getDataSourceMasterContext = useLatest(masterContext);
14784
+ const isDetail = !!masterContext;
14785
+ const key = isDetail ? masterContext.masterRowInfo.id : "master";
14786
+ const { contextValue: managedContextValue, ContextComponent } = useManagedDataSource(props);
14787
+ const { componentActions, componentState, assignState } = managedContextValue;
14788
+ componentState.getDataSourceMasterContextRef.current = getDataSourceMasterContext;
14789
+ const getState = useLatest(componentState);
14790
+ const [api] = (0, import_react36.useState)(
14791
+ () => getDataSourceApi({ getState, actions: componentActions })
14792
+ );
14793
+ const contextValue = {
14794
+ componentState,
14795
+ componentActions,
14796
+ getDataSourceMasterContext,
14797
+ getState,
14798
+ assignState,
14799
+ api
14800
+ };
14801
+ const getLatestManagedContextValue = useLatest(managedContextValue);
14802
+ const getLatestContextValue = useLatest(contextValue);
14803
+ const DataSourceContext = getDataSourceContext();
14804
+ const DataSource2 = (0, import_react36.useCallback)(
14805
+ ({ children }) => {
14806
+ if (typeof children === "function") {
14807
+ children = children(getState());
14808
+ }
14809
+ return /* @__PURE__ */ import_react36.default.createElement(
14810
+ ContextComponent.Provider,
14811
+ {
14812
+ key,
14813
+ value: getLatestManagedContextValue()
14814
+ },
14815
+ /* @__PURE__ */ import_react36.default.createElement(DataSourceContext.Provider, { value: getLatestContextValue() }, children)
14816
+ );
14817
+ },
14818
+ [ContextComponent, isDetail, key]
14819
+ );
14820
+ (0, import_react36.useLayoutEffect)(() => {
14821
+ if (masterContext) {
14822
+ masterContext.registerDetail(contextValue);
14823
+ }
14824
+ }, []);
14825
+ (0, import_react36.useLayoutEffect)(() => {
14826
+ return () => {
14827
+ const state = getState();
14828
+ state.onCleanup(state);
14829
+ };
14830
+ }, []);
14831
+ if (false) {
14832
+ globalThis.getDataSourceState = getState;
14833
+ globalThis.dataSourceActions = componentActions;
14834
+ globalThis.dataSourceApi = api;
14835
+ }
14836
+ if (false) {
14837
+ globalThis.dataSources = globalThis.dataSources || {};
14838
+ globalThis["dataSources"][componentState.debugId] = {
14839
+ getState,
14840
+ actions: componentActions,
14841
+ api
14842
+ };
14843
+ }
14844
+ useLoadData({
14845
+ componentState,
14846
+ componentActions,
14847
+ getComponentState: getState
14848
+ });
14849
+ (0, import_react36.useEffect)(() => {
14850
+ var _a;
14851
+ (_a = componentState.onDataArrayChange) == null ? void 0 : _a.call(
14852
+ componentState,
14853
+ componentState.originalDataArray,
14854
+ componentState.originalDataArrayChangedInfo
14855
+ );
14856
+ if (componentState.onDataMutations && componentState.originalDataArrayChangedInfo.mutations && componentState.originalDataArrayChangedInfo.mutations.size) {
14857
+ componentState.onDataMutations({
14858
+ primaryKeyField: typeof componentState.primaryKey === "string" ? componentState.primaryKey : void 0,
14859
+ dataArray: componentState.originalDataArray,
14860
+ mutations: componentState.originalDataArrayChangedInfo.mutations,
14861
+ timestamp: componentState.originalDataArrayChangedInfo.timestamp
14862
+ });
14863
+ }
14864
+ }, [componentState.originalDataArrayChangedInfo]);
14865
+ (0, import_react36.useEffect)(() => {
14866
+ var _a;
14867
+ (_a = componentState.onReady) == null ? void 0 : _a.call(componentState, api);
14868
+ }, []);
14869
+ return {
14870
+ DataSource: DataSource2,
14871
+ state: contextValue.componentState
14872
+ };
14873
+ }
14874
+
14701
14875
  // src/utils/FixedSizeMap.ts
14702
14876
  var _FixedSizeMap = class {
14703
14877
  constructor(clone, size) {
@@ -15032,19 +15206,10 @@ var DataSourceActionType = /* @__PURE__ */ ((DataSourceActionType2) => {
15032
15206
  })(DataSourceActionType || {});
15033
15207
 
15034
15208
  // src/components/DataSource/index.tsx
15035
- function DataSourceWithContext(props) {
15036
- let { children } = props;
15037
- const { api, componentState } = useDataSourceContextValue();
15038
- if (typeof children === "function") {
15039
- children = children(componentState);
15040
- }
15041
- (0, import_react36.useEffect)(() => {
15042
- var _a;
15043
- (_a = componentState.onReady) == null ? void 0 : _a.call(componentState, api);
15044
- }, []);
15045
- return /* @__PURE__ */ React50.createElement(React50.Fragment, null, children);
15046
- }
15047
- var DataSourceRoot = getComponentStateRoot({
15209
+ var {
15210
+ // ManagedComponentContextProvider: ManagedDataSourceContextProvider,
15211
+ useManagedComponent: useManagedDataSource
15212
+ } = buildManagedComponent({
15048
15213
  debugName: "DataSource",
15049
15214
  //@ts-ignore
15050
15215
  initSetupState,
@@ -15063,78 +15228,12 @@ var DataSourceRoot = getComponentStateRoot({
15063
15228
  //@ts-ignore
15064
15229
  mappedCallbacks: getMappedCallbacks()
15065
15230
  });
15066
- function DataSourceCmp({
15067
- children,
15068
- isDetail
15069
- }) {
15070
- const DataSourceContext = getDataSourceContext();
15071
- const masterContext = useMasterDetailContext();
15072
- const getDataSourceMasterContext = useLatest(masterContext);
15073
- const { componentState, componentActions, assignState } = useComponentState();
15074
- componentState.getDataSourceMasterContextRef.current = getDataSourceMasterContext;
15075
- const getState = useLatest(componentState);
15076
- const [api] = React50.useState(() => {
15077
- return getDataSourceApi({ getState, actions: componentActions });
15078
- });
15079
- const contextValue = {
15080
- componentState,
15081
- componentActions,
15082
- getDataSourceMasterContext,
15083
- getState,
15084
- assignState,
15085
- api
15086
- };
15087
- (0, import_react36.useLayoutEffect)(() => {
15088
- if (masterContext) {
15089
- masterContext.registerDetail(contextValue);
15090
- }
15091
- }, []);
15092
- (0, import_react36.useLayoutEffect)(() => {
15093
- return () => {
15094
- const state = getState();
15095
- state.onCleanup(state);
15096
- };
15097
- }, []);
15098
- if (false) {
15099
- globalThis.getDataSourceState = getState;
15100
- globalThis.dataSourceActions = componentActions;
15101
- globalThis.dataSourceApi = api;
15102
- }
15103
- if (false) {
15104
- globalThis.dataSources = globalThis.dataSources || {};
15105
- globalThis["dataSources"][componentState.debugId] = {
15106
- getState,
15107
- actions: componentActions,
15108
- api
15109
- };
15110
- }
15111
- useLoadData();
15112
- (0, import_react36.useEffect)(() => {
15113
- var _a;
15114
- (_a = componentState.onDataArrayChange) == null ? void 0 : _a.call(
15115
- componentState,
15116
- componentState.originalDataArray,
15117
- componentState.originalDataArrayChangedInfo
15118
- );
15119
- if (componentState.onDataMutations && componentState.originalDataArrayChangedInfo.mutations && componentState.originalDataArrayChangedInfo.mutations.size) {
15120
- componentState.onDataMutations({
15121
- primaryKeyField: typeof componentState.primaryKey === "string" ? componentState.primaryKey : void 0,
15122
- dataArray: componentState.originalDataArray,
15123
- mutations: componentState.originalDataArrayChangedInfo.mutations,
15124
- timestamp: componentState.originalDataArrayChangedInfo.timestamp
15125
- });
15126
- }
15127
- }, [componentState.originalDataArrayChangedInfo]);
15128
- return /* @__PURE__ */ React50.createElement(DataSourceContext.Provider, { value: contextValue }, /* @__PURE__ */ React50.createElement(DataSourceWithContext, { children }));
15129
- }
15130
15231
  function DataSource(props) {
15131
- const masterContext = useMasterDetailContext();
15132
- const isDetail = !!masterContext;
15133
- const key = isDetail ? masterContext.masterRowInfo.id : "master";
15134
- return /* @__PURE__ */ React50.createElement(DataSourceRoot, __spreadProps(__spreadValues({}, props), { key }), /* @__PURE__ */ React50.createElement(DataSourceCmp, { children: props.children, isDetail }));
15232
+ const { DataSource: DataSourceComponent } = useDataSourceInternal(props);
15233
+ return /* @__PURE__ */ React51.createElement(DataSourceComponent, null, props.children);
15135
15234
  }
15136
15235
  function useRowInfoReducers() {
15137
- const { rowInfoReducerResults } = useDataSource();
15236
+ const { rowInfoReducerResults } = useDataSourceState();
15138
15237
  return rowInfoReducerResults;
15139
15238
  }
15140
15239
  function useMasterRowInfo() {
@@ -16443,7 +16542,7 @@ function useAutoSizeColumns() {
16443
16542
  getComponentState,
16444
16543
  componentActions,
16445
16544
  componentState: { domRef, ready, autoSizeColumnsKey, brain }
16446
- } = useComponentState();
16545
+ } = useManagedComponentState();
16447
16546
  const [refreshId, setRefreshId] = (0, import_react37.useState)(0);
16448
16547
  const theKey = typeof autoSizeColumnsKey === "object" ? autoSizeColumnsKey.key : autoSizeColumnsKey;
16449
16548
  const getTheKey = useLatest(theKey);
@@ -16508,7 +16607,7 @@ function useAutoSizeColumns() {
16508
16607
  // src/components/InfiniteTable/hooks/useCellRendering.tsx
16509
16608
  var import_react39 = require("react");
16510
16609
  var import_react40 = require("react");
16511
- var React52 = __toESM(require("react"));
16610
+ var React53 = __toESM(require("react"));
16512
16611
 
16513
16612
  // src/components/InfiniteTable/hooks/useYourBrain.ts
16514
16613
  function useYourBrain(param) {
@@ -16545,7 +16644,7 @@ function useYourBrain(param) {
16545
16644
  }
16546
16645
 
16547
16646
  // src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableDetailRow.tsx
16548
- var React51 = __toESM(require("react"));
16647
+ var React52 = __toESM(require("react"));
16549
16648
 
16550
16649
  // src/components/InfiniteTable/components/rowDetail.css.ts
16551
16650
  var RowDetailRecipe = createRuntimeFn({ defaultClassName: "rowDetail_RowDetailRecipe__evqes20", variantClassNames: {}, defaultVariants: {}, compoundVariants: [] });
@@ -16682,7 +16781,7 @@ function InfiniteTableDetailRowFn(props) {
16682
16781
  rowDetailsCache,
16683
16782
  rowInfo
16684
16783
  });
16685
- return /* @__PURE__ */ React51.createElement(DataSourceMasterDetailContext.Provider, { value: masterDetailContextValue }, /* @__PURE__ */ React51.createElement(
16784
+ return /* @__PURE__ */ React52.createElement(DataSourceMasterDetailContext.Provider, { value: masterDetailContextValue }, /* @__PURE__ */ React52.createElement(
16686
16785
  "div",
16687
16786
  {
16688
16787
  ref: domRef,
@@ -16699,7 +16798,7 @@ function InfiniteTableDetailRowFn(props) {
16699
16798
  rowDetailRenderer(rowInfo, currentRowCache)
16700
16799
  ));
16701
16800
  }
16702
- var InfiniteTableDetailRow = React51.memo(
16801
+ var InfiniteTableDetailRow = React52.memo(
16703
16802
  InfiniteTableDetailRowFn
16704
16803
  );
16705
16804
 
@@ -16858,7 +16957,7 @@ function useCellRendering(param) {
16858
16957
  cellStyle,
16859
16958
  cellClassName
16860
16959
  };
16861
- return /* @__PURE__ */ React52.createElement(InfiniteTableColumnCell, __spreadValues({}, cellProps));
16960
+ return /* @__PURE__ */ React53.createElement(InfiniteTableColumnCell, __spreadValues({}, cellProps));
16862
16961
  },
16863
16962
  [
16864
16963
  rowHeight,
@@ -16889,10 +16988,10 @@ function useCellRendering(param) {
16889
16988
  const dataArray2 = getData();
16890
16989
  const rowInfo = dataArray2[rowIndex];
16891
16990
  if (!rowInfo || !isRowDetailsExpanded(rowInfo) || !computedRowSizeCacheForDetails) {
16892
- return /* @__PURE__ */ React52.createElement("div", { ref: domRef, className: visibility.hidden });
16991
+ return /* @__PURE__ */ React53.createElement("div", { ref: domRef, className: visibility.hidden });
16893
16992
  }
16894
16993
  const { rowDetailHeight: rowDetailHeight2, rowHeight: rowHeight2 } = computedRowSizeCacheForDetails.getSize(rowIndex);
16895
- return /* @__PURE__ */ React52.createElement(
16994
+ return /* @__PURE__ */ React53.createElement(
16896
16995
  InfiniteTableDetailRow,
16897
16996
  {
16898
16997
  rowInfo,
@@ -17225,10 +17324,10 @@ function computeColumnGroupsDepths(columnGroups) {
17225
17324
  }
17226
17325
 
17227
17326
  // src/components/InfiniteTable/state/rowDetailRendererFromComponent.tsx
17228
- var React53 = __toESM(require("react"));
17327
+ var React54 = __toESM(require("react"));
17229
17328
  function getRowDetailRendererFromComponent(RowDetail) {
17230
17329
  return (rowInfo, cache) => {
17231
- return /* @__PURE__ */ React53.createElement(RowDetail, { key: rowInfo.id, rowInfo, cache });
17330
+ return /* @__PURE__ */ React54.createElement(RowDetail, { key: rowInfo.id, rowInfo, cache });
17232
17331
  };
17233
17332
  }
17234
17333
 
@@ -17705,7 +17804,7 @@ function useColumnsWhen() {
17705
17804
  pivotTotalColumnPosition,
17706
17805
  pivotGrandTotalColumnPosition
17707
17806
  }
17708
- } = useComponentState();
17807
+ } = useManagedComponentState();
17709
17808
  (0, import_react45.useEffect)(() => {
17710
17809
  dataSourceActions.generateGroupRows = groupRenderStrategy !== "inline";
17711
17810
  }, [groupRenderStrategy]);
@@ -17728,7 +17827,7 @@ function useColumnsWhenInlineGroupRenderStrategy(groupByMap) {
17728
17827
  const {
17729
17828
  componentActions,
17730
17829
  componentState: { columns, groupRenderStrategy }
17731
- } = useComponentState();
17830
+ } = useManagedComponentState();
17732
17831
  function computeColumnsWhenInlineGroupRenderStrategy(columns2, groupByMap2, groupRenderStrategy2, toggleGroupRow2) {
17733
17832
  const computedColumns = {};
17734
17833
  if (groupRenderStrategy2 !== "inline") {
@@ -17823,7 +17922,7 @@ function useColumnsWhenGrouping() {
17823
17922
  pivotGrandTotalColumnPosition
17824
17923
  },
17825
17924
  getComponentState
17826
- } = useComponentState();
17925
+ } = useManagedComponentState();
17827
17926
  const toggleGroupRow = useToggleGroupRow();
17828
17927
  (0, import_react45.useEffect)(() => {
17829
17928
  const update = () => {
@@ -17895,7 +17994,7 @@ function useHideColumns(groupByMap) {
17895
17994
  hideEmptyGroupColumns,
17896
17995
  groupRenderStrategy
17897
17996
  }
17898
- } = useComponentState();
17997
+ } = useManagedComponentState();
17899
17998
  (0, import_react45.useLayoutEffect)(() => {
17900
17999
  if (groupRenderStrategy !== "multi-column") {
17901
18000
  return;
@@ -18339,7 +18438,7 @@ var INITIAL_SCROLLBARS = {
18339
18438
  horizontal: false
18340
18439
  };
18341
18440
  function useScrollbars(brain) {
18342
- const { getComponentState: getInfiniteTableState } = useComponentState();
18441
+ const { getComponentState: getInfiniteTableState } = useManagedComponentState();
18343
18442
  const { getState: getDataSourceState } = useDataSourceContextValue();
18344
18443
  const [scrollbars, setScrollbars] = (0, import_react48.useState)(INITIAL_SCROLLBARS);
18345
18444
  (0, import_react48.useEffect)(() => {
@@ -18367,7 +18466,7 @@ function useScrollbars(brain) {
18367
18466
  // src/components/InfiniteTable/hooks/useComputed.ts
18368
18467
  function useComputed() {
18369
18468
  var _a;
18370
- const { componentActions, componentState } = useComponentState();
18469
+ const { componentActions, componentState } = useManagedComponentState();
18371
18470
  const {
18372
18471
  componentActions: dataSourceActions,
18373
18472
  componentState: dataSourceState,
@@ -18711,7 +18810,7 @@ var useLicense = (licenseKey = "") => {
18711
18810
  }
18712
18811
  let valid2 = isValidLicense(licenseKey, {
18713
18812
  publishedAt: 1624970570587,
18714
- version: "4.2.1-canary.0"
18813
+ version: "4.3.0"
18715
18814
  });
18716
18815
  if (!licenseKey && !valid2 && isInsidePlayground) {
18717
18816
  return true;
@@ -19750,7 +19849,7 @@ function useDOMEventHandlers() {
19750
19849
  var import_react58 = require("react");
19751
19850
 
19752
19851
  // src/components/hooks/useOverlay/index.tsx
19753
- var React54 = __toESM(require("react"));
19852
+ var React55 = __toESM(require("react"));
19754
19853
  var import_react54 = require("react");
19755
19854
  var import_react_dom2 = require("react-dom");
19756
19855
 
@@ -20136,10 +20235,10 @@ function retrieveElement(elementGetter) {
20136
20235
  });
20137
20236
  }
20138
20237
  function DefaultOverlayPortal(props) {
20139
- return /* @__PURE__ */ React54.createElement("div", { style: { position: "fixed", top: 0, left: 0 } }, props.children);
20238
+ return /* @__PURE__ */ React55.createElement("div", { style: { position: "fixed", top: 0, left: 0 } }, props.children);
20140
20239
  }
20141
20240
  function OverlayContent(props) {
20142
- const nodeRef = React54.useRef(null);
20241
+ const nodeRef = React55.useRef(null);
20143
20242
  (0, import_react54.useEffect)(() => {
20144
20243
  return props.realign.onChange((handle) => {
20145
20244
  if (nodeRef.current && handle) {
@@ -20147,7 +20246,7 @@ function OverlayContent(props) {
20147
20246
  }
20148
20247
  });
20149
20248
  }, [props.realign]);
20150
- return /* @__PURE__ */ React54.createElement(
20249
+ return /* @__PURE__ */ React55.createElement(
20151
20250
  "div",
20152
20251
  {
20153
20252
  style: { position: "absolute", top: 0, left: 0 },
@@ -20218,22 +20317,22 @@ function useOverlayPortal(content, portalContainer) {
20218
20317
  }, [portalContainer]);
20219
20318
  return portalContainer ? container ? (0, import_react_dom2.createPortal)(content, container) : (
20220
20319
  // we're probably still fetching the container
20221
- /* @__PURE__ */ React54.createElement(React54.Fragment, null)
20222
- ) : portalContainer === null || portalContainer === false ? content : /* @__PURE__ */ React54.createElement(DefaultOverlayPortal, null, content);
20320
+ /* @__PURE__ */ React55.createElement(React55.Fragment, null)
20321
+ ) : portalContainer === null || portalContainer === false ? content : /* @__PURE__ */ React55.createElement(DefaultOverlayPortal, null, content);
20223
20322
  }
20224
20323
  function getIdForReactOnlyChild(children) {
20225
- if (React54.Children.count(children) === 1) {
20226
- const child = React54.Children.only(children);
20227
- if (React54.isValidElement(child)) {
20324
+ if (React55.Children.count(children) === 1) {
20325
+ const child = React55.Children.only(children);
20326
+ if (React55.isValidElement(child)) {
20228
20327
  return child.props.id || child.key;
20229
20328
  }
20230
20329
  }
20231
20330
  return null;
20232
20331
  }
20233
20332
  function injectPortalContainerAndConstrainInMenuChild(children, portalContainer, constrainTo) {
20234
- if (React54.Children.count(children) === 1) {
20235
- const child = React54.Children.only(children);
20236
- if (React54.isValidElement(child) && child.type[propToIdentifyMenu]) {
20333
+ if (React55.Children.count(children) === 1) {
20334
+ const child = React55.Children.only(children);
20335
+ if (React55.isValidElement(child) && child.type[propToIdentifyMenu]) {
20237
20336
  const newProps = {};
20238
20337
  if (child.props.portalContainer === void 0) {
20239
20338
  newProps.portalContainer = portalContainer;
@@ -20241,7 +20340,7 @@ function injectPortalContainerAndConstrainInMenuChild(children, portalContainer,
20241
20340
  if (child.props.constrainTo === void 0) {
20242
20341
  newProps.constrainTo = constrainTo;
20243
20342
  }
20244
- return React54.cloneElement(child, newProps);
20343
+ return React55.cloneElement(child, newProps);
20245
20344
  }
20246
20345
  }
20247
20346
  return children;
@@ -20257,7 +20356,7 @@ function useOverlay(params) {
20257
20356
  const contentForPortal = [];
20258
20357
  for (const [_2, handle] of handles) {
20259
20358
  contentForPortal.push(
20260
- /* @__PURE__ */ React54.createElement(OverlayContent, __spreadProps(__spreadValues({}, handle), { key: handle.key }))
20359
+ /* @__PURE__ */ React55.createElement(OverlayContent, __spreadProps(__spreadValues({}, handle), { key: handle.key }))
20261
20360
  );
20262
20361
  }
20263
20362
  return contentForPortal;
@@ -20302,7 +20401,7 @@ function useOverlay(params) {
20302
20401
  },
20303
20402
  [handles, rootParams.portalContainer, updateContent]
20304
20403
  );
20305
- React54.useEffect(() => {
20404
+ React55.useEffect(() => {
20306
20405
  if (handleToRealign) {
20307
20406
  const handle = handles.get(handleToRealign);
20308
20407
  if (handle) {
@@ -20321,7 +20420,7 @@ function useOverlay(params) {
20321
20420
  handles.clear();
20322
20421
  updateContent();
20323
20422
  };
20324
- React54.useEffect(() => {
20423
+ React55.useEffect(() => {
20325
20424
  }, []);
20326
20425
  return {
20327
20426
  portal,
@@ -20333,16 +20432,16 @@ function useOverlay(params) {
20333
20432
  }
20334
20433
 
20335
20434
  // src/components/InfiniteTable/utils/getMenuForColumn.tsx
20336
- var React60 = __toESM(require("react"));
20435
+ var React61 = __toESM(require("react"));
20337
20436
 
20338
20437
  // src/components/Menu/index.tsx
20339
- var React58 = __toESM(require("react"));
20438
+ var React59 = __toESM(require("react"));
20340
20439
 
20341
20440
  // src/components/Menu/getMenuState.tsx
20342
- var React56 = __toESM(require("react"));
20441
+ var React57 = __toESM(require("react"));
20343
20442
 
20344
20443
  // src/components/Menu/childrenToRuntimeItems.tsx
20345
- var React55 = __toESM(require("react"));
20444
+ var React56 = __toESM(require("react"));
20346
20445
 
20347
20446
  // src/components/Menu/MenuItem.tsx
20348
20447
  function MenuItem(_props) {
@@ -20361,7 +20460,7 @@ var MenuSeparatorCls = "MenuCls_MenuSeparatorCls__db3arfd";
20361
20460
  // src/components/Menu/childrenToRuntimeItems.tsx
20362
20461
  var SEPARATOR = "-";
20363
20462
  function MenuSeparator() {
20364
- return /* @__PURE__ */ React55.createElement("hr", { className: MenuSeparatorCls });
20463
+ return /* @__PURE__ */ React56.createElement("hr", { className: MenuSeparatorCls });
20365
20464
  }
20366
20465
  var toRuntimeItem = ({
20367
20466
  columns,
@@ -20370,7 +20469,7 @@ var toRuntimeItem = ({
20370
20469
  menuId
20371
20470
  }, item) => {
20372
20471
  const menuItem = item && (item.key != null || item.label != null) ? item : null;
20373
- const menuDecoration = menuItem === null ? item === SEPARATOR ? /* @__PURE__ */ React55.createElement(MenuSeparator, null) : item : null;
20472
+ const menuDecoration = menuItem === null ? item === SEPARATOR ? /* @__PURE__ */ React56.createElement(MenuSeparator, null) : item : null;
20374
20473
  const runtimeItem = menuItem != null ? {
20375
20474
  type: "item",
20376
20475
  parentMenuId: menuId,
@@ -20398,7 +20497,7 @@ var toRuntimeItem = ({
20398
20497
  return runtimeItem;
20399
20498
  };
20400
20499
  function childrenToRuntimeItems(context, children) {
20401
- return React55.Children.map(children, (child) => {
20500
+ return React56.Children.map(children, (child) => {
20402
20501
  if (child) {
20403
20502
  if (child.props.__is_menu_item || child.type === MenuItem) {
20404
20503
  const itemProps = __spreadValues({}, child.props);
@@ -20421,7 +20520,7 @@ function childrenToRuntimeItems(context, children) {
20421
20520
  // src/components/Menu/getMenuState.tsx
20422
20521
  var SUBMENU_COL_NAME = "submenu";
20423
20522
  function getInitialMenuState() {
20424
- const domRef = React56.createRef();
20523
+ const domRef = React57.createRef();
20425
20524
  return {
20426
20525
  keyboardActiveItemKey: null,
20427
20526
  activeItemKey: null,
@@ -20476,7 +20575,7 @@ var deriveStateFromProps2 = (params) => {
20476
20575
  columns.push({
20477
20576
  name: SUBMENU_COL_NAME,
20478
20577
  render: ({ domProps, item }) => {
20479
- return item.menu ? /* @__PURE__ */ React56.createElement("div", __spreadValues({}, domProps), /* @__PURE__ */ React56.createElement(ExpanderIcon, { expanded: false })) : /* @__PURE__ */ React56.createElement("div", __spreadValues({}, domProps));
20578
+ return item.menu ? /* @__PURE__ */ React57.createElement("div", __spreadValues({}, domProps), /* @__PURE__ */ React57.createElement(ExpanderIcon, { expanded: false })) : /* @__PURE__ */ React57.createElement("div", __spreadValues({}, domProps));
20480
20579
  }
20481
20580
  });
20482
20581
  }
@@ -20493,7 +20592,7 @@ var deriveStateFromProps2 = (params) => {
20493
20592
  };
20494
20593
 
20495
20594
  // src/components/Menu/Menu.tsx
20496
- var React57 = __toESM(require("react"));
20595
+ var React58 = __toESM(require("react"));
20497
20596
  var import_react57 = require("react");
20498
20597
 
20499
20598
  // src/utils/pageGeometry/Triangle.ts
@@ -20753,7 +20852,7 @@ function renderSubmenuForItem(item, config) {
20753
20852
  if (typeof itemMenu === "function") {
20754
20853
  itemMenu = itemMenu();
20755
20854
  }
20756
- return /* @__PURE__ */ React57.createElement(
20855
+ return /* @__PURE__ */ React58.createElement(
20757
20856
  Menu,
20758
20857
  __spreadProps(__spreadValues({
20759
20858
  key: overlayId,
@@ -20966,7 +21065,7 @@ function MenuComponent(props) {
20966
21065
  setActiveItemKey(key);
20967
21066
  }
20968
21067
  });
20969
- renderedChildren = runtimeItems.map((runtimeItem, index) => /* @__PURE__ */ React57.createElement(
21068
+ renderedChildren = runtimeItems.map((runtimeItem, index) => /* @__PURE__ */ React58.createElement(
20970
21069
  RuntimeItemRenderer,
20971
21070
  {
20972
21071
  key: runtimeItem.type === "item" ? runtimeItem.key : index,
@@ -21151,7 +21250,7 @@ function MenuComponent(props) {
21151
21250
  domRef.current = node;
21152
21251
  }
21153
21252
  }, []);
21154
- const result = /* @__PURE__ */ React57.createElement("div", { className: display.contents }, /* @__PURE__ */ React57.createElement(
21253
+ const result = /* @__PURE__ */ React58.createElement("div", { className: display.contents }, /* @__PURE__ */ React58.createElement(
21155
21254
  "div",
21156
21255
  __spreadProps(__spreadValues({}, domProps), {
21157
21256
  "data-menu-id": menuId,
@@ -21183,12 +21282,12 @@ function MenuComponent(props) {
21183
21282
  return destroyed ? null : result;
21184
21283
  }
21185
21284
  function RuntimeItemRenderer(props) {
21186
- const [pressed, setPressed] = React57.useState(false);
21285
+ const [pressed, setPressed] = React58.useState(false);
21187
21286
  const { columns, item, index, active, keyboardActive } = props;
21188
21287
  const key = item.type === "item" ? item.value.key : index;
21189
21288
  let content = null;
21190
21289
  if (item.type === "decoration") {
21191
- content = /* @__PURE__ */ React57.createElement("div", { style: item.style }, item.value);
21290
+ content = /* @__PURE__ */ React58.createElement("div", { style: item.style }, item.value);
21192
21291
  } else {
21193
21292
  let spanIndex = 0;
21194
21293
  content = columns.map((col, i) => {
@@ -21249,7 +21348,7 @@ function RuntimeItemRenderer(props) {
21249
21348
  }
21250
21349
  }
21251
21350
  };
21252
- return col.render ? /* @__PURE__ */ React57.createElement(
21351
+ return col.render ? /* @__PURE__ */ React58.createElement(
21253
21352
  RenderHookComponent,
21254
21353
  {
21255
21354
  key: `${key}-${field}`,
@@ -21261,14 +21360,14 @@ function RuntimeItemRenderer(props) {
21261
21360
  domProps
21262
21361
  }
21263
21362
  }
21264
- ) : /* @__PURE__ */ React57.createElement("div", __spreadValues({ key: `${key}-${field}` }, domProps), target[field]);
21363
+ ) : /* @__PURE__ */ React58.createElement("div", __spreadValues({ key: `${key}-${field}` }, domProps), target[field]);
21265
21364
  }).filter(Boolean);
21266
21365
  }
21267
- return /* @__PURE__ */ React57.createElement("div", { className: MenuRowCls }, content);
21366
+ return /* @__PURE__ */ React58.createElement("div", { className: MenuRowCls }, content);
21268
21367
  }
21269
21368
 
21270
21369
  // src/components/Menu/index.tsx
21271
- var MenuRoot = getComponentStateRoot({
21370
+ var { ManagedComponentContextProvider: MenuRoot } = buildManagedComponent({
21272
21371
  initSetupState: getInitialMenuState,
21273
21372
  forwardProps: forwardProps5,
21274
21373
  // @ts-ignore
@@ -21276,14 +21375,14 @@ var MenuRoot = getComponentStateRoot({
21276
21375
  layoutEffect: true
21277
21376
  });
21278
21377
  function MenuContextProvider(props) {
21279
- const { componentActions, componentState } = useComponentState();
21378
+ const { componentActions, componentState } = useManagedComponentState();
21280
21379
  const getState = useLatest(componentState);
21281
- return /* @__PURE__ */ React58.createElement(
21380
+ return /* @__PURE__ */ React59.createElement(
21282
21381
  MenuContext.Provider,
21283
21382
  {
21284
21383
  value: { componentActions, componentState, getState }
21285
21384
  },
21286
- /* @__PURE__ */ React58.createElement(MenuComponent, { domProps: props.domProps })
21385
+ /* @__PURE__ */ React59.createElement(MenuComponent, { domProps: props.domProps })
21287
21386
  );
21288
21387
  }
21289
21388
  function Menu(props) {
@@ -21325,24 +21424,24 @@ function Menu(props) {
21325
21424
  //@ts-ignore
21326
21425
  "__is_infinite_menu_component"
21327
21426
  ]);
21328
- const menu = /* @__PURE__ */ React58.createElement(
21427
+ const menu = /* @__PURE__ */ React59.createElement(
21329
21428
  MenuRoot,
21330
21429
  __spreadValues({
21331
21430
  addSubmenuColumnIfNeeded,
21332
21431
  bubbleActionsFromSubmenus,
21333
21432
  wrapLabels
21334
21433
  }, props),
21335
- /* @__PURE__ */ React58.createElement(MenuContextProvider, { domProps })
21434
+ /* @__PURE__ */ React59.createElement(MenuContextProvider, { domProps })
21336
21435
  );
21337
21436
  if (false) {
21338
- return /* @__PURE__ */ React58.createElement(React58.StrictMode, null, menu);
21437
+ return /* @__PURE__ */ React59.createElement(React59.StrictMode, null, menu);
21339
21438
  }
21340
21439
  return menu;
21341
21440
  }
21342
21441
  Menu[propToIdentifyMenu] = true;
21343
21442
 
21344
21443
  // src/components/InfiniteTable/utils/defaultGetColumnMenuItems.tsx
21345
- var React59 = __toESM(require("react"));
21444
+ var React60 = __toESM(require("react"));
21346
21445
  function defaultGetColumnMenuItems(_items, params) {
21347
21446
  const { columnApi, column, getComputed, api } = params;
21348
21447
  const sortable = columnApi.isSortable();
@@ -21429,7 +21528,7 @@ function defaultGetColumnMenuItems(_items, params) {
21429
21528
  colItems.push({
21430
21529
  key: id,
21431
21530
  label,
21432
- check: /* @__PURE__ */ React59.createElement(
21531
+ check: /* @__PURE__ */ React60.createElement(
21433
21532
  InfiniteCheckBox,
21434
21533
  {
21435
21534
  key: col.id,
@@ -21492,7 +21591,7 @@ function getMenuForColumn(columnId, context, onHideIntent) {
21492
21591
  if (!items || !items.length) {
21493
21592
  return null;
21494
21593
  }
21495
- return /* @__PURE__ */ React60.createElement(
21594
+ return /* @__PURE__ */ React61.createElement(
21496
21595
  MenuCmp,
21497
21596
  {
21498
21597
  autoFocus: true,
@@ -21612,7 +21711,7 @@ function useColumnMenu() {
21612
21711
  }
21613
21712
 
21614
21713
  // src/components/InfiniteTable/components/FocusDetect.tsx
21615
- var React61 = __toESM(require("react"));
21714
+ var React62 = __toESM(require("react"));
21616
21715
  var import_react59 = require("react");
21617
21716
  var style = {
21618
21717
  width: 0,
@@ -21646,7 +21745,7 @@ function FocusDetect() {
21646
21745
  };
21647
21746
  focusLastFocusableCell(context);
21648
21747
  }), []);
21649
- return /* @__PURE__ */ React61.createElement(
21748
+ return /* @__PURE__ */ React62.createElement(
21650
21749
  "div",
21651
21750
  {
21652
21751
  onFocus,
@@ -21777,18 +21876,18 @@ function useEditingCallbackProps() {
21777
21876
  var import_react61 = require("react");
21778
21877
 
21779
21878
  // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
21780
- var React64 = __toESM(require("react"));
21879
+ var React65 = __toESM(require("react"));
21781
21880
 
21782
21881
  // src/components/InfiniteTable/components/icons/ClearIcon.tsx
21783
- var React62 = __toESM(require("react"));
21882
+ var React63 = __toESM(require("react"));
21784
21883
  var ClearIcon = (props) => {
21785
- return /* @__PURE__ */ React62.createElement(Icon, __spreadValues({}, props), /* @__PURE__ */ React62.createElement("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }));
21884
+ return /* @__PURE__ */ React63.createElement(Icon, __spreadValues({}, props), /* @__PURE__ */ React63.createElement("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }));
21786
21885
  };
21787
21886
 
21788
21887
  // src/components/InfiniteTable/components/icons/DoneIcon.tsx
21789
- var React63 = __toESM(require("react"));
21888
+ var React64 = __toESM(require("react"));
21790
21889
  var DoneIcon = (props) => {
21791
- return /* @__PURE__ */ React63.createElement(Icon, __spreadValues({}, props), /* @__PURE__ */ React63.createElement("path", { d: "m9.55 19-6.725-6.725L5.25 9.85l4.3 4.325 9.225-9.225 2.425 2.4Z" }));
21890
+ return /* @__PURE__ */ React64.createElement(Icon, __spreadValues({}, props), /* @__PURE__ */ React64.createElement("path", { d: "m9.55 19-6.725-6.725L5.25 9.85l4.3 4.325 9.225-9.225 2.425 2.4Z" }));
21792
21891
  };
21793
21892
 
21794
21893
  // src/components/InfiniteTable/utils/getFilterOperatorMenuForColumn.tsx
@@ -21834,12 +21933,12 @@ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
21834
21933
  const IconCmp = (_b = (_a2 = operator.components) == null ? void 0 : _a2.Icon) != null ? _b : FilterIcon;
21835
21934
  return {
21836
21935
  key,
21837
- icon: /* @__PURE__ */ React64.createElement(IconCmp, null),
21838
- label: /* @__PURE__ */ React64.createElement(React64.Fragment, null, (_c = operator.label) != null ? _c : operator.name),
21936
+ icon: /* @__PURE__ */ React65.createElement(IconCmp, null),
21937
+ label: /* @__PURE__ */ React65.createElement(React65.Fragment, null, (_c = operator.label) != null ? _c : operator.name),
21839
21938
  onAction: () => {
21840
21939
  api.setColumnFilterOperator(columnId, key);
21841
21940
  },
21842
- checked: checked ? /* @__PURE__ */ React64.createElement(DoneIcon, { size: 16 }) : null
21941
+ checked: checked ? /* @__PURE__ */ React65.createElement(DoneIcon, { size: 16 }) : null
21843
21942
  };
21844
21943
  });
21845
21944
  const firstItems = [
@@ -21854,7 +21953,7 @@ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
21854
21953
  {
21855
21954
  key: "reset",
21856
21955
  label: "Reset",
21857
- icon: /* @__PURE__ */ React64.createElement(ClearIcon, null),
21956
+ icon: /* @__PURE__ */ React65.createElement(ClearIcon, null),
21858
21957
  disabled: !column.computedFiltered,
21859
21958
  onAction: () => {
21860
21959
  api.clearColumnFilter(columnId);
@@ -21876,7 +21975,7 @@ function getFilterOperatorMenuForColumn(columnId, context, onHideIntent) {
21876
21975
  filterTypes
21877
21976
  };
21878
21977
  const items = getFilterOperatorMenuItems ? getFilterOperatorMenuItems(defaultItems, param) : defaultItems;
21879
- return /* @__PURE__ */ React64.createElement(
21978
+ return /* @__PURE__ */ React65.createElement(
21880
21979
  MenuCmp,
21881
21980
  {
21882
21981
  autoFocus: true,
@@ -21983,7 +22082,7 @@ function useColumnFilterOperatorMenu() {
21983
22082
  var import_react62 = require("react");
21984
22083
 
21985
22084
  // src/components/InfiniteTable/utils/getCellContextMenu.tsx
21986
- var React65 = __toESM(require("react"));
22085
+ var React66 = __toESM(require("react"));
21987
22086
  function getCellContextMenu(cellLocation, context, onHideIntent) {
21988
22087
  var _a;
21989
22088
  const { columnId, rowIndex, event } = cellLocation;
@@ -22023,7 +22122,7 @@ function getCellContextMenu(cellLocation, context, onHideIntent) {
22023
22122
  }
22024
22123
  return {
22025
22124
  preventDefault: true,
22026
- menu: /* @__PURE__ */ React65.createElement(
22125
+ menu: /* @__PURE__ */ React66.createElement(
22027
22126
  MenuCmp,
22028
22127
  {
22029
22128
  columns: menuColumns,
@@ -22078,7 +22177,7 @@ function getTableContextMenu(menuLocation, context, onHideIntent) {
22078
22177
  }
22079
22178
  return {
22080
22179
  preventDefault: true,
22081
- menu: /* @__PURE__ */ React65.createElement(
22180
+ menu: /* @__PURE__ */ React66.createElement(
22082
22181
  MenuCmp,
22083
22182
  {
22084
22183
  columns: menuColumns,
@@ -22284,7 +22383,7 @@ function useTableContextMenu() {
22284
22383
 
22285
22384
  // src/components/InfiniteTable/components/HScrollSyncContent.tsx
22286
22385
  var import_react64 = require("react");
22287
- var React66 = __toESM(require("react"));
22386
+ var React67 = __toESM(require("react"));
22288
22387
 
22289
22388
  // src/components/InfiniteTable/hooks/useGridScroll.ts
22290
22389
  var import_react63 = require("react");
@@ -22330,7 +22429,7 @@ function HScrollSyncContent(props) {
22330
22429
  } else if (maxWidth === "viewport") {
22331
22430
  style2.maxWidth = ThemeVars.runtime.bodyWidth;
22332
22431
  }
22333
- return /* @__PURE__ */ React66.createElement(
22432
+ return /* @__PURE__ */ React67.createElement(
22334
22433
  "div",
22335
22434
  __spreadProps(__spreadValues({
22336
22435
  ref: domRef
@@ -22362,7 +22461,7 @@ function useVisibleColumnSizes() {
22362
22461
  // src/components/InfiniteTable/index.tsx
22363
22462
  var InfiniteTableClassName = internalProps.rootClassName;
22364
22463
  var HOVERED_CLASS_NAMES = [RowHoverCls, "InfiniteColumnCell--hovered"];
22365
- var InfiniteTableRoot = getComponentStateRoot({
22464
+ var { ManagedComponentContextProvider: InfiniteTableRoot } = buildManagedComponent({
22366
22465
  // @ts-ignore
22367
22466
  initSetupState: initSetupState2,
22368
22467
  // @ts-ignore
@@ -22379,7 +22478,7 @@ var InfiniteTableRoot = getComponentStateRoot({
22379
22478
  //@ts-ignore
22380
22479
  mappedCallbacks: getMappedCallbacks2(),
22381
22480
  // @ts-ignore
22382
- getParentState: () => useDataSource(),
22481
+ getParentState: () => useDataSourceState(),
22383
22482
  debugName: "InfiniteTable"
22384
22483
  });
22385
22484
  function InfiniteTableHeader2() {
@@ -22387,7 +22486,7 @@ function InfiniteTableHeader2() {
22387
22486
  const { state: componentState, getComputed } = context;
22388
22487
  const { header, brain, headerBrain } = componentState;
22389
22488
  const { scrollbars } = getComputed();
22390
- return header ? /* @__PURE__ */ React67.createElement(
22489
+ return header ? /* @__PURE__ */ React68.createElement(
22391
22490
  TableHeaderWrapper,
22392
22491
  {
22393
22492
  bodyBrain: brain,
@@ -22403,7 +22502,7 @@ var InfiniteTableBodyCls = join(
22403
22502
  transformTranslateZero
22404
22503
  );
22405
22504
  function InfiniteTableBodyContainer(props) {
22406
- return /* @__PURE__ */ React67.createElement(
22505
+ return /* @__PURE__ */ React68.createElement(
22407
22506
  "div",
22408
22507
  __spreadProps(__spreadValues({}, props), {
22409
22508
  className: props.className ? join(InfiniteTableBodyCls, props.className) : InfiniteTableBodyCls
@@ -22437,7 +22536,7 @@ function InfiniteTableBody() {
22437
22536
  const {
22438
22537
  componentState: { loading }
22439
22538
  } = useDataSourceContextValue();
22440
- const onContextMenu = React67.useCallback((event) => {
22539
+ const onContextMenu = React68.useCallback((event) => {
22441
22540
  const state = context.getState();
22442
22541
  const target = event.target;
22443
22542
  if (!masterContext && event._from_row_detail) {
@@ -22481,7 +22580,7 @@ function InfiniteTableBody() {
22481
22580
  bodySize,
22482
22581
  computed
22483
22582
  });
22484
- return /* @__PURE__ */ React67.createElement(InfiniteTableBodyContainer, { onContextMenu }, /* @__PURE__ */ React67.createElement(
22583
+ return /* @__PURE__ */ React68.createElement(InfiniteTableBodyContainer, { onContextMenu }, /* @__PURE__ */ React68.createElement(
22485
22584
  HeadlessTable,
22486
22585
  {
22487
22586
  debugId,
@@ -22499,9 +22598,9 @@ function InfiniteTableBody() {
22499
22598
  cellHoverClassNames: HOVERED_CLASS_NAMES,
22500
22599
  scrollerDOMRef
22501
22600
  }
22502
- ), /* @__PURE__ */ React67.createElement(LoadMaskCmp, { visible: loading }, loadingText));
22601
+ ), /* @__PURE__ */ React68.createElement(LoadMaskCmp, { visible: loading }, loadingText));
22503
22602
  }
22504
- var InfiniteTableComponent = React67.memo(
22603
+ var InfiniteTableComponent = React68.memo(
22505
22604
  function InfiniteTableComponent2() {
22506
22605
  const context = useInfiniteTable();
22507
22606
  const masterContext = useMasterDetailContext();
@@ -22532,7 +22631,7 @@ var InfiniteTableComponent = React67.memo(
22532
22631
  useScrollToActiveRow(activeRowIndex, dataArray.length, api);
22533
22632
  useScrollToActiveCell(activeCellIndex, dataArray.length, api);
22534
22633
  const { onKeyDown: onKeyDown2 } = useDOMEventHandlers();
22535
- React67.useEffect(() => {
22634
+ React68.useEffect(() => {
22536
22635
  const dataSourceState = getDataSourceState();
22537
22636
  const onChange = debounce(
22538
22637
  (renderRange) => {
@@ -22547,7 +22646,7 @@ var InfiniteTableComponent = React67.memo(
22547
22646
  }, [brain, scrollStopDelay]);
22548
22647
  const licenseValid = useLicense(licenseKey);
22549
22648
  const domProps = useDOMProps(componentState.domProps);
22550
- React67.useEffect(() => {
22649
+ React68.useEffect(() => {
22551
22650
  brain.setScrollStopDelay(scrollStopDelay);
22552
22651
  dataSourceActions.scrollStopDelayUpdatedByTable = scrollStopDelay;
22553
22652
  }, [scrollStopDelay]);
@@ -22557,7 +22656,7 @@ var InfiniteTableComponent = React67.memo(
22557
22656
  const { menuPortal: cellContextMenuPortal } = useCellContextMenu();
22558
22657
  const { menuPortal: tableContextMenuPortal } = useTableContextMenu();
22559
22658
  const { menuPortal: filterOperatorMenuPortal } = useColumnFilterOperatorMenu();
22560
- React67.useEffect(() => {
22659
+ React68.useEffect(() => {
22561
22660
  if (typeof globalThis.__DO_NOT_USE_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_IS_READY === "function") {
22562
22661
  globalThis.__DO_NOT_USE_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_IS_READY(
22563
22662
  componentState.id,
@@ -22570,13 +22669,13 @@ var InfiniteTableComponent = React67.memo(
22570
22669
  globalThis.infiniteApi = context.api;
22571
22670
  }
22572
22671
  }, [componentState.ready]);
22573
- React67.useEffect(() => {
22672
+ React68.useEffect(() => {
22574
22673
  if (masterContext) {
22575
22674
  portalDOMRef.current = masterContext.getMasterState().portalDOMRef.current;
22576
22675
  }
22577
22676
  }, []);
22578
- const children = initialChildren != null ? initialChildren : /* @__PURE__ */ React67.createElement(React67.Fragment, null, /* @__PURE__ */ React67.createElement(InfiniteTableHeader2, null), /* @__PURE__ */ React67.createElement(InfiniteTableBody, null));
22579
- return /* @__PURE__ */ React67.createElement("div", __spreadValues({ onKeyDown: onKeyDown2, ref: domRef }, domProps), children, /* @__PURE__ */ React67.createElement(
22677
+ const children = initialChildren != null ? initialChildren : /* @__PURE__ */ React68.createElement(React68.Fragment, null, /* @__PURE__ */ React68.createElement(InfiniteTableHeader2, null), /* @__PURE__ */ React68.createElement(InfiniteTableBody, null));
22678
+ return /* @__PURE__ */ React68.createElement("div", __spreadValues({ onKeyDown: onKeyDown2, ref: domRef }, domProps), children, /* @__PURE__ */ React68.createElement(
22580
22679
  "div",
22581
22680
  {
22582
22681
  ref: portalDOMRef,
@@ -22592,31 +22691,31 @@ var InfiniteTableComponent = React67.memo(
22592
22691
  cellContextMenuPortal,
22593
22692
  tableContextMenuPortal,
22594
22693
  filterOperatorMenuPortal
22595
- ), rowHeightCSSVar ? /* @__PURE__ */ React67.createElement(
22694
+ ), rowHeightCSSVar ? /* @__PURE__ */ React68.createElement(
22596
22695
  CSSNumericVariableWatch,
22597
22696
  {
22598
22697
  varName: rowHeightCSSVar,
22599
22698
  onChange: onRowHeightCSSVarChange
22600
22699
  }
22601
- ) : null, rowDetailHeightCSSVar ? /* @__PURE__ */ React67.createElement(
22700
+ ) : null, rowDetailHeightCSSVar ? /* @__PURE__ */ React68.createElement(
22602
22701
  CSSNumericVariableWatch,
22603
22702
  {
22604
22703
  varName: rowDetailHeightCSSVar,
22605
22704
  onChange: onRowDetailHeightCSSVarChange
22606
22705
  }
22607
- ) : null, columnHeaderHeightCSSVar ? /* @__PURE__ */ React67.createElement(
22706
+ ) : null, columnHeaderHeightCSSVar ? /* @__PURE__ */ React68.createElement(
22608
22707
  CSSNumericVariableWatch,
22609
22708
  {
22610
22709
  varName: columnHeaderHeightCSSVar,
22611
22710
  onChange: onColumnHeaderHeightCSSVarChange
22612
22711
  }
22613
- ) : null, licenseValid ? null : /* @__PURE__ */ React67.createElement(InfiniteTableLicenseFooter, null), /* @__PURE__ */ React67.createElement(FocusDetect, null));
22712
+ ) : null, licenseValid ? null : /* @__PURE__ */ React68.createElement(InfiniteTableLicenseFooter, null), /* @__PURE__ */ React68.createElement(FocusDetect, null));
22614
22713
  }
22615
22714
  );
22616
22715
  function InfiniteTableContextProvider({
22617
22716
  children
22618
22717
  }) {
22619
- const { componentActions, componentState } = useComponentState();
22718
+ const { componentActions, componentState } = useManagedComponentState();
22620
22719
  const { scrollerDOMRef, scrollTopKey } = componentState;
22621
22720
  const computed = useComputed();
22622
22721
  const getComputed = useLatest(computed);
@@ -22634,7 +22733,7 @@ function InfiniteTableContextProvider({
22634
22733
  getDataSourceMasterContext,
22635
22734
  api: dataSourceApi
22636
22735
  } = useDataSourceContextValue();
22637
- const [imperativeApi] = React67.useState(() => {
22736
+ const [imperativeApi] = React68.useState(() => {
22638
22737
  return getImperativeApi({
22639
22738
  getComputed,
22640
22739
  getState,
@@ -22670,37 +22769,233 @@ function InfiniteTableContextProvider({
22670
22769
  },
22671
22770
  { earlyAttach: true, debounce: 50 }
22672
22771
  );
22673
- React67.useEffect(() => {
22772
+ React68.useEffect(() => {
22674
22773
  if (scrollerDOMRef.current) {
22675
22774
  scrollerDOMRef.current.scrollTop = 0;
22676
22775
  }
22677
22776
  }, [scrollTopKey, scrollerDOMRef]);
22678
22777
  const TableContext2 = getInfiniteTableContext();
22679
- return /* @__PURE__ */ React67.createElement(TableContext2.Provider, { value: contextValue }, /* @__PURE__ */ React67.createElement(InfiniteTableComponent, null));
22778
+ return /* @__PURE__ */ React68.createElement(TableContext2.Provider, { value: contextValue }, /* @__PURE__ */ React68.createElement(InfiniteTableComponent, null));
22680
22779
  }
22681
22780
  var DEFAULT_ROW_HEIGHT = 40;
22682
22781
  var DEFAULT_COLUMN_HEADER_HEIGHT = toCSSVarName(columnHeaderHeightName);
22683
22782
  var InfiniteTable = function(props) {
22684
22783
  const table = (
22685
22784
  //@ts-ignore
22686
- /* @__PURE__ */ React67.createElement(
22785
+ /* @__PURE__ */ React68.createElement(
22687
22786
  InfiniteTableRoot,
22688
22787
  __spreadValues({
22689
22788
  rowHeight: DEFAULT_ROW_HEIGHT,
22690
22789
  columnHeaderHeight: DEFAULT_COLUMN_HEADER_HEIGHT
22691
22790
  }, props),
22692
- /* @__PURE__ */ React67.createElement(InfiniteTableContextProvider, { children: props.children })
22791
+ /* @__PURE__ */ React68.createElement(InfiniteTableContextProvider, { children: props.children })
22693
22792
  )
22694
22793
  );
22695
22794
  if (false) {
22696
- return /* @__PURE__ */ React67.createElement(React67.StrictMode, null, table);
22795
+ return /* @__PURE__ */ React68.createElement(React68.StrictMode, null, table);
22697
22796
  }
22698
22797
  return table;
22699
22798
  };
22700
22799
  InfiniteTable.Header = InfiniteTableHeader2;
22701
22800
  InfiniteTable.Body = InfiniteTableBody;
22702
22801
  InfiniteTable.HScrollSyncContent = HScrollSyncContent;
22703
- InfiniteTable.Footer = () => /* @__PURE__ */ React67.createElement(InfiniteTableFooter, null);
22802
+ InfiniteTable.Footer = () => /* @__PURE__ */ React68.createElement(InfiniteTableFooter, null);
22803
+
22804
+ // src/components/DataSource/DataLoader/DataQuery.ts
22805
+ var logger2 = debug("InfiniteTable:DataQuery");
22806
+ var DataQuery = class {
22807
+ constructor(debugName) {
22808
+ this.state = "idle";
22809
+ this.result = void 0;
22810
+ this.error = void 0;
22811
+ this.doneAt = 0;
22812
+ this.pendingPromise = void 0;
22813
+ this.debugName = "";
22814
+ this.fetch = (loadFn, ...key) => __async(this, null, function* () {
22815
+ this.state = "loading";
22816
+ let resolvePending = () => {
22817
+ };
22818
+ try {
22819
+ logger2(`Fetching query ${this.debugName}...`);
22820
+ this.pendingPromise = new Promise((resolve) => {
22821
+ resolvePending = resolve;
22822
+ });
22823
+ this.result = yield loadFn(...key);
22824
+ this.state = "success";
22825
+ } catch (error2) {
22826
+ this.result = void 0;
22827
+ this.error = error2;
22828
+ this.state = "error";
22829
+ }
22830
+ this.doneAt = Date.now();
22831
+ this.pendingPromise = void 0;
22832
+ resolvePending(this);
22833
+ logger2(`Fetched query ${this.debugName}. State: ${this.state}.`);
22834
+ return this.getDoneSnapshot();
22835
+ });
22836
+ this.getCurrentSnapshot = () => {
22837
+ const result = {
22838
+ state: this.state,
22839
+ result: this.result,
22840
+ doneAt: this.doneAt,
22841
+ error: this.error,
22842
+ done: this.isDone()
22843
+ };
22844
+ if (!result.done) {
22845
+ result.promise = this.pendingPromise;
22846
+ }
22847
+ return result;
22848
+ };
22849
+ this.getDoneSnapshot = () => __async(this, null, function* () {
22850
+ if (this.state === "idle") {
22851
+ throw new Error("DataQuery is still idle");
22852
+ }
22853
+ if (this.pendingPromise) {
22854
+ yield this.pendingPromise;
22855
+ }
22856
+ return {
22857
+ state: this.state,
22858
+ result: this.result,
22859
+ error: this.error,
22860
+ done: this.isDone(),
22861
+ doneAt: this.doneAt
22862
+ };
22863
+ });
22864
+ this.getResult = () => {
22865
+ if (!this.isDone()) {
22866
+ throw new Error("DataQuery is not done yet");
22867
+ }
22868
+ return this.result;
22869
+ };
22870
+ this.isDone = () => this.state === "success" || this.state === "error";
22871
+ this.isSuccess = () => this.state === "success";
22872
+ this.debugName = debugName || "";
22873
+ }
22874
+ };
22875
+
22876
+ // src/components/DataSource/DataLoader/DataClient.ts
22877
+ function queryKeyToCacheKey(key) {
22878
+ if (Array.isArray(key)) {
22879
+ return key.map(queryKeyToCacheKey);
22880
+ }
22881
+ if (typeof key === "object") {
22882
+ if (key === null) {
22883
+ return key;
22884
+ }
22885
+ const current = key;
22886
+ const keys = Object.keys(current).sort((a, b) => a.localeCompare(b));
22887
+ const result = {};
22888
+ keys.forEach((k) => {
22889
+ const value = current[k];
22890
+ if (value !== void 0) {
22891
+ result[k] = queryKeyToCacheKey(value);
22892
+ }
22893
+ });
22894
+ return JSON.stringify(result);
22895
+ }
22896
+ if (key instanceof Date) {
22897
+ return key.toISOString();
22898
+ }
22899
+ return key;
22900
+ }
22901
+ var _DataClient = class {
22902
+ constructor(options) {
22903
+ this.queryCache = new DeepMap();
22904
+ this.removeQueryIfErrored = (query, stringifiedQueryKey) => {
22905
+ if (query.getCurrentSnapshot().state !== "success") {
22906
+ const currentCachedQuery = this.queryCache.get(stringifiedQueryKey);
22907
+ if (query === currentCachedQuery) {
22908
+ this.queryCache.delete(stringifiedQueryKey);
22909
+ return true;
22910
+ }
22911
+ }
22912
+ return false;
22913
+ };
22914
+ this.fireQuery = (options) => {
22915
+ var _a;
22916
+ const stringifiedCacheKey = queryKeyToCacheKey(
22917
+ options.key
22918
+ );
22919
+ const cachedQuery = this.options.cache ? this.queryCache.get(stringifiedCacheKey) : null;
22920
+ if (cachedQuery != null) {
22921
+ const currentSnapshot = cachedQuery.getCurrentSnapshot();
22922
+ if (currentSnapshot.state === "success") {
22923
+ return { query: cachedQuery, fromCache: true };
22924
+ }
22925
+ if (currentSnapshot.state === "loading") {
22926
+ return { query: cachedQuery, fromCache: true };
22927
+ }
22928
+ if (currentSnapshot.state === "error") {
22929
+ this.removeQueryIfErrored(cachedQuery, stringifiedCacheKey);
22930
+ }
22931
+ }
22932
+ const dataQuery = new DataQuery(options.name || "");
22933
+ this.queryCache.set(stringifiedCacheKey, dataQuery);
22934
+ dataQuery.fetch(options.fn, options.key);
22935
+ (_a = dataQuery.getCurrentSnapshot().promise) == null ? void 0 : _a.then(() => {
22936
+ this.removeQueryIfErrored(dataQuery, stringifiedCacheKey);
22937
+ });
22938
+ return { query: dataQuery, fromCache: false };
22939
+ };
22940
+ this.query = (options) => {
22941
+ return this.fireQuery(options).query.getCurrentSnapshot();
22942
+ };
22943
+ this.awaitQuery = (options) => __async(this, null, function* () {
22944
+ const { query, fromCache } = this.fireQuery(options);
22945
+ let snapshot = query.getCurrentSnapshot();
22946
+ if (snapshot.promise) {
22947
+ snapshot = yield query.getDoneSnapshot();
22948
+ if (snapshot.state === "error" && fromCache) {
22949
+ return yield this.fireQuery(options).query.getDoneSnapshot();
22950
+ }
22951
+ }
22952
+ return snapshot;
22953
+ });
22954
+ this.isQueryInProgress = (key) => {
22955
+ var _a;
22956
+ const stringifiedCacheKey = queryKeyToCacheKey(
22957
+ key
22958
+ );
22959
+ const cachedQuery = this.queryCache.get(stringifiedCacheKey);
22960
+ return (_a = cachedQuery == null ? void 0 : cachedQuery.getCurrentSnapshot().done) != null ? _a : false;
22961
+ };
22962
+ this.hasQueryForKey = (key) => {
22963
+ const stringifiedCacheKey = queryKeyToCacheKey(
22964
+ key
22965
+ );
22966
+ return this.queryCache.has(stringifiedCacheKey);
22967
+ };
22968
+ this.discardQueryForKey = (key) => {
22969
+ const stringifiedCacheKey = queryKeyToCacheKey(
22970
+ key
22971
+ );
22972
+ this.queryCache.delete(stringifiedCacheKey);
22973
+ };
22974
+ this.options = options;
22975
+ if (_DataClient.clients.has(options.name)) {
22976
+ const errMsg = `There's already a DataClient with name "${options.name}". Specify a different name for the client`;
22977
+ throw new Error(errMsg);
22978
+ }
22979
+ _DataClient.clients.set(options.name, this);
22980
+ this.name = options.name;
22981
+ }
22982
+ static destroy(clientName) {
22983
+ const client = _DataClient.clients.get(clientName);
22984
+ if (client) {
22985
+ client.destroy();
22986
+ }
22987
+ }
22988
+ static destroyAll() {
22989
+ _DataClient.clients.forEach((client) => {
22990
+ _DataClient.destroy(client.name);
22991
+ });
22992
+ }
22993
+ destroy() {
22994
+ _DataClient.clients.delete(this.options.name);
22995
+ }
22996
+ };
22997
+ var DataClient = _DataClient;
22998
+ DataClient.clients = /* @__PURE__ */ new Map();
22704
22999
 
22705
23000
  // src/components/InfiniteTable/eventHandlers/keyboardShortcuts.ts
22706
23001
  var instantEdit = {
@@ -22919,6 +23214,7 @@ var components = {
22919
23214
  // Annotate the CommonJS export names for ESM import in node:
22920
23215
  0 && (module.exports = {
22921
23216
  CellSelectionState,
23217
+ DataClient,
22922
23218
  DataSource,
22923
23219
  DataSourceActionType,
22924
23220
  DeepMap,
@@ -22944,8 +23240,10 @@ var components = {
22944
23240
  interceptMap,
22945
23241
  keyboardShortcuts,
22946
23242
  multisort,
23243
+ queryKeyToCacheKey,
22947
23244
  useComponentState,
22948
- useDataSource,
23245
+ useDataSourceInternal,
23246
+ useDataSourceState,
22949
23247
  useEffectWithChanges,
22950
23248
  useEffectWithObject,
22951
23249
  useGridScroll,
@@ -22953,6 +23251,7 @@ var components = {
22953
23251
  useInfiniteColumnEditor,
22954
23252
  useInfiniteColumnFilterEditor,
22955
23253
  useInfiniteHeaderCell,
23254
+ useManagedDataSource,
22956
23255
  useMasterRowInfo,
22957
23256
  useOverlay,
22958
23257
  useOverlayPortal,