@pretable/core 0.7.0 → 0.8.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.
- package/dist/index.cjs +83 -0
- package/dist/index.d.cts +56 -1
- package/dist/index.d.ts +56 -1
- package/dist/index.mjs +83 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -917,6 +917,72 @@ function isIndexedRowSelected(selection, ref, snapshot) {
|
|
|
917
917
|
return false;
|
|
918
918
|
return semanticRowSelected(rowSelectionProgram(selection, snapshot), ref.rowId);
|
|
919
919
|
}
|
|
920
|
+
function createIndexedRowSelection(requested, snapshot) {
|
|
921
|
+
let selection = createEmptyIndexedSelection();
|
|
922
|
+
if (requested.kind === "all") {
|
|
923
|
+
selection = selectAllVisibleRows(selection, snapshot);
|
|
924
|
+
} else {
|
|
925
|
+
for (const rowId of new Set(requested.rowIds)) {
|
|
926
|
+
selection = toggleIndexedRowSelection(selection, rowId, snapshot);
|
|
927
|
+
}
|
|
928
|
+
for (const range of requested.ranges ?? []) {
|
|
929
|
+
selection = selectIndexedRowRange(selection, range.startRowId, range.endRowId, snapshot);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
for (const rowId of new Set(requested.excludedRowIds)) {
|
|
933
|
+
if (!isIndexedRowSelected(selection, dataRef(rowId), snapshot))
|
|
934
|
+
continue;
|
|
935
|
+
selection = toggleIndexedRowSelection(selection, rowId, snapshot);
|
|
936
|
+
}
|
|
937
|
+
return selection.rows;
|
|
938
|
+
}
|
|
939
|
+
function describeRowSelection(rows) {
|
|
940
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
941
|
+
for (const range of rows.excludedRanges ?? []) {
|
|
942
|
+
excluded.add(range.startRowId);
|
|
943
|
+
excluded.add(range.endRowId);
|
|
944
|
+
}
|
|
945
|
+
const excludedRowIds = excluded.size === 0 ? {} : { excludedRowIds: Object.freeze([...excluded]) };
|
|
946
|
+
if (rows.kind === "all") {
|
|
947
|
+
return Object.freeze({ kind: "all", ...excludedRowIds });
|
|
948
|
+
}
|
|
949
|
+
const ranges = [...rows.ranges ?? []].map((range) => Object.freeze({ startRowId: range.startRowId, endRowId: range.endRowId }));
|
|
950
|
+
return Object.freeze({
|
|
951
|
+
kind: "explicit",
|
|
952
|
+
rowIds: Object.freeze([...rows.rowIds]),
|
|
953
|
+
...ranges.length === 0 ? {} : { ranges: Object.freeze(ranges) },
|
|
954
|
+
...excludedRowIds
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
function sameIndexedRowSelectionValue(left, right) {
|
|
958
|
+
if (left === right)
|
|
959
|
+
return true;
|
|
960
|
+
if (left.kind !== right.kind)
|
|
961
|
+
return false;
|
|
962
|
+
if (!sameRowRangeIndex(left.excludedRanges, right.excludedRanges))
|
|
963
|
+
return false;
|
|
964
|
+
if (left.kind !== "explicit" || right.kind !== "explicit")
|
|
965
|
+
return true;
|
|
966
|
+
if (left.rowIds.size !== right.rowIds.size)
|
|
967
|
+
return false;
|
|
968
|
+
for (const rowId of left.rowIds) {
|
|
969
|
+
if (!right.rowIds.has(rowId))
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
return sameRowRangeIndex(left.ranges, right.ranges);
|
|
973
|
+
}
|
|
974
|
+
function sameRowRangeIndex(left, right) {
|
|
975
|
+
if (left === right)
|
|
976
|
+
return true;
|
|
977
|
+
if ((left?.size ?? 0) !== (right?.size ?? 0))
|
|
978
|
+
return false;
|
|
979
|
+
const leftRanges = [...left ?? []];
|
|
980
|
+
const rightRanges = [...right ?? []];
|
|
981
|
+
return leftRanges.every((range, index) => {
|
|
982
|
+
const other = rightRanges[index];
|
|
983
|
+
return other !== void 0 && sameRowId(range.startRowId, other.startRowId) && sameRowId(range.endRowId, other.endRowId);
|
|
984
|
+
});
|
|
985
|
+
}
|
|
920
986
|
function getIndexedSelectionSummary(selection, snapshot) {
|
|
921
987
|
const visibleCount2 = snapshot.visibleDataRowCount;
|
|
922
988
|
const selectedCount = projectionFor(rowSelectionProgram(selection, snapshot), snapshot).runs?.selectedCount ?? 0;
|
|
@@ -1323,6 +1389,22 @@ function createGridUiCore(options) {
|
|
|
1323
1389
|
publish({ ...state, selection: next });
|
|
1324
1390
|
});
|
|
1325
1391
|
},
|
|
1392
|
+
setRowSelection(rows) {
|
|
1393
|
+
command(() => {
|
|
1394
|
+
let nextRows;
|
|
1395
|
+
try {
|
|
1396
|
+
nextRows = createIndexedRowSelection(rows, snapshotForInteraction());
|
|
1397
|
+
} catch (cause) {
|
|
1398
|
+
throw observationError("The supplied row selection could not be applied atomically.", cause);
|
|
1399
|
+
}
|
|
1400
|
+
if (sameIndexedRowSelectionValue(state.selection.rows, nextRows))
|
|
1401
|
+
return;
|
|
1402
|
+
publish({
|
|
1403
|
+
...state,
|
|
1404
|
+
selection: Object.freeze({ ...state.selection, rows: nextRows })
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
},
|
|
1326
1408
|
toggleRowSelection(rowId) {
|
|
1327
1409
|
command(() => {
|
|
1328
1410
|
let next;
|
|
@@ -8395,4 +8477,5 @@ exports.PretableUnsupportedRowUpdateError = PretableUnsupportedRowUpdateError;
|
|
|
8395
8477
|
exports.createColumnHelper = createColumnHelper2;
|
|
8396
8478
|
exports.createGrid = createGrid;
|
|
8397
8479
|
exports.createLocalRowModel = createLocalRowModel2;
|
|
8480
|
+
exports.describeRowSelection = describeRowSelection;
|
|
8398
8481
|
exports.numberFormats = numberFormats;
|
package/dist/index.d.cts
CHANGED
|
@@ -912,6 +912,39 @@ type PretableIndexedRowSelection<TRowId extends PretableRowId> = {
|
|
|
912
912
|
readonly kind: "all";
|
|
913
913
|
readonly excludedRanges?: PretableIndexedRowRangeIndex<TRowId>;
|
|
914
914
|
};
|
|
915
|
+
/**
|
|
916
|
+
* The row-checkbox slice as a consumer WRITES it — the settable counterpart of
|
|
917
|
+
* {@link PretableIndexedRowSelection}, which is what the engine holds.
|
|
918
|
+
*
|
|
919
|
+
* Same two cases and the same discriminant, because they describe the same
|
|
920
|
+
* thing; only the containers differ. The engine stores a `ReadonlySet` and an
|
|
921
|
+
* opaque normalized interval index, neither of which a consumer can build; this
|
|
922
|
+
* shape takes plain arrays and the engine indexes them at the boundary.
|
|
923
|
+
*
|
|
924
|
+
* The sparseness survives that conversion, which is the point of not flattening
|
|
925
|
+
* this to a list of ids:
|
|
926
|
+
*
|
|
927
|
+
* - `{ kind: "all" }` is symbolic. Applying it is O(1) whatever the row
|
|
928
|
+
* count — it never enumerates the population, so select-all over a million
|
|
929
|
+
* rows stays free.
|
|
930
|
+
* - `ranges` carries a shift-checked span as its two endpoints, so a 100k-row
|
|
931
|
+
* span costs two ids rather than 100k.
|
|
932
|
+
* - `excludedRowIds` is POINTS, not spans, matching what the engine can
|
|
933
|
+
* actually store: unticking one row out of a symbolic "all" records that
|
|
934
|
+
* one row. A span-shaped exclusion would read as though it could untick a
|
|
935
|
+
* range, which nothing here can do.
|
|
936
|
+
*
|
|
937
|
+
* @public
|
|
938
|
+
*/
|
|
939
|
+
type PretableRowSelectionState<TRowId extends PretableRowId> = {
|
|
940
|
+
readonly kind: "explicit";
|
|
941
|
+
readonly rowIds: readonly TRowId[];
|
|
942
|
+
readonly ranges?: readonly PretableIndexedRowRange<TRowId>[];
|
|
943
|
+
readonly excludedRowIds?: readonly TRowId[];
|
|
944
|
+
} | {
|
|
945
|
+
readonly kind: "all";
|
|
946
|
+
readonly excludedRowIds?: readonly TRowId[];
|
|
947
|
+
};
|
|
915
948
|
/** Data-only selection owned by the indexed UI layer. @public */
|
|
916
949
|
interface PretableIndexedSelectionState<TRowId extends PretableRowId, TColumnId extends string> {
|
|
917
950
|
readonly rows: PretableIndexedRowSelection<TRowId>;
|
|
@@ -974,6 +1007,17 @@ interface PretableGridUiCore<TRow extends object, TRowId extends PretableRowId,
|
|
|
974
1007
|
readonly pageRows?: number;
|
|
975
1008
|
}) => void;
|
|
976
1009
|
readonly setSelection: (selection: PretableIndexedSelectionState<TRowId, ColumnIdOf<TColumns>>) => void;
|
|
1010
|
+
/**
|
|
1011
|
+
* Replace the row-checkbox slice, leaving the cell ranges and anchor alone.
|
|
1012
|
+
*
|
|
1013
|
+
* The write-side counterpart of `getState().selection.rows`. `setSelection`
|
|
1014
|
+
* cannot do this job: it takes the engine's own containers, which a consumer
|
|
1015
|
+
* has no way to construct.
|
|
1016
|
+
*
|
|
1017
|
+
* Idempotent — applying a value the slice already holds publishes nothing, so
|
|
1018
|
+
* a controlled caller can push on every render without looping.
|
|
1019
|
+
*/
|
|
1020
|
+
readonly setRowSelection: (rows: PretableRowSelectionState<TRowId>) => void;
|
|
977
1021
|
readonly toggleRowSelection: (rowId: TRowId) => void;
|
|
978
1022
|
readonly selectRowRange: (startRowId: TRowId, endRowId: TRowId) => void;
|
|
979
1023
|
readonly isRowSelected: (rowId: TRowId) => boolean;
|
|
@@ -1007,6 +1051,17 @@ interface CreateGridUiCoreOptions<TRow extends object, TRowId extends PretableRo
|
|
|
1007
1051
|
readonly viewport?: PretableViewportState;
|
|
1008
1052
|
}
|
|
1009
1053
|
|
|
1054
|
+
/**
|
|
1055
|
+
* Render the engine's row-checkbox slice as the shape a consumer can write
|
|
1056
|
+
* back — the inverse of {@link createIndexedRowSelection}.
|
|
1057
|
+
*
|
|
1058
|
+
* Sparse in, sparse out. A symbolic "all" stays two words, and a shift-checked
|
|
1059
|
+
* 100k-row span stays its two endpoint ids; nothing here walks a population.
|
|
1060
|
+
*
|
|
1061
|
+
* @public
|
|
1062
|
+
*/
|
|
1063
|
+
declare function describeRowSelection<TRowId extends PretableRowId>(rows: PretableIndexedRowSelection<TRowId>): PretableRowSelectionState<TRowId>;
|
|
1064
|
+
|
|
1010
1065
|
/**
|
|
1011
1066
|
* Half-open row index range — `start` inclusive, `end` exclusive — used to
|
|
1012
1067
|
* describe a visible row window without materializing the rows outside it.
|
|
@@ -1145,4 +1200,4 @@ declare const numberFormats: {
|
|
|
1145
1200
|
readonly accounting: (options: PretableCurrencyFormatOptions) => Intl.NumberFormatOptions;
|
|
1146
1201
|
};
|
|
1147
1202
|
|
|
1148
|
-
export { type AutosizeOptions, type ColumnAggregateValueOf, type ColumnAlign, type ColumnFilter, type ColumnIdOf, type ColumnOption, type ColumnType, type ColumnValueOf, type ColumnsOf, type CreateGridUiCoreOptions, type CreateLocalRowModelOptions, type CreateLocalRowModelWithDefaultIdOptions, type FilterOperator, type FilterValue, GROUP_COLUMN_ID, type PretableAggregateFormatInput, type PretableAggregateOutputOf, type PretableAggregateSpec, type PretableAggregatesFor, type PretableAggregator, type PretableBuiltinAggregate, type PretableCellAddress, type PretableCellRange, type PretableChangeOperation, type PretableChangeSequence, type PretableChangeSet, type PretableColumn, type PretableColumnAccessorKind, type PretableColumnCallbackContext, type PretableColumnDefinition, type PretableColumnDerivation, type PretableColumnHelper, type PretableColumnOptions, type PretableColumnType, type PretableColumnTypeFor, type PretableCompatibleAggregateSpec, type PretableCompatibleAggregator, type PretableCurrencyFormatOptions, type PretableDataRow, type PretableDerivationTransition, type PretableDerivationsFor, PretableDisposedModelError, type PretableDistinctColumnIdOf, type PretableDistinctValueOptions, type PretableDistinctValueQuery, type PretableDistinctValueResult, type PretableEditInput, type PretableEditState, type PretableEditStatus, type PretableExpansionDefault, type PretableExpansionState, type PretableFilterFor, type PretableFilterOperandFor, type PretableFocusDirection, type PretableFocusState, type PretableFormatInput, type PretableGridUiColumn, type PretableGridUiColumnLayout, type PretableGridUiCore, type PretableGridUiState, type PretableGroupColumnOptions, type PretableGroupId, type PretableGroupKey, type PretableGroupRow, type PretableIndexedCellAddress, type PretableIndexedCellRange, type PretableIndexedEditingState, type PretableIndexedFocusMovement, type PretableIndexedFocusState, type PretableIndexedRowRange, type PretableIndexedRowRangeIndex, type PretableIndexedRowSelection, type PretableIndexedSelectionState, type PretableIndexedSelectionSummary, PretableInvalidGroupKeyError, type PretableMatchingTotal, type PretableMoveFocusOptions, type PretableMutationIssue, type PretableMutationResult, type PretableProcessingAuthority, type PretableProcessingOptions, type PretableQueryFor, type PretableQueryTransition, PretableReentrantMutationError, type PretableResultMeta, type PretableRow, type PretableRowGroupFor, type PretableRowId, PretableRowIdentityChangeError, type PretableRowModel, PretableRowModelError, type PretableRowModelErrorCode, type PretableRowModelErrorContext, type PretableRowModelOperation, type PretableRowModelSnapshot, type PretableRowModelState, type PretableRowModelStatus, type PretableRowRange, type PretableRowUpdate, type PretableSelectionState, type PretableSortDirection, type PretableSortEntry, type PretableSortFor, type PretableTransaction, type PretableTransitionCancellationReason, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, type PretableViewportState, type PretableVisibleRow, type PretableVisibleRowField, type PretableVisibleRowRef, type Prettify, type RowIdOf, type RowOf, createColumnHelper, createGrid, createLocalRowModel, numberFormats };
|
|
1203
|
+
export { type AutosizeOptions, type ColumnAggregateValueOf, type ColumnAlign, type ColumnFilter, type ColumnIdOf, type ColumnOption, type ColumnType, type ColumnValueOf, type ColumnsOf, type CreateGridUiCoreOptions, type CreateLocalRowModelOptions, type CreateLocalRowModelWithDefaultIdOptions, type FilterOperator, type FilterValue, GROUP_COLUMN_ID, type PretableAggregateFormatInput, type PretableAggregateOutputOf, type PretableAggregateSpec, type PretableAggregatesFor, type PretableAggregator, type PretableBuiltinAggregate, type PretableCellAddress, type PretableCellRange, type PretableChangeOperation, type PretableChangeSequence, type PretableChangeSet, type PretableColumn, type PretableColumnAccessorKind, type PretableColumnCallbackContext, type PretableColumnDefinition, type PretableColumnDerivation, type PretableColumnHelper, type PretableColumnOptions, type PretableColumnType, type PretableColumnTypeFor, type PretableCompatibleAggregateSpec, type PretableCompatibleAggregator, type PretableCurrencyFormatOptions, type PretableDataRow, type PretableDerivationTransition, type PretableDerivationsFor, PretableDisposedModelError, type PretableDistinctColumnIdOf, type PretableDistinctValueOptions, type PretableDistinctValueQuery, type PretableDistinctValueResult, type PretableEditInput, type PretableEditState, type PretableEditStatus, type PretableExpansionDefault, type PretableExpansionState, type PretableFilterFor, type PretableFilterOperandFor, type PretableFocusDirection, type PretableFocusState, type PretableFormatInput, type PretableGridUiColumn, type PretableGridUiColumnLayout, type PretableGridUiCore, type PretableGridUiState, type PretableGroupColumnOptions, type PretableGroupId, type PretableGroupKey, type PretableGroupRow, type PretableIndexedCellAddress, type PretableIndexedCellRange, type PretableIndexedEditingState, type PretableIndexedFocusMovement, type PretableIndexedFocusState, type PretableIndexedRowRange, type PretableIndexedRowRangeIndex, type PretableIndexedRowSelection, type PretableIndexedSelectionState, type PretableIndexedSelectionSummary, PretableInvalidGroupKeyError, type PretableMatchingTotal, type PretableMoveFocusOptions, type PretableMutationIssue, type PretableMutationResult, type PretableProcessingAuthority, type PretableProcessingOptions, type PretableQueryFor, type PretableQueryTransition, PretableReentrantMutationError, type PretableResultMeta, type PretableRow, type PretableRowGroupFor, type PretableRowId, PretableRowIdentityChangeError, type PretableRowModel, PretableRowModelError, type PretableRowModelErrorCode, type PretableRowModelErrorContext, type PretableRowModelOperation, type PretableRowModelSnapshot, type PretableRowModelState, type PretableRowModelStatus, type PretableRowRange, type PretableRowSelectionState, type PretableRowUpdate, type PretableSelectionState, type PretableSortDirection, type PretableSortEntry, type PretableSortFor, type PretableTransaction, type PretableTransitionCancellationReason, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, type PretableViewportState, type PretableVisibleRow, type PretableVisibleRowField, type PretableVisibleRowRef, type Prettify, type RowIdOf, type RowOf, createColumnHelper, createGrid, createLocalRowModel, describeRowSelection, numberFormats };
|
package/dist/index.d.ts
CHANGED
|
@@ -912,6 +912,39 @@ type PretableIndexedRowSelection<TRowId extends PretableRowId> = {
|
|
|
912
912
|
readonly kind: "all";
|
|
913
913
|
readonly excludedRanges?: PretableIndexedRowRangeIndex<TRowId>;
|
|
914
914
|
};
|
|
915
|
+
/**
|
|
916
|
+
* The row-checkbox slice as a consumer WRITES it — the settable counterpart of
|
|
917
|
+
* {@link PretableIndexedRowSelection}, which is what the engine holds.
|
|
918
|
+
*
|
|
919
|
+
* Same two cases and the same discriminant, because they describe the same
|
|
920
|
+
* thing; only the containers differ. The engine stores a `ReadonlySet` and an
|
|
921
|
+
* opaque normalized interval index, neither of which a consumer can build; this
|
|
922
|
+
* shape takes plain arrays and the engine indexes them at the boundary.
|
|
923
|
+
*
|
|
924
|
+
* The sparseness survives that conversion, which is the point of not flattening
|
|
925
|
+
* this to a list of ids:
|
|
926
|
+
*
|
|
927
|
+
* - `{ kind: "all" }` is symbolic. Applying it is O(1) whatever the row
|
|
928
|
+
* count — it never enumerates the population, so select-all over a million
|
|
929
|
+
* rows stays free.
|
|
930
|
+
* - `ranges` carries a shift-checked span as its two endpoints, so a 100k-row
|
|
931
|
+
* span costs two ids rather than 100k.
|
|
932
|
+
* - `excludedRowIds` is POINTS, not spans, matching what the engine can
|
|
933
|
+
* actually store: unticking one row out of a symbolic "all" records that
|
|
934
|
+
* one row. A span-shaped exclusion would read as though it could untick a
|
|
935
|
+
* range, which nothing here can do.
|
|
936
|
+
*
|
|
937
|
+
* @public
|
|
938
|
+
*/
|
|
939
|
+
type PretableRowSelectionState<TRowId extends PretableRowId> = {
|
|
940
|
+
readonly kind: "explicit";
|
|
941
|
+
readonly rowIds: readonly TRowId[];
|
|
942
|
+
readonly ranges?: readonly PretableIndexedRowRange<TRowId>[];
|
|
943
|
+
readonly excludedRowIds?: readonly TRowId[];
|
|
944
|
+
} | {
|
|
945
|
+
readonly kind: "all";
|
|
946
|
+
readonly excludedRowIds?: readonly TRowId[];
|
|
947
|
+
};
|
|
915
948
|
/** Data-only selection owned by the indexed UI layer. @public */
|
|
916
949
|
interface PretableIndexedSelectionState<TRowId extends PretableRowId, TColumnId extends string> {
|
|
917
950
|
readonly rows: PretableIndexedRowSelection<TRowId>;
|
|
@@ -974,6 +1007,17 @@ interface PretableGridUiCore<TRow extends object, TRowId extends PretableRowId,
|
|
|
974
1007
|
readonly pageRows?: number;
|
|
975
1008
|
}) => void;
|
|
976
1009
|
readonly setSelection: (selection: PretableIndexedSelectionState<TRowId, ColumnIdOf<TColumns>>) => void;
|
|
1010
|
+
/**
|
|
1011
|
+
* Replace the row-checkbox slice, leaving the cell ranges and anchor alone.
|
|
1012
|
+
*
|
|
1013
|
+
* The write-side counterpart of `getState().selection.rows`. `setSelection`
|
|
1014
|
+
* cannot do this job: it takes the engine's own containers, which a consumer
|
|
1015
|
+
* has no way to construct.
|
|
1016
|
+
*
|
|
1017
|
+
* Idempotent — applying a value the slice already holds publishes nothing, so
|
|
1018
|
+
* a controlled caller can push on every render without looping.
|
|
1019
|
+
*/
|
|
1020
|
+
readonly setRowSelection: (rows: PretableRowSelectionState<TRowId>) => void;
|
|
977
1021
|
readonly toggleRowSelection: (rowId: TRowId) => void;
|
|
978
1022
|
readonly selectRowRange: (startRowId: TRowId, endRowId: TRowId) => void;
|
|
979
1023
|
readonly isRowSelected: (rowId: TRowId) => boolean;
|
|
@@ -1007,6 +1051,17 @@ interface CreateGridUiCoreOptions<TRow extends object, TRowId extends PretableRo
|
|
|
1007
1051
|
readonly viewport?: PretableViewportState;
|
|
1008
1052
|
}
|
|
1009
1053
|
|
|
1054
|
+
/**
|
|
1055
|
+
* Render the engine's row-checkbox slice as the shape a consumer can write
|
|
1056
|
+
* back — the inverse of {@link createIndexedRowSelection}.
|
|
1057
|
+
*
|
|
1058
|
+
* Sparse in, sparse out. A symbolic "all" stays two words, and a shift-checked
|
|
1059
|
+
* 100k-row span stays its two endpoint ids; nothing here walks a population.
|
|
1060
|
+
*
|
|
1061
|
+
* @public
|
|
1062
|
+
*/
|
|
1063
|
+
declare function describeRowSelection<TRowId extends PretableRowId>(rows: PretableIndexedRowSelection<TRowId>): PretableRowSelectionState<TRowId>;
|
|
1064
|
+
|
|
1010
1065
|
/**
|
|
1011
1066
|
* Half-open row index range — `start` inclusive, `end` exclusive — used to
|
|
1012
1067
|
* describe a visible row window without materializing the rows outside it.
|
|
@@ -1145,4 +1200,4 @@ declare const numberFormats: {
|
|
|
1145
1200
|
readonly accounting: (options: PretableCurrencyFormatOptions) => Intl.NumberFormatOptions;
|
|
1146
1201
|
};
|
|
1147
1202
|
|
|
1148
|
-
export { type AutosizeOptions, type ColumnAggregateValueOf, type ColumnAlign, type ColumnFilter, type ColumnIdOf, type ColumnOption, type ColumnType, type ColumnValueOf, type ColumnsOf, type CreateGridUiCoreOptions, type CreateLocalRowModelOptions, type CreateLocalRowModelWithDefaultIdOptions, type FilterOperator, type FilterValue, GROUP_COLUMN_ID, type PretableAggregateFormatInput, type PretableAggregateOutputOf, type PretableAggregateSpec, type PretableAggregatesFor, type PretableAggregator, type PretableBuiltinAggregate, type PretableCellAddress, type PretableCellRange, type PretableChangeOperation, type PretableChangeSequence, type PretableChangeSet, type PretableColumn, type PretableColumnAccessorKind, type PretableColumnCallbackContext, type PretableColumnDefinition, type PretableColumnDerivation, type PretableColumnHelper, type PretableColumnOptions, type PretableColumnType, type PretableColumnTypeFor, type PretableCompatibleAggregateSpec, type PretableCompatibleAggregator, type PretableCurrencyFormatOptions, type PretableDataRow, type PretableDerivationTransition, type PretableDerivationsFor, PretableDisposedModelError, type PretableDistinctColumnIdOf, type PretableDistinctValueOptions, type PretableDistinctValueQuery, type PretableDistinctValueResult, type PretableEditInput, type PretableEditState, type PretableEditStatus, type PretableExpansionDefault, type PretableExpansionState, type PretableFilterFor, type PretableFilterOperandFor, type PretableFocusDirection, type PretableFocusState, type PretableFormatInput, type PretableGridUiColumn, type PretableGridUiColumnLayout, type PretableGridUiCore, type PretableGridUiState, type PretableGroupColumnOptions, type PretableGroupId, type PretableGroupKey, type PretableGroupRow, type PretableIndexedCellAddress, type PretableIndexedCellRange, type PretableIndexedEditingState, type PretableIndexedFocusMovement, type PretableIndexedFocusState, type PretableIndexedRowRange, type PretableIndexedRowRangeIndex, type PretableIndexedRowSelection, type PretableIndexedSelectionState, type PretableIndexedSelectionSummary, PretableInvalidGroupKeyError, type PretableMatchingTotal, type PretableMoveFocusOptions, type PretableMutationIssue, type PretableMutationResult, type PretableProcessingAuthority, type PretableProcessingOptions, type PretableQueryFor, type PretableQueryTransition, PretableReentrantMutationError, type PretableResultMeta, type PretableRow, type PretableRowGroupFor, type PretableRowId, PretableRowIdentityChangeError, type PretableRowModel, PretableRowModelError, type PretableRowModelErrorCode, type PretableRowModelErrorContext, type PretableRowModelOperation, type PretableRowModelSnapshot, type PretableRowModelState, type PretableRowModelStatus, type PretableRowRange, type PretableRowUpdate, type PretableSelectionState, type PretableSortDirection, type PretableSortEntry, type PretableSortFor, type PretableTransaction, type PretableTransitionCancellationReason, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, type PretableViewportState, type PretableVisibleRow, type PretableVisibleRowField, type PretableVisibleRowRef, type Prettify, type RowIdOf, type RowOf, createColumnHelper, createGrid, createLocalRowModel, numberFormats };
|
|
1203
|
+
export { type AutosizeOptions, type ColumnAggregateValueOf, type ColumnAlign, type ColumnFilter, type ColumnIdOf, type ColumnOption, type ColumnType, type ColumnValueOf, type ColumnsOf, type CreateGridUiCoreOptions, type CreateLocalRowModelOptions, type CreateLocalRowModelWithDefaultIdOptions, type FilterOperator, type FilterValue, GROUP_COLUMN_ID, type PretableAggregateFormatInput, type PretableAggregateOutputOf, type PretableAggregateSpec, type PretableAggregatesFor, type PretableAggregator, type PretableBuiltinAggregate, type PretableCellAddress, type PretableCellRange, type PretableChangeOperation, type PretableChangeSequence, type PretableChangeSet, type PretableColumn, type PretableColumnAccessorKind, type PretableColumnCallbackContext, type PretableColumnDefinition, type PretableColumnDerivation, type PretableColumnHelper, type PretableColumnOptions, type PretableColumnType, type PretableColumnTypeFor, type PretableCompatibleAggregateSpec, type PretableCompatibleAggregator, type PretableCurrencyFormatOptions, type PretableDataRow, type PretableDerivationTransition, type PretableDerivationsFor, PretableDisposedModelError, type PretableDistinctColumnIdOf, type PretableDistinctValueOptions, type PretableDistinctValueQuery, type PretableDistinctValueResult, type PretableEditInput, type PretableEditState, type PretableEditStatus, type PretableExpansionDefault, type PretableExpansionState, type PretableFilterFor, type PretableFilterOperandFor, type PretableFocusDirection, type PretableFocusState, type PretableFormatInput, type PretableGridUiColumn, type PretableGridUiColumnLayout, type PretableGridUiCore, type PretableGridUiState, type PretableGroupColumnOptions, type PretableGroupId, type PretableGroupKey, type PretableGroupRow, type PretableIndexedCellAddress, type PretableIndexedCellRange, type PretableIndexedEditingState, type PretableIndexedFocusMovement, type PretableIndexedFocusState, type PretableIndexedRowRange, type PretableIndexedRowRangeIndex, type PretableIndexedRowSelection, type PretableIndexedSelectionState, type PretableIndexedSelectionSummary, PretableInvalidGroupKeyError, type PretableMatchingTotal, type PretableMoveFocusOptions, type PretableMutationIssue, type PretableMutationResult, type PretableProcessingAuthority, type PretableProcessingOptions, type PretableQueryFor, type PretableQueryTransition, PretableReentrantMutationError, type PretableResultMeta, type PretableRow, type PretableRowGroupFor, type PretableRowId, PretableRowIdentityChangeError, type PretableRowModel, PretableRowModelError, type PretableRowModelErrorCode, type PretableRowModelErrorContext, type PretableRowModelOperation, type PretableRowModelSnapshot, type PretableRowModelState, type PretableRowModelStatus, type PretableRowRange, type PretableRowSelectionState, type PretableRowUpdate, type PretableSelectionState, type PretableSortDirection, type PretableSortEntry, type PretableSortFor, type PretableTransaction, type PretableTransitionCancellationReason, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, type PretableViewportState, type PretableVisibleRow, type PretableVisibleRowField, type PretableVisibleRowRef, type Prettify, type RowIdOf, type RowOf, createColumnHelper, createGrid, createLocalRowModel, describeRowSelection, numberFormats };
|
package/dist/index.mjs
CHANGED
|
@@ -915,6 +915,72 @@ function isIndexedRowSelected(selection, ref, snapshot) {
|
|
|
915
915
|
return false;
|
|
916
916
|
return semanticRowSelected(rowSelectionProgram(selection, snapshot), ref.rowId);
|
|
917
917
|
}
|
|
918
|
+
function createIndexedRowSelection(requested, snapshot) {
|
|
919
|
+
let selection = createEmptyIndexedSelection();
|
|
920
|
+
if (requested.kind === "all") {
|
|
921
|
+
selection = selectAllVisibleRows(selection, snapshot);
|
|
922
|
+
} else {
|
|
923
|
+
for (const rowId of new Set(requested.rowIds)) {
|
|
924
|
+
selection = toggleIndexedRowSelection(selection, rowId, snapshot);
|
|
925
|
+
}
|
|
926
|
+
for (const range of requested.ranges ?? []) {
|
|
927
|
+
selection = selectIndexedRowRange(selection, range.startRowId, range.endRowId, snapshot);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
for (const rowId of new Set(requested.excludedRowIds)) {
|
|
931
|
+
if (!isIndexedRowSelected(selection, dataRef(rowId), snapshot))
|
|
932
|
+
continue;
|
|
933
|
+
selection = toggleIndexedRowSelection(selection, rowId, snapshot);
|
|
934
|
+
}
|
|
935
|
+
return selection.rows;
|
|
936
|
+
}
|
|
937
|
+
function describeRowSelection(rows) {
|
|
938
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
939
|
+
for (const range of rows.excludedRanges ?? []) {
|
|
940
|
+
excluded.add(range.startRowId);
|
|
941
|
+
excluded.add(range.endRowId);
|
|
942
|
+
}
|
|
943
|
+
const excludedRowIds = excluded.size === 0 ? {} : { excludedRowIds: Object.freeze([...excluded]) };
|
|
944
|
+
if (rows.kind === "all") {
|
|
945
|
+
return Object.freeze({ kind: "all", ...excludedRowIds });
|
|
946
|
+
}
|
|
947
|
+
const ranges = [...rows.ranges ?? []].map((range) => Object.freeze({ startRowId: range.startRowId, endRowId: range.endRowId }));
|
|
948
|
+
return Object.freeze({
|
|
949
|
+
kind: "explicit",
|
|
950
|
+
rowIds: Object.freeze([...rows.rowIds]),
|
|
951
|
+
...ranges.length === 0 ? {} : { ranges: Object.freeze(ranges) },
|
|
952
|
+
...excludedRowIds
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
function sameIndexedRowSelectionValue(left, right) {
|
|
956
|
+
if (left === right)
|
|
957
|
+
return true;
|
|
958
|
+
if (left.kind !== right.kind)
|
|
959
|
+
return false;
|
|
960
|
+
if (!sameRowRangeIndex(left.excludedRanges, right.excludedRanges))
|
|
961
|
+
return false;
|
|
962
|
+
if (left.kind !== "explicit" || right.kind !== "explicit")
|
|
963
|
+
return true;
|
|
964
|
+
if (left.rowIds.size !== right.rowIds.size)
|
|
965
|
+
return false;
|
|
966
|
+
for (const rowId of left.rowIds) {
|
|
967
|
+
if (!right.rowIds.has(rowId))
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
return sameRowRangeIndex(left.ranges, right.ranges);
|
|
971
|
+
}
|
|
972
|
+
function sameRowRangeIndex(left, right) {
|
|
973
|
+
if (left === right)
|
|
974
|
+
return true;
|
|
975
|
+
if ((left?.size ?? 0) !== (right?.size ?? 0))
|
|
976
|
+
return false;
|
|
977
|
+
const leftRanges = [...left ?? []];
|
|
978
|
+
const rightRanges = [...right ?? []];
|
|
979
|
+
return leftRanges.every((range, index) => {
|
|
980
|
+
const other = rightRanges[index];
|
|
981
|
+
return other !== void 0 && sameRowId(range.startRowId, other.startRowId) && sameRowId(range.endRowId, other.endRowId);
|
|
982
|
+
});
|
|
983
|
+
}
|
|
918
984
|
function getIndexedSelectionSummary(selection, snapshot) {
|
|
919
985
|
const visibleCount2 = snapshot.visibleDataRowCount;
|
|
920
986
|
const selectedCount = projectionFor(rowSelectionProgram(selection, snapshot), snapshot).runs?.selectedCount ?? 0;
|
|
@@ -1321,6 +1387,22 @@ function createGridUiCore(options) {
|
|
|
1321
1387
|
publish({ ...state, selection: next });
|
|
1322
1388
|
});
|
|
1323
1389
|
},
|
|
1390
|
+
setRowSelection(rows) {
|
|
1391
|
+
command(() => {
|
|
1392
|
+
let nextRows;
|
|
1393
|
+
try {
|
|
1394
|
+
nextRows = createIndexedRowSelection(rows, snapshotForInteraction());
|
|
1395
|
+
} catch (cause) {
|
|
1396
|
+
throw observationError("The supplied row selection could not be applied atomically.", cause);
|
|
1397
|
+
}
|
|
1398
|
+
if (sameIndexedRowSelectionValue(state.selection.rows, nextRows))
|
|
1399
|
+
return;
|
|
1400
|
+
publish({
|
|
1401
|
+
...state,
|
|
1402
|
+
selection: Object.freeze({ ...state.selection, rows: nextRows })
|
|
1403
|
+
});
|
|
1404
|
+
});
|
|
1405
|
+
},
|
|
1324
1406
|
toggleRowSelection(rowId) {
|
|
1325
1407
|
command(() => {
|
|
1326
1408
|
let next;
|
|
@@ -8382,4 +8464,4 @@ var numberFormats = {
|
|
|
8382
8464
|
}
|
|
8383
8465
|
};
|
|
8384
8466
|
|
|
8385
|
-
export { GROUP_COLUMN_ID, PretableDisposedModelError, PretableInvalidGroupKeyError, PretableReentrantMutationError, PretableRowIdentityChangeError, PretableRowModelError, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, createColumnHelper2 as createColumnHelper, createGrid, createLocalRowModel2 as createLocalRowModel, numberFormats };
|
|
8467
|
+
export { GROUP_COLUMN_ID, PretableDisposedModelError, PretableInvalidGroupKeyError, PretableReentrantMutationError, PretableRowIdentityChangeError, PretableRowModelError, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, createColumnHelper2 as createColumnHelper, createGrid, createLocalRowModel2 as createLocalRowModel, describeRowSelection, numberFormats };
|