@pretable/core 0.8.0 → 0.9.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 +230 -16
- package/dist/index.d.cts +154 -1
- package/dist/index.d.ts +154 -1
- package/dist/index.mjs +230 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -992,6 +992,79 @@ function getIndexedSelectionSummary(selection, snapshot) {
|
|
|
992
992
|
visibleCount: visibleCount2
|
|
993
993
|
});
|
|
994
994
|
}
|
|
995
|
+
function datasetPosition(snapshot, rowId, loadedWindow) {
|
|
996
|
+
const rank = snapshot.dataIndexOf(dataRef(rowId));
|
|
997
|
+
if (rank < 0)
|
|
998
|
+
return -1;
|
|
999
|
+
return (loadedWindow?.start ?? 0) + rank;
|
|
1000
|
+
}
|
|
1001
|
+
function spanReadableInWindow(span, window) {
|
|
1002
|
+
return window.datasetKey !== void 0 && span.datasetKey === window.datasetKey;
|
|
1003
|
+
}
|
|
1004
|
+
function windowCarriesSpans(window) {
|
|
1005
|
+
return window !== null && window.datasetKey !== void 0;
|
|
1006
|
+
}
|
|
1007
|
+
function endpointPositions(range, snapshot, loadedWindow) {
|
|
1008
|
+
const liveStart = datasetPosition(snapshot, range.start.rowId, loadedWindow);
|
|
1009
|
+
const liveEnd = datasetPosition(snapshot, range.end.rowId, loadedWindow);
|
|
1010
|
+
const bothLive = liveStart >= 0 && liveEnd >= 0;
|
|
1011
|
+
if (bothLive)
|
|
1012
|
+
return { start: liveStart, end: liveEnd, bothLive };
|
|
1013
|
+
if (loadedWindow === null)
|
|
1014
|
+
return { start: void 0, end: void 0, bothLive };
|
|
1015
|
+
const remembered = range.datasetRowSpan !== void 0 && spanReadableInWindow(range.datasetRowSpan, loadedWindow) ? range.datasetRowSpan : void 0;
|
|
1016
|
+
return {
|
|
1017
|
+
start: liveStart >= 0 ? liveStart : remembered?.start,
|
|
1018
|
+
end: liveEnd >= 0 ? liveEnd : remembered?.end,
|
|
1019
|
+
bothLive
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
function rangeDatasetSpan(range, snapshot, loadedWindow) {
|
|
1023
|
+
const { start, end, bothLive } = endpointPositions(range, snapshot, loadedWindow);
|
|
1024
|
+
const low = start ?? end;
|
|
1025
|
+
const high = end ?? start;
|
|
1026
|
+
if (low === void 0 || high === void 0)
|
|
1027
|
+
return void 0;
|
|
1028
|
+
return {
|
|
1029
|
+
lo: Math.min(low, high),
|
|
1030
|
+
hi: Math.max(low, high),
|
|
1031
|
+
// Both endpoints present is not on its own enough to call the extent
|
|
1032
|
+
// proven. Under a window that CAN carry spans, a range without one has no
|
|
1033
|
+
// positional identity: reconciliation stripped it, which it only does
|
|
1034
|
+
// when it could not locate the range in the current population. The rows
|
|
1035
|
+
// it still names really are selected — so it paints — but the extent it
|
|
1036
|
+
// reports is a remnant, not what the user chose, and saying otherwise is
|
|
1037
|
+
// the same "silent under-count wearing a verified flag" this whole
|
|
1038
|
+
// design exists to remove.
|
|
1039
|
+
verified: bothLive && (!windowCarriesSpans(loadedWindow) || range.datasetRowSpan !== void 0)
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function getIndexedCellSelectionSummary(selection, snapshot, loadedWindow) {
|
|
1043
|
+
const window = loadedWindow ?? null;
|
|
1044
|
+
const spans = [];
|
|
1045
|
+
let verified = true;
|
|
1046
|
+
for (const range of selection.ranges) {
|
|
1047
|
+
const span = rangeDatasetSpan(range, snapshot, window);
|
|
1048
|
+
if (span === void 0) {
|
|
1049
|
+
verified = false;
|
|
1050
|
+
continue;
|
|
1051
|
+
}
|
|
1052
|
+
if (!span.verified)
|
|
1053
|
+
verified = false;
|
|
1054
|
+
spans.push(span);
|
|
1055
|
+
}
|
|
1056
|
+
spans.sort((left, right) => left.lo - right.lo);
|
|
1057
|
+
let rowCount = 0;
|
|
1058
|
+
let covered = null;
|
|
1059
|
+
for (const span of spans) {
|
|
1060
|
+
const lo = covered === null || span.lo > covered ? span.lo : covered + 1;
|
|
1061
|
+
if (span.hi >= lo)
|
|
1062
|
+
rowCount += span.hi - lo + 1;
|
|
1063
|
+
if (covered === null || span.hi > covered)
|
|
1064
|
+
covered = span.hi;
|
|
1065
|
+
}
|
|
1066
|
+
return Object.freeze({ rowCount, verified });
|
|
1067
|
+
}
|
|
995
1068
|
function visibleAddress(address, snapshot) {
|
|
996
1069
|
return isVisibleData(snapshot, address.rowId);
|
|
997
1070
|
}
|
|
@@ -1041,7 +1114,84 @@ function projectIndexedSelection(selection, previousSnapshot, snapshot, sequence
|
|
|
1041
1114
|
const rows = cloneRowsWithProgram(selection.rows, nextProgram);
|
|
1042
1115
|
return Object.freeze({ ...selection, rows });
|
|
1043
1116
|
}
|
|
1044
|
-
function
|
|
1117
|
+
function provenDeletedRow(rowId, loadedWindow, previous) {
|
|
1118
|
+
if (previous === void 0 || previous.window == null)
|
|
1119
|
+
return false;
|
|
1120
|
+
const previousRank = previous.snapshot.dataIndexOf(dataRef(rowId));
|
|
1121
|
+
if (previousRank < 0)
|
|
1122
|
+
return false;
|
|
1123
|
+
const previousAbsolute = previous.window.start + previousRank;
|
|
1124
|
+
return previousAbsolute >= loadedWindow.start && previousAbsolute < loadedWindow.start + loadedWindow.length;
|
|
1125
|
+
}
|
|
1126
|
+
function sameSpan(left, right) {
|
|
1127
|
+
if (left === right)
|
|
1128
|
+
return true;
|
|
1129
|
+
if (left === void 0 || right === void 0)
|
|
1130
|
+
return false;
|
|
1131
|
+
return left.start === right.start && left.end === right.end && left.datasetKey === right.datasetKey;
|
|
1132
|
+
}
|
|
1133
|
+
function withoutDatasetRowSpan(range) {
|
|
1134
|
+
if (range.datasetRowSpan === void 0)
|
|
1135
|
+
return range;
|
|
1136
|
+
return Object.freeze({ start: range.start, end: range.end });
|
|
1137
|
+
}
|
|
1138
|
+
function stampDatasetRowSpan(range, snapshot, loadedWindow) {
|
|
1139
|
+
if (loadedWindow === null)
|
|
1140
|
+
return range;
|
|
1141
|
+
if (!windowCarriesSpans(loadedWindow))
|
|
1142
|
+
return withoutDatasetRowSpan(range);
|
|
1143
|
+
const { start, end } = endpointPositions(range, snapshot, loadedWindow);
|
|
1144
|
+
if (start === void 0 || end === void 0) {
|
|
1145
|
+
return range.datasetRowSpan === void 0 || spanReadableInWindow(range.datasetRowSpan, loadedWindow) ? range : withoutDatasetRowSpan(range);
|
|
1146
|
+
}
|
|
1147
|
+
const next = Object.freeze({
|
|
1148
|
+
start,
|
|
1149
|
+
end,
|
|
1150
|
+
datasetKey: loadedWindow.datasetKey
|
|
1151
|
+
});
|
|
1152
|
+
if (sameSpan(range.datasetRowSpan, next))
|
|
1153
|
+
return range;
|
|
1154
|
+
return Object.freeze({ ...range, datasetRowSpan: next });
|
|
1155
|
+
}
|
|
1156
|
+
function adoptIndexedCellRangeSpans(ranges, replaced, snapshot, loadedWindow) {
|
|
1157
|
+
if (!windowCarriesSpans(loadedWindow))
|
|
1158
|
+
return ranges.map((range) => stampDatasetRowSpan(range, snapshot, loadedWindow));
|
|
1159
|
+
const remembered = /* @__PURE__ */ new Map();
|
|
1160
|
+
for (const range of replaced) {
|
|
1161
|
+
const span = range.datasetRowSpan;
|
|
1162
|
+
if (span === void 0)
|
|
1163
|
+
continue;
|
|
1164
|
+
if (!spanReadableInWindow(span, loadedWindow))
|
|
1165
|
+
continue;
|
|
1166
|
+
if (!remembered.has(range.start.rowId))
|
|
1167
|
+
remembered.set(range.start.rowId, span.start);
|
|
1168
|
+
if (!remembered.has(range.end.rowId))
|
|
1169
|
+
remembered.set(range.end.rowId, span.end);
|
|
1170
|
+
}
|
|
1171
|
+
return ranges.map((range) => {
|
|
1172
|
+
const own = endpointPositions(range, snapshot, loadedWindow);
|
|
1173
|
+
const start = own.start ?? remembered.get(range.start.rowId);
|
|
1174
|
+
const end = own.end ?? remembered.get(range.end.rowId);
|
|
1175
|
+
if (start === void 0 || end === void 0)
|
|
1176
|
+
return stampDatasetRowSpan(range, snapshot, loadedWindow);
|
|
1177
|
+
const next = Object.freeze({
|
|
1178
|
+
start,
|
|
1179
|
+
end,
|
|
1180
|
+
datasetKey: loadedWindow.datasetKey
|
|
1181
|
+
});
|
|
1182
|
+
if (sameSpan(range.datasetRowSpan, next))
|
|
1183
|
+
return range;
|
|
1184
|
+
return Object.freeze({ ...range, datasetRowSpan: next });
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
function reconcileIndexedSelection(selection, snapshot, eviction) {
|
|
1188
|
+
const suppliedWindow = eviction?.window ?? null;
|
|
1189
|
+
const previous = eviction?.previous;
|
|
1190
|
+
const populationChanged = suppliedWindow !== null && previous?.window != null && // Value comparison, not `spanReadableInWindow`: two keyless windows are
|
|
1191
|
+
// not evidence of a change. A keyless consumer gets no span trust at all
|
|
1192
|
+
// (see `windowCarriesSpans`), so there is nothing here to invalidate.
|
|
1193
|
+
previous.window.datasetKey !== suppliedWindow.datasetKey;
|
|
1194
|
+
const retentionWindow = populationChanged ? null : suppliedWindow;
|
|
1045
1195
|
let changed = false;
|
|
1046
1196
|
rowSelectionProgram(selection, snapshot);
|
|
1047
1197
|
const ranges = [];
|
|
@@ -1049,11 +1199,41 @@ function reconcileIndexedSelection(selection, snapshot) {
|
|
|
1049
1199
|
const startVisible = visibleAddress(range.start, snapshot);
|
|
1050
1200
|
const endVisible = visibleAddress(range.end, snapshot);
|
|
1051
1201
|
if (startVisible && endVisible) {
|
|
1052
|
-
|
|
1202
|
+
const stamped = stampDatasetRowSpan(range, snapshot, suppliedWindow);
|
|
1203
|
+
if (stamped !== range)
|
|
1204
|
+
changed = true;
|
|
1205
|
+
ranges.push(stamped);
|
|
1053
1206
|
} else if (startVisible || endVisible) {
|
|
1054
1207
|
const survivor = startVisible ? range.start : range.end;
|
|
1055
|
-
|
|
1056
|
-
|
|
1208
|
+
const absentee = startVisible ? range.end : range.start;
|
|
1209
|
+
if (retentionWindow === null || provenDeletedRow(absentee.rowId, retentionWindow, previous)) {
|
|
1210
|
+
ranges.push(stampDatasetRowSpan(
|
|
1211
|
+
Object.freeze({ start: survivor, end: survivor }),
|
|
1212
|
+
snapshot,
|
|
1213
|
+
// `retentionWindow`, not `suppliedWindow`. On a population change
|
|
1214
|
+
// this is null, so the collapsed range gets NO span — which is
|
|
1215
|
+
// the whole point: it is a remnant of a selection the engine
|
|
1216
|
+
// could not locate in the new population, and a span would let
|
|
1217
|
+
// the summary call its one surviving row a proven extent. See
|
|
1218
|
+
// `rangeDatasetSpan`, which reads a missing span under a
|
|
1219
|
+
// span-carrying window as exactly that doubt.
|
|
1220
|
+
retentionWindow
|
|
1221
|
+
));
|
|
1222
|
+
changed = true;
|
|
1223
|
+
} else {
|
|
1224
|
+
const retained = stampDatasetRowSpan(range, snapshot, retentionWindow);
|
|
1225
|
+
if (retained !== range)
|
|
1226
|
+
changed = true;
|
|
1227
|
+
ranges.push(retained);
|
|
1228
|
+
}
|
|
1229
|
+
} else if (retentionWindow != null) {
|
|
1230
|
+
const startDeleted = provenDeletedRow(range.start.rowId, retentionWindow, previous);
|
|
1231
|
+
const endDeleted = provenDeletedRow(range.end.rowId, retentionWindow, previous);
|
|
1232
|
+
if (startDeleted || endDeleted) {
|
|
1233
|
+
changed = true;
|
|
1234
|
+
} else {
|
|
1235
|
+
ranges.push(range);
|
|
1236
|
+
}
|
|
1057
1237
|
} else {
|
|
1058
1238
|
changed = true;
|
|
1059
1239
|
}
|
|
@@ -1135,7 +1315,7 @@ function orderPinnedColumns(columns) {
|
|
|
1135
1315
|
...columns.filter((column) => column.pinned === "right")
|
|
1136
1316
|
];
|
|
1137
1317
|
}
|
|
1138
|
-
function copySelection(selection) {
|
|
1318
|
+
function copySelection(selection, context) {
|
|
1139
1319
|
const rows = selection.rows.kind === "explicit" ? Object.freeze({
|
|
1140
1320
|
kind: "explicit",
|
|
1141
1321
|
rowIds: toImmutableIndexedSet(selection.rows.rowIds),
|
|
@@ -1148,10 +1328,15 @@ function copySelection(selection) {
|
|
|
1148
1328
|
preserveIndexedRowSelectionProgram(selection.rows, rows);
|
|
1149
1329
|
return Object.freeze({
|
|
1150
1330
|
rows,
|
|
1151
|
-
ranges: Object.freeze(selection.ranges.map((range) => Object.freeze({
|
|
1331
|
+
ranges: Object.freeze(adoptIndexedCellRangeSpans(selection.ranges.map((range) => Object.freeze({
|
|
1152
1332
|
start: Object.freeze({ ...range.start }),
|
|
1153
|
-
end: Object.freeze({ ...range.end })
|
|
1154
|
-
|
|
1333
|
+
end: Object.freeze({ ...range.end }),
|
|
1334
|
+
// Copied, not rebuilt from ids: this is the only public write
|
|
1335
|
+
// path, so dropping the span here un-counts every retained range
|
|
1336
|
+
// in the selection — including the ones the gesture never
|
|
1337
|
+
// touched.
|
|
1338
|
+
...range.datasetRowSpan === void 0 ? {} : { datasetRowSpan: Object.freeze({ ...range.datasetRowSpan }) }
|
|
1339
|
+
})), context.replaced, context.snapshot, context.loadedWindow)),
|
|
1155
1340
|
anchor: selection.anchor === null ? null : Object.freeze({ ...selection.anchor })
|
|
1156
1341
|
});
|
|
1157
1342
|
}
|
|
@@ -1185,6 +1370,13 @@ function sameRowRanges(left, right) {
|
|
|
1185
1370
|
return false;
|
|
1186
1371
|
}
|
|
1187
1372
|
}
|
|
1373
|
+
function sameDatasetRowSpan(left, right) {
|
|
1374
|
+
if (left === right)
|
|
1375
|
+
return true;
|
|
1376
|
+
if (left === void 0 || right === void 0)
|
|
1377
|
+
return false;
|
|
1378
|
+
return left.start === right.start && left.end === right.end && left.datasetKey === right.datasetKey;
|
|
1379
|
+
}
|
|
1188
1380
|
function sameSelection(left, right) {
|
|
1189
1381
|
if (left.rows.kind !== right.rows.kind)
|
|
1190
1382
|
return false;
|
|
@@ -1203,7 +1395,14 @@ function sameSelection(left, right) {
|
|
|
1203
1395
|
for (let index = 0; index < left.ranges.length; index += 1) {
|
|
1204
1396
|
const leftRange = left.ranges[index];
|
|
1205
1397
|
const rightRange = right.ranges[index];
|
|
1206
|
-
if (!sameValueZero(leftRange.start.rowId, rightRange.start.rowId) || leftRange.start.columnId !== rightRange.start.columnId || !sameValueZero(leftRange.end.rowId, rightRange.end.rowId) || leftRange.end.columnId !== rightRange.end.columnId
|
|
1398
|
+
if (!sameValueZero(leftRange.start.rowId, rightRange.start.rowId) || leftRange.start.columnId !== rightRange.start.columnId || !sameValueZero(leftRange.end.rowId, rightRange.end.rowId) || leftRange.end.columnId !== rightRange.end.columnId || // The span is part of a range's identity, not decoration on it: while
|
|
1399
|
+
// the rows are evicted it is the ONLY thing that says how large the
|
|
1400
|
+
// selection is, and two ranges over the same ids with different spans
|
|
1401
|
+
// select different numbers of rows. Comparing it is safe precisely
|
|
1402
|
+
// because `copySelection` recovers a missing span from the selection
|
|
1403
|
+
// being replaced — so a controlled `state` echo that drops the field
|
|
1404
|
+
// still compares equal, and the effect stays the no-op it has to be.
|
|
1405
|
+
!sameDatasetRowSpan(leftRange.datasetRowSpan, rightRange.datasetRowSpan)) {
|
|
1207
1406
|
return false;
|
|
1208
1407
|
}
|
|
1209
1408
|
}
|
|
@@ -1224,7 +1423,7 @@ function createGridUiCore(options) {
|
|
|
1224
1423
|
let draining = false;
|
|
1225
1424
|
let projecting = false;
|
|
1226
1425
|
let activeProjectionToken;
|
|
1227
|
-
let
|
|
1426
|
+
let observed;
|
|
1228
1427
|
let state = Object.freeze({
|
|
1229
1428
|
viewport: options.viewport ? normalizeViewport(options.viewport) : EMPTY_VIEWPORT,
|
|
1230
1429
|
focus: Object.freeze({ ref: null, columnId: null }),
|
|
@@ -1294,11 +1493,12 @@ function createGridUiCore(options) {
|
|
|
1294
1493
|
const observationError = (message, cause) => cause instanceof PretableGridUiError && cause.code === "row-model-observation-failed" ? cause : new PretableGridUiError("row-model-observation-failed", message, cause);
|
|
1295
1494
|
const snapshotForInteraction = () => {
|
|
1296
1495
|
try {
|
|
1297
|
-
return
|
|
1496
|
+
return observed?.snapshot ?? options.rowModel.getState().snapshot;
|
|
1298
1497
|
} catch (cause) {
|
|
1299
1498
|
throw new PretableGridUiError("row-model-observation-failed", "The row-model snapshot could not be read for a UI interaction.", cause);
|
|
1300
1499
|
}
|
|
1301
1500
|
};
|
|
1501
|
+
const interactionContext = () => observed ?? { snapshot: snapshotForInteraction(), window: null };
|
|
1302
1502
|
const navigationColumnIds = () => {
|
|
1303
1503
|
if (cachedNavigationLayout !== state.columnLayout) {
|
|
1304
1504
|
cachedNavigationLayout = state.columnLayout;
|
|
@@ -1311,7 +1511,7 @@ function createGridUiCore(options) {
|
|
|
1311
1511
|
return;
|
|
1312
1512
|
disposed = true;
|
|
1313
1513
|
activeProjectionToken = void 0;
|
|
1314
|
-
|
|
1514
|
+
observed = void 0;
|
|
1315
1515
|
releaseIndexedRowSelectionProgram(state.selection.rows);
|
|
1316
1516
|
queuedActions.length = 0;
|
|
1317
1517
|
const captured = Array.from(listeners);
|
|
@@ -1379,7 +1579,12 @@ function createGridUiCore(options) {
|
|
|
1379
1579
|
setSelection(selection) {
|
|
1380
1580
|
let next;
|
|
1381
1581
|
try {
|
|
1382
|
-
|
|
1582
|
+
const context = interactionContext();
|
|
1583
|
+
next = copySelection(selection, {
|
|
1584
|
+
replaced: state.selection.ranges,
|
|
1585
|
+
snapshot: context.snapshot,
|
|
1586
|
+
loadedWindow: context.window
|
|
1587
|
+
});
|
|
1383
1588
|
} catch (cause) {
|
|
1384
1589
|
throw new PretableGridUiError("invalid-ui-state", "The supplied selection could not be captured atomically.", cause);
|
|
1385
1590
|
}
|
|
@@ -1445,6 +1650,14 @@ function createGridUiCore(options) {
|
|
|
1445
1650
|
throw observationError("Indexed row selection summary could not be observed atomically.", cause);
|
|
1446
1651
|
}
|
|
1447
1652
|
},
|
|
1653
|
+
getCellSelectionSummary() {
|
|
1654
|
+
try {
|
|
1655
|
+
const context = interactionContext();
|
|
1656
|
+
return getIndexedCellSelectionSummary(state.selection, context.snapshot, context.window);
|
|
1657
|
+
} catch (cause) {
|
|
1658
|
+
throw observationError("Indexed cell selection summary could not be observed atomically.", cause);
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1448
1661
|
selectAllVisibleRows() {
|
|
1449
1662
|
command(() => {
|
|
1450
1663
|
let next;
|
|
@@ -1475,7 +1688,7 @@ function createGridUiCore(options) {
|
|
|
1475
1688
|
status: "editing"
|
|
1476
1689
|
});
|
|
1477
1690
|
command(() => {
|
|
1478
|
-
const snapshot =
|
|
1691
|
+
const snapshot = observed?.snapshot;
|
|
1479
1692
|
let visible = false;
|
|
1480
1693
|
try {
|
|
1481
1694
|
visible = snapshot !== void 0 && snapshot.indexOf({ kind: "data", rowId: input.rowId }) >= 0;
|
|
@@ -1619,7 +1832,8 @@ function createGridUiCore(options) {
|
|
|
1619
1832
|
return;
|
|
1620
1833
|
}
|
|
1621
1834
|
const focus = reconcileIndexedFocus(state.focus, snapshot);
|
|
1622
|
-
const
|
|
1835
|
+
const selectionWindow = options.getSelectionWindow?.() ?? null;
|
|
1836
|
+
const selection = reconcileIndexedSelection(observed === void 0 ? state.selection : projectIndexedSelection(state.selection, observed.snapshot, snapshot, options.rowModel.changesSince(observed.snapshot.revision)), snapshot, { window: selectionWindow, previous: observed });
|
|
1623
1837
|
let editing = state.editing;
|
|
1624
1838
|
if (editing !== null && snapshot.indexOf({ kind: "data", rowId: editing.rowId }) < 0) {
|
|
1625
1839
|
editing = null;
|
|
@@ -1634,7 +1848,7 @@ function createGridUiCore(options) {
|
|
|
1634
1848
|
}
|
|
1635
1849
|
if (disposed || activeProjectionToken !== token)
|
|
1636
1850
|
return;
|
|
1637
|
-
|
|
1851
|
+
observed = { snapshot, window: selectionWindow };
|
|
1638
1852
|
committed = true;
|
|
1639
1853
|
publish({
|
|
1640
1854
|
...state,
|
package/dist/index.d.cts
CHANGED
|
@@ -837,6 +837,17 @@ interface PretableCellRange {
|
|
|
837
837
|
endRowId: string;
|
|
838
838
|
startColumnId: string;
|
|
839
839
|
endColumnId: string;
|
|
840
|
+
/**
|
|
841
|
+
* Dataset positions of this range's endpoints, when the grid is serving a
|
|
842
|
+
* window under the honesty gate — see
|
|
843
|
+
* {@link PretableIndexedDatasetRowSpan}. Present on every range the grid
|
|
844
|
+
* emits through `onSelectionChange`, and accepted back through the
|
|
845
|
+
* controlled `state.selection` prop so a selection that is persisted and
|
|
846
|
+
* restored stays countable while its rows are evicted. Omitting it on the
|
|
847
|
+
* way back in is safe: the engine recovers the positions by row id from
|
|
848
|
+
* the selection it is replacing.
|
|
849
|
+
*/
|
|
850
|
+
datasetRowSpan?: PretableIndexedDatasetRowSpan;
|
|
840
851
|
}
|
|
841
852
|
/**
|
|
842
853
|
* Cell-range selection state including the optional anchor for shift-extension.
|
|
@@ -888,10 +899,72 @@ interface PretableIndexedCellAddress<TRowId extends PretableRowId, TColumnId ext
|
|
|
888
899
|
readonly rowId: TRowId;
|
|
889
900
|
readonly columnId: TColumnId;
|
|
890
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Where a cell range's two endpoints sit in the DATASET — the coordinate
|
|
904
|
+
* system `PretableIndexedSelectionWindow` is expressed in, not snapshot
|
|
905
|
+
* indices, which shift under the loaded window every time it moves.
|
|
906
|
+
*
|
|
907
|
+
* Under the honesty gate this is the range's IDENTITY, not an annotation on
|
|
908
|
+
* it: a range named by row ids stops meaning anything once those rows are
|
|
909
|
+
* evicted, because an id cannot be resolved to a position without the row.
|
|
910
|
+
* A dataset position survives the row. So `end - start + 1` stays answerable
|
|
911
|
+
* with nothing loaded, and so does "is this rendered row inside it?".
|
|
912
|
+
*
|
|
913
|
+
* `start`/`end` mirror the range's own `start`/`end` endpoints and are NOT
|
|
914
|
+
* normalized — `start` may exceed `end` for a range dragged upwards. Count
|
|
915
|
+
* and containment order them; keeping the orientation is what lets a range
|
|
916
|
+
* with one evicted endpoint resolve the survivor live and the absentee from
|
|
917
|
+
* memory, instead of guessing which remembered bound belongs to which.
|
|
918
|
+
*
|
|
919
|
+
* @public
|
|
920
|
+
*/
|
|
921
|
+
interface PretableIndexedDatasetRowSpan {
|
|
922
|
+
/** Dataset position of the range's `start` endpoint. */
|
|
923
|
+
readonly start: number;
|
|
924
|
+
/** Dataset position of the range's `end` endpoint. */
|
|
925
|
+
readonly end: number;
|
|
926
|
+
/**
|
|
927
|
+
* The population these positions were measured in — `resultMeta.datasetKey`
|
|
928
|
+
* as of the measurement. A re-sort or a filter change re-fills the same
|
|
929
|
+
* dataset positions with different rows, so a span carrying a different key
|
|
930
|
+
* than the window currently reports is not stale-but-usable, it is about a
|
|
931
|
+
* different table. Count and containment both refuse it rather than
|
|
932
|
+
* answering from it: `indexedRangeContainsCell` returns a bare boolean and
|
|
933
|
+
* has no `verified` channel to downgrade through, and a wrong `true` there
|
|
934
|
+
* paints the wrong rows.
|
|
935
|
+
*
|
|
936
|
+
* **This is load-bearing, and it fails CLOSED.** An absent key is not a
|
|
937
|
+
* match — it is the absence of any evidence about the population, which
|
|
938
|
+
* leaves the engine unable to tell a scroll from a re-sort, so it refuses.
|
|
939
|
+
* A grid that publishes `resultMeta.window` but no `resultMeta.datasetKey`
|
|
940
|
+
* therefore gets no span at all: its selections degrade to the loaded
|
|
941
|
+
* window, visibly, in `rowCount` and `verified`. `@pretable/react` warns
|
|
942
|
+
* once when it sees that combination.
|
|
943
|
+
*
|
|
944
|
+
* Local mode is a different case and is genuinely unaffected: with no
|
|
945
|
+
* window there are no dataset positions to record, so there is nothing a
|
|
946
|
+
* key could qualify.
|
|
947
|
+
*/
|
|
948
|
+
readonly datasetKey?: string;
|
|
949
|
+
}
|
|
891
950
|
/** Inclusive data-cell range; group rows can never be endpoints. @public */
|
|
892
951
|
interface PretableIndexedCellRange<TRowId extends PretableRowId, TColumnId extends string> {
|
|
893
952
|
readonly start: PretableIndexedCellAddress<TRowId, TColumnId>;
|
|
894
953
|
readonly end: PretableIndexedCellAddress<TRowId, TColumnId>;
|
|
954
|
+
/**
|
|
955
|
+
* Where `start` and `end` sit in the dataset. Absent in local mode and
|
|
956
|
+
* outside the honesty gate, where dataset positions are meaningless and
|
|
957
|
+
* every endpoint is loaded anyway.
|
|
958
|
+
*
|
|
959
|
+
* Derived by the engine on every write — `setSelection` fills it in from
|
|
960
|
+
* the loaded snapshot, and from the positions the selection being replaced
|
|
961
|
+
* already remembers, so a gesture extending from an EVICTED anchor still
|
|
962
|
+
* produces a countable range. Reconciliation refreshes it. A consumer that
|
|
963
|
+
* echoes a selection back through the controlled `state` prop may
|
|
964
|
+
* round-trip it verbatim, but does not have to: dropping it costs nothing,
|
|
965
|
+
* because the engine recovers it by row id from the selection it replaces.
|
|
966
|
+
*/
|
|
967
|
+
readonly datasetRowSpan?: PretableIndexedDatasetRowSpan;
|
|
895
968
|
}
|
|
896
969
|
/** Inclusive data-row span stored by its stable endpoint IDs. @public */
|
|
897
970
|
interface PretableIndexedRowRange<TRowId extends PretableRowId> {
|
|
@@ -951,12 +1024,70 @@ interface PretableIndexedSelectionState<TRowId extends PretableRowId, TColumnId
|
|
|
951
1024
|
readonly ranges: readonly PretableIndexedCellRange<TRowId, TColumnId>[];
|
|
952
1025
|
readonly anchor: PretableIndexedCellAddress<TRowId, TColumnId> | null;
|
|
953
1026
|
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Loaded span, in dataset-index terms, that `reconcileIndexedSelection` uses
|
|
1029
|
+
* to tell an evicted row (outside `[start, start + length)`) from a deleted
|
|
1030
|
+
* one (inside it) — see `resultMeta.window` on `PretableResultMeta`, which
|
|
1031
|
+
* this mirrors with `length` standing in for `rows.length`. `@internal`
|
|
1032
|
+
* rather than derived from `PretableResultMeta` directly: grid-core has no
|
|
1033
|
+
* dependency on the react-level honesty gate that decides whether a window
|
|
1034
|
+
* may be trusted, so callers pass this only once that gate has passed.
|
|
1035
|
+
*
|
|
1036
|
+
* @internal
|
|
1037
|
+
*/
|
|
1038
|
+
interface PretableIndexedSelectionWindow {
|
|
1039
|
+
readonly start: number;
|
|
1040
|
+
readonly length: number;
|
|
1041
|
+
/**
|
|
1042
|
+
* `resultMeta.datasetKey` for the population this window is a slice of.
|
|
1043
|
+
* Carried here rather than on a channel of its own because a span is only
|
|
1044
|
+
* meaningful paired with the population it was measured in, and the two
|
|
1045
|
+
* must never be able to disagree — see
|
|
1046
|
+
* {@link PretableIndexedDatasetRowSpan.datasetKey}.
|
|
1047
|
+
*
|
|
1048
|
+
* Absent switches spans off entirely for this window: none are recorded and
|
|
1049
|
+
* none are read back. That is fail-closed by design, not an oversight.
|
|
1050
|
+
*/
|
|
1051
|
+
readonly datasetKey?: string;
|
|
1052
|
+
}
|
|
954
1053
|
/** Header-checkbox state derived without visiting every visible row. @public */
|
|
955
1054
|
interface PretableIndexedSelectionSummary {
|
|
956
1055
|
readonly state: "none" | "some" | "all";
|
|
957
1056
|
readonly selectedCount: number;
|
|
958
1057
|
readonly visibleCount: number;
|
|
959
1058
|
}
|
|
1059
|
+
/**
|
|
1060
|
+
* How many data rows the CELL-RANGE slice covers — `ranges`, the slice a
|
|
1061
|
+
* click/shift-click/marquee builds. Distinct from
|
|
1062
|
+
* {@link PretableIndexedSelectionSummary}, which counts the separate sparse
|
|
1063
|
+
* row-selection program behind the checkbox column; the two answer different
|
|
1064
|
+
* questions and neither is derived from the other.
|
|
1065
|
+
*
|
|
1066
|
+
* @public
|
|
1067
|
+
*/
|
|
1068
|
+
interface PretableIndexedCellSelectionSummary {
|
|
1069
|
+
/**
|
|
1070
|
+
* Distinct data rows covered, counted by arithmetic over spans — O(ranges),
|
|
1071
|
+
* independent of how many rows are selected or how many are loaded.
|
|
1072
|
+
* Overlapping ranges are unioned, never double-counted.
|
|
1073
|
+
*/
|
|
1074
|
+
readonly rowCount: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* Whether every contributing range had both endpoints loaded, so
|
|
1077
|
+
* `rowCount` is a fact about rows that are provably still there.
|
|
1078
|
+
*
|
|
1079
|
+
* `false` means the count came wholly or partly from remembered dataset
|
|
1080
|
+
* positions: the rows are evicted, and a row deleted server-side while
|
|
1081
|
+
* evicted cannot be detected, so `rowCount` may overstate. It is still the
|
|
1082
|
+
* best available number — the loaded-rows-only alternative understates a
|
|
1083
|
+
* genuine selection by whatever fraction is evicted — but it may not be
|
|
1084
|
+
* presented as a proven one. Same rule as `PretableMatchingTotal`'s
|
|
1085
|
+
* `"exact" | "estimate"`: keep the number, qualify the claim, and let the
|
|
1086
|
+
* boundary that must speak a bare integer downgrade (see
|
|
1087
|
+
* `resolveAriaRowCount`).
|
|
1088
|
+
*/
|
|
1089
|
+
readonly verified: boolean;
|
|
1090
|
+
}
|
|
960
1091
|
/** Group and data rows share one focus path while preserving runtime identity. @public */
|
|
961
1092
|
interface PretableIndexedFocusState<TRowId extends PretableRowId, TColumnId extends string> {
|
|
962
1093
|
readonly ref: PretableVisibleRowRef<TRowId> | null;
|
|
@@ -1022,6 +1153,16 @@ interface PretableGridUiCore<TRow extends object, TRowId extends PretableRowId,
|
|
|
1022
1153
|
readonly selectRowRange: (startRowId: TRowId, endRowId: TRowId) => void;
|
|
1023
1154
|
readonly isRowSelected: (rowId: TRowId) => boolean;
|
|
1024
1155
|
readonly getSelectionSummary: () => PretableIndexedSelectionSummary;
|
|
1156
|
+
/**
|
|
1157
|
+
* How many data rows the CELL-RANGE slice covers, and whether that number
|
|
1158
|
+
* is proven. Counted by arithmetic over dataset spans, so it stays correct
|
|
1159
|
+
* — and O(ranges) — while most of the selection is evicted.
|
|
1160
|
+
*
|
|
1161
|
+
* A separate method from {@link getSelectionSummary} because they count
|
|
1162
|
+
* different slices: that one counts the sparse row-selection program the
|
|
1163
|
+
* checkbox column drives, this one counts `selection.ranges`.
|
|
1164
|
+
*/
|
|
1165
|
+
readonly getCellSelectionSummary: () => PretableIndexedCellSelectionSummary;
|
|
1025
1166
|
readonly selectAllVisibleRows: () => void;
|
|
1026
1167
|
readonly clearSelection: () => void;
|
|
1027
1168
|
readonly beginEdit: <TColumnId extends ColumnIdOf<TColumns>>(input: {
|
|
@@ -1049,6 +1190,18 @@ interface CreateGridUiCoreOptions<TRow extends object, TRowId extends PretableRo
|
|
|
1049
1190
|
readonly rowModel: PretableRowModel<TRow, TRowId, TColumns>;
|
|
1050
1191
|
readonly columns: readonly PretableGridUiColumn<ColumnIdOf<TColumns>>[];
|
|
1051
1192
|
readonly viewport?: PretableViewportState;
|
|
1193
|
+
/**
|
|
1194
|
+
* @internal Late-bound getter for the loaded span (dataset-index terms)
|
|
1195
|
+
* behind the same honesty gate as `aria-rowindex` and the scroll-extent
|
|
1196
|
+
* spacers — see `WindowSpacers`/`getWindowSpacers` in `@pretable/react`'s
|
|
1197
|
+
* `pretable-model.ts`, which this mirrors and is fed by. Read fresh on
|
|
1198
|
+
* every row-model revision (never cached) so `reconcileIndexedSelection`
|
|
1199
|
+
* can tell an evicted row from a deleted one — see
|
|
1200
|
+
* {@link PretableIndexedSelectionWindow}. Undefined, or a getter that
|
|
1201
|
+
* returns null, reproduces pre-eviction behavior exactly: every absent
|
|
1202
|
+
* row is treated as deleted.
|
|
1203
|
+
*/
|
|
1204
|
+
readonly getSelectionWindow?: () => PretableIndexedSelectionWindow | null;
|
|
1052
1205
|
}
|
|
1053
1206
|
|
|
1054
1207
|
/**
|
|
@@ -1200,4 +1353,4 @@ declare const numberFormats: {
|
|
|
1200
1353
|
readonly accounting: (options: PretableCurrencyFormatOptions) => Intl.NumberFormatOptions;
|
|
1201
1354
|
};
|
|
1202
1355
|
|
|
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 };
|
|
1356
|
+
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 PretableIndexedCellSelectionSummary, type PretableIndexedDatasetRowSpan, 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, type PretableIndexedSelectionWindow as ɵPretableIndexedSelectionWindow };
|
package/dist/index.d.ts
CHANGED
|
@@ -837,6 +837,17 @@ interface PretableCellRange {
|
|
|
837
837
|
endRowId: string;
|
|
838
838
|
startColumnId: string;
|
|
839
839
|
endColumnId: string;
|
|
840
|
+
/**
|
|
841
|
+
* Dataset positions of this range's endpoints, when the grid is serving a
|
|
842
|
+
* window under the honesty gate — see
|
|
843
|
+
* {@link PretableIndexedDatasetRowSpan}. Present on every range the grid
|
|
844
|
+
* emits through `onSelectionChange`, and accepted back through the
|
|
845
|
+
* controlled `state.selection` prop so a selection that is persisted and
|
|
846
|
+
* restored stays countable while its rows are evicted. Omitting it on the
|
|
847
|
+
* way back in is safe: the engine recovers the positions by row id from
|
|
848
|
+
* the selection it is replacing.
|
|
849
|
+
*/
|
|
850
|
+
datasetRowSpan?: PretableIndexedDatasetRowSpan;
|
|
840
851
|
}
|
|
841
852
|
/**
|
|
842
853
|
* Cell-range selection state including the optional anchor for shift-extension.
|
|
@@ -888,10 +899,72 @@ interface PretableIndexedCellAddress<TRowId extends PretableRowId, TColumnId ext
|
|
|
888
899
|
readonly rowId: TRowId;
|
|
889
900
|
readonly columnId: TColumnId;
|
|
890
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Where a cell range's two endpoints sit in the DATASET — the coordinate
|
|
904
|
+
* system `PretableIndexedSelectionWindow` is expressed in, not snapshot
|
|
905
|
+
* indices, which shift under the loaded window every time it moves.
|
|
906
|
+
*
|
|
907
|
+
* Under the honesty gate this is the range's IDENTITY, not an annotation on
|
|
908
|
+
* it: a range named by row ids stops meaning anything once those rows are
|
|
909
|
+
* evicted, because an id cannot be resolved to a position without the row.
|
|
910
|
+
* A dataset position survives the row. So `end - start + 1` stays answerable
|
|
911
|
+
* with nothing loaded, and so does "is this rendered row inside it?".
|
|
912
|
+
*
|
|
913
|
+
* `start`/`end` mirror the range's own `start`/`end` endpoints and are NOT
|
|
914
|
+
* normalized — `start` may exceed `end` for a range dragged upwards. Count
|
|
915
|
+
* and containment order them; keeping the orientation is what lets a range
|
|
916
|
+
* with one evicted endpoint resolve the survivor live and the absentee from
|
|
917
|
+
* memory, instead of guessing which remembered bound belongs to which.
|
|
918
|
+
*
|
|
919
|
+
* @public
|
|
920
|
+
*/
|
|
921
|
+
interface PretableIndexedDatasetRowSpan {
|
|
922
|
+
/** Dataset position of the range's `start` endpoint. */
|
|
923
|
+
readonly start: number;
|
|
924
|
+
/** Dataset position of the range's `end` endpoint. */
|
|
925
|
+
readonly end: number;
|
|
926
|
+
/**
|
|
927
|
+
* The population these positions were measured in — `resultMeta.datasetKey`
|
|
928
|
+
* as of the measurement. A re-sort or a filter change re-fills the same
|
|
929
|
+
* dataset positions with different rows, so a span carrying a different key
|
|
930
|
+
* than the window currently reports is not stale-but-usable, it is about a
|
|
931
|
+
* different table. Count and containment both refuse it rather than
|
|
932
|
+
* answering from it: `indexedRangeContainsCell` returns a bare boolean and
|
|
933
|
+
* has no `verified` channel to downgrade through, and a wrong `true` there
|
|
934
|
+
* paints the wrong rows.
|
|
935
|
+
*
|
|
936
|
+
* **This is load-bearing, and it fails CLOSED.** An absent key is not a
|
|
937
|
+
* match — it is the absence of any evidence about the population, which
|
|
938
|
+
* leaves the engine unable to tell a scroll from a re-sort, so it refuses.
|
|
939
|
+
* A grid that publishes `resultMeta.window` but no `resultMeta.datasetKey`
|
|
940
|
+
* therefore gets no span at all: its selections degrade to the loaded
|
|
941
|
+
* window, visibly, in `rowCount` and `verified`. `@pretable/react` warns
|
|
942
|
+
* once when it sees that combination.
|
|
943
|
+
*
|
|
944
|
+
* Local mode is a different case and is genuinely unaffected: with no
|
|
945
|
+
* window there are no dataset positions to record, so there is nothing a
|
|
946
|
+
* key could qualify.
|
|
947
|
+
*/
|
|
948
|
+
readonly datasetKey?: string;
|
|
949
|
+
}
|
|
891
950
|
/** Inclusive data-cell range; group rows can never be endpoints. @public */
|
|
892
951
|
interface PretableIndexedCellRange<TRowId extends PretableRowId, TColumnId extends string> {
|
|
893
952
|
readonly start: PretableIndexedCellAddress<TRowId, TColumnId>;
|
|
894
953
|
readonly end: PretableIndexedCellAddress<TRowId, TColumnId>;
|
|
954
|
+
/**
|
|
955
|
+
* Where `start` and `end` sit in the dataset. Absent in local mode and
|
|
956
|
+
* outside the honesty gate, where dataset positions are meaningless and
|
|
957
|
+
* every endpoint is loaded anyway.
|
|
958
|
+
*
|
|
959
|
+
* Derived by the engine on every write — `setSelection` fills it in from
|
|
960
|
+
* the loaded snapshot, and from the positions the selection being replaced
|
|
961
|
+
* already remembers, so a gesture extending from an EVICTED anchor still
|
|
962
|
+
* produces a countable range. Reconciliation refreshes it. A consumer that
|
|
963
|
+
* echoes a selection back through the controlled `state` prop may
|
|
964
|
+
* round-trip it verbatim, but does not have to: dropping it costs nothing,
|
|
965
|
+
* because the engine recovers it by row id from the selection it replaces.
|
|
966
|
+
*/
|
|
967
|
+
readonly datasetRowSpan?: PretableIndexedDatasetRowSpan;
|
|
895
968
|
}
|
|
896
969
|
/** Inclusive data-row span stored by its stable endpoint IDs. @public */
|
|
897
970
|
interface PretableIndexedRowRange<TRowId extends PretableRowId> {
|
|
@@ -951,12 +1024,70 @@ interface PretableIndexedSelectionState<TRowId extends PretableRowId, TColumnId
|
|
|
951
1024
|
readonly ranges: readonly PretableIndexedCellRange<TRowId, TColumnId>[];
|
|
952
1025
|
readonly anchor: PretableIndexedCellAddress<TRowId, TColumnId> | null;
|
|
953
1026
|
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Loaded span, in dataset-index terms, that `reconcileIndexedSelection` uses
|
|
1029
|
+
* to tell an evicted row (outside `[start, start + length)`) from a deleted
|
|
1030
|
+
* one (inside it) — see `resultMeta.window` on `PretableResultMeta`, which
|
|
1031
|
+
* this mirrors with `length` standing in for `rows.length`. `@internal`
|
|
1032
|
+
* rather than derived from `PretableResultMeta` directly: grid-core has no
|
|
1033
|
+
* dependency on the react-level honesty gate that decides whether a window
|
|
1034
|
+
* may be trusted, so callers pass this only once that gate has passed.
|
|
1035
|
+
*
|
|
1036
|
+
* @internal
|
|
1037
|
+
*/
|
|
1038
|
+
interface PretableIndexedSelectionWindow {
|
|
1039
|
+
readonly start: number;
|
|
1040
|
+
readonly length: number;
|
|
1041
|
+
/**
|
|
1042
|
+
* `resultMeta.datasetKey` for the population this window is a slice of.
|
|
1043
|
+
* Carried here rather than on a channel of its own because a span is only
|
|
1044
|
+
* meaningful paired with the population it was measured in, and the two
|
|
1045
|
+
* must never be able to disagree — see
|
|
1046
|
+
* {@link PretableIndexedDatasetRowSpan.datasetKey}.
|
|
1047
|
+
*
|
|
1048
|
+
* Absent switches spans off entirely for this window: none are recorded and
|
|
1049
|
+
* none are read back. That is fail-closed by design, not an oversight.
|
|
1050
|
+
*/
|
|
1051
|
+
readonly datasetKey?: string;
|
|
1052
|
+
}
|
|
954
1053
|
/** Header-checkbox state derived without visiting every visible row. @public */
|
|
955
1054
|
interface PretableIndexedSelectionSummary {
|
|
956
1055
|
readonly state: "none" | "some" | "all";
|
|
957
1056
|
readonly selectedCount: number;
|
|
958
1057
|
readonly visibleCount: number;
|
|
959
1058
|
}
|
|
1059
|
+
/**
|
|
1060
|
+
* How many data rows the CELL-RANGE slice covers — `ranges`, the slice a
|
|
1061
|
+
* click/shift-click/marquee builds. Distinct from
|
|
1062
|
+
* {@link PretableIndexedSelectionSummary}, which counts the separate sparse
|
|
1063
|
+
* row-selection program behind the checkbox column; the two answer different
|
|
1064
|
+
* questions and neither is derived from the other.
|
|
1065
|
+
*
|
|
1066
|
+
* @public
|
|
1067
|
+
*/
|
|
1068
|
+
interface PretableIndexedCellSelectionSummary {
|
|
1069
|
+
/**
|
|
1070
|
+
* Distinct data rows covered, counted by arithmetic over spans — O(ranges),
|
|
1071
|
+
* independent of how many rows are selected or how many are loaded.
|
|
1072
|
+
* Overlapping ranges are unioned, never double-counted.
|
|
1073
|
+
*/
|
|
1074
|
+
readonly rowCount: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* Whether every contributing range had both endpoints loaded, so
|
|
1077
|
+
* `rowCount` is a fact about rows that are provably still there.
|
|
1078
|
+
*
|
|
1079
|
+
* `false` means the count came wholly or partly from remembered dataset
|
|
1080
|
+
* positions: the rows are evicted, and a row deleted server-side while
|
|
1081
|
+
* evicted cannot be detected, so `rowCount` may overstate. It is still the
|
|
1082
|
+
* best available number — the loaded-rows-only alternative understates a
|
|
1083
|
+
* genuine selection by whatever fraction is evicted — but it may not be
|
|
1084
|
+
* presented as a proven one. Same rule as `PretableMatchingTotal`'s
|
|
1085
|
+
* `"exact" | "estimate"`: keep the number, qualify the claim, and let the
|
|
1086
|
+
* boundary that must speak a bare integer downgrade (see
|
|
1087
|
+
* `resolveAriaRowCount`).
|
|
1088
|
+
*/
|
|
1089
|
+
readonly verified: boolean;
|
|
1090
|
+
}
|
|
960
1091
|
/** Group and data rows share one focus path while preserving runtime identity. @public */
|
|
961
1092
|
interface PretableIndexedFocusState<TRowId extends PretableRowId, TColumnId extends string> {
|
|
962
1093
|
readonly ref: PretableVisibleRowRef<TRowId> | null;
|
|
@@ -1022,6 +1153,16 @@ interface PretableGridUiCore<TRow extends object, TRowId extends PretableRowId,
|
|
|
1022
1153
|
readonly selectRowRange: (startRowId: TRowId, endRowId: TRowId) => void;
|
|
1023
1154
|
readonly isRowSelected: (rowId: TRowId) => boolean;
|
|
1024
1155
|
readonly getSelectionSummary: () => PretableIndexedSelectionSummary;
|
|
1156
|
+
/**
|
|
1157
|
+
* How many data rows the CELL-RANGE slice covers, and whether that number
|
|
1158
|
+
* is proven. Counted by arithmetic over dataset spans, so it stays correct
|
|
1159
|
+
* — and O(ranges) — while most of the selection is evicted.
|
|
1160
|
+
*
|
|
1161
|
+
* A separate method from {@link getSelectionSummary} because they count
|
|
1162
|
+
* different slices: that one counts the sparse row-selection program the
|
|
1163
|
+
* checkbox column drives, this one counts `selection.ranges`.
|
|
1164
|
+
*/
|
|
1165
|
+
readonly getCellSelectionSummary: () => PretableIndexedCellSelectionSummary;
|
|
1025
1166
|
readonly selectAllVisibleRows: () => void;
|
|
1026
1167
|
readonly clearSelection: () => void;
|
|
1027
1168
|
readonly beginEdit: <TColumnId extends ColumnIdOf<TColumns>>(input: {
|
|
@@ -1049,6 +1190,18 @@ interface CreateGridUiCoreOptions<TRow extends object, TRowId extends PretableRo
|
|
|
1049
1190
|
readonly rowModel: PretableRowModel<TRow, TRowId, TColumns>;
|
|
1050
1191
|
readonly columns: readonly PretableGridUiColumn<ColumnIdOf<TColumns>>[];
|
|
1051
1192
|
readonly viewport?: PretableViewportState;
|
|
1193
|
+
/**
|
|
1194
|
+
* @internal Late-bound getter for the loaded span (dataset-index terms)
|
|
1195
|
+
* behind the same honesty gate as `aria-rowindex` and the scroll-extent
|
|
1196
|
+
* spacers — see `WindowSpacers`/`getWindowSpacers` in `@pretable/react`'s
|
|
1197
|
+
* `pretable-model.ts`, which this mirrors and is fed by. Read fresh on
|
|
1198
|
+
* every row-model revision (never cached) so `reconcileIndexedSelection`
|
|
1199
|
+
* can tell an evicted row from a deleted one — see
|
|
1200
|
+
* {@link PretableIndexedSelectionWindow}. Undefined, or a getter that
|
|
1201
|
+
* returns null, reproduces pre-eviction behavior exactly: every absent
|
|
1202
|
+
* row is treated as deleted.
|
|
1203
|
+
*/
|
|
1204
|
+
readonly getSelectionWindow?: () => PretableIndexedSelectionWindow | null;
|
|
1052
1205
|
}
|
|
1053
1206
|
|
|
1054
1207
|
/**
|
|
@@ -1200,4 +1353,4 @@ declare const numberFormats: {
|
|
|
1200
1353
|
readonly accounting: (options: PretableCurrencyFormatOptions) => Intl.NumberFormatOptions;
|
|
1201
1354
|
};
|
|
1202
1355
|
|
|
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 };
|
|
1356
|
+
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 PretableIndexedCellSelectionSummary, type PretableIndexedDatasetRowSpan, 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, type PretableIndexedSelectionWindow as ɵPretableIndexedSelectionWindow };
|
package/dist/index.mjs
CHANGED
|
@@ -990,6 +990,79 @@ function getIndexedSelectionSummary(selection, snapshot) {
|
|
|
990
990
|
visibleCount: visibleCount2
|
|
991
991
|
});
|
|
992
992
|
}
|
|
993
|
+
function datasetPosition(snapshot, rowId, loadedWindow) {
|
|
994
|
+
const rank = snapshot.dataIndexOf(dataRef(rowId));
|
|
995
|
+
if (rank < 0)
|
|
996
|
+
return -1;
|
|
997
|
+
return (loadedWindow?.start ?? 0) + rank;
|
|
998
|
+
}
|
|
999
|
+
function spanReadableInWindow(span, window) {
|
|
1000
|
+
return window.datasetKey !== void 0 && span.datasetKey === window.datasetKey;
|
|
1001
|
+
}
|
|
1002
|
+
function windowCarriesSpans(window) {
|
|
1003
|
+
return window !== null && window.datasetKey !== void 0;
|
|
1004
|
+
}
|
|
1005
|
+
function endpointPositions(range, snapshot, loadedWindow) {
|
|
1006
|
+
const liveStart = datasetPosition(snapshot, range.start.rowId, loadedWindow);
|
|
1007
|
+
const liveEnd = datasetPosition(snapshot, range.end.rowId, loadedWindow);
|
|
1008
|
+
const bothLive = liveStart >= 0 && liveEnd >= 0;
|
|
1009
|
+
if (bothLive)
|
|
1010
|
+
return { start: liveStart, end: liveEnd, bothLive };
|
|
1011
|
+
if (loadedWindow === null)
|
|
1012
|
+
return { start: void 0, end: void 0, bothLive };
|
|
1013
|
+
const remembered = range.datasetRowSpan !== void 0 && spanReadableInWindow(range.datasetRowSpan, loadedWindow) ? range.datasetRowSpan : void 0;
|
|
1014
|
+
return {
|
|
1015
|
+
start: liveStart >= 0 ? liveStart : remembered?.start,
|
|
1016
|
+
end: liveEnd >= 0 ? liveEnd : remembered?.end,
|
|
1017
|
+
bothLive
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
function rangeDatasetSpan(range, snapshot, loadedWindow) {
|
|
1021
|
+
const { start, end, bothLive } = endpointPositions(range, snapshot, loadedWindow);
|
|
1022
|
+
const low = start ?? end;
|
|
1023
|
+
const high = end ?? start;
|
|
1024
|
+
if (low === void 0 || high === void 0)
|
|
1025
|
+
return void 0;
|
|
1026
|
+
return {
|
|
1027
|
+
lo: Math.min(low, high),
|
|
1028
|
+
hi: Math.max(low, high),
|
|
1029
|
+
// Both endpoints present is not on its own enough to call the extent
|
|
1030
|
+
// proven. Under a window that CAN carry spans, a range without one has no
|
|
1031
|
+
// positional identity: reconciliation stripped it, which it only does
|
|
1032
|
+
// when it could not locate the range in the current population. The rows
|
|
1033
|
+
// it still names really are selected — so it paints — but the extent it
|
|
1034
|
+
// reports is a remnant, not what the user chose, and saying otherwise is
|
|
1035
|
+
// the same "silent under-count wearing a verified flag" this whole
|
|
1036
|
+
// design exists to remove.
|
|
1037
|
+
verified: bothLive && (!windowCarriesSpans(loadedWindow) || range.datasetRowSpan !== void 0)
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
function getIndexedCellSelectionSummary(selection, snapshot, loadedWindow) {
|
|
1041
|
+
const window = loadedWindow ?? null;
|
|
1042
|
+
const spans = [];
|
|
1043
|
+
let verified = true;
|
|
1044
|
+
for (const range of selection.ranges) {
|
|
1045
|
+
const span = rangeDatasetSpan(range, snapshot, window);
|
|
1046
|
+
if (span === void 0) {
|
|
1047
|
+
verified = false;
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
if (!span.verified)
|
|
1051
|
+
verified = false;
|
|
1052
|
+
spans.push(span);
|
|
1053
|
+
}
|
|
1054
|
+
spans.sort((left, right) => left.lo - right.lo);
|
|
1055
|
+
let rowCount = 0;
|
|
1056
|
+
let covered = null;
|
|
1057
|
+
for (const span of spans) {
|
|
1058
|
+
const lo = covered === null || span.lo > covered ? span.lo : covered + 1;
|
|
1059
|
+
if (span.hi >= lo)
|
|
1060
|
+
rowCount += span.hi - lo + 1;
|
|
1061
|
+
if (covered === null || span.hi > covered)
|
|
1062
|
+
covered = span.hi;
|
|
1063
|
+
}
|
|
1064
|
+
return Object.freeze({ rowCount, verified });
|
|
1065
|
+
}
|
|
993
1066
|
function visibleAddress(address, snapshot) {
|
|
994
1067
|
return isVisibleData(snapshot, address.rowId);
|
|
995
1068
|
}
|
|
@@ -1039,7 +1112,84 @@ function projectIndexedSelection(selection, previousSnapshot, snapshot, sequence
|
|
|
1039
1112
|
const rows = cloneRowsWithProgram(selection.rows, nextProgram);
|
|
1040
1113
|
return Object.freeze({ ...selection, rows });
|
|
1041
1114
|
}
|
|
1042
|
-
function
|
|
1115
|
+
function provenDeletedRow(rowId, loadedWindow, previous) {
|
|
1116
|
+
if (previous === void 0 || previous.window == null)
|
|
1117
|
+
return false;
|
|
1118
|
+
const previousRank = previous.snapshot.dataIndexOf(dataRef(rowId));
|
|
1119
|
+
if (previousRank < 0)
|
|
1120
|
+
return false;
|
|
1121
|
+
const previousAbsolute = previous.window.start + previousRank;
|
|
1122
|
+
return previousAbsolute >= loadedWindow.start && previousAbsolute < loadedWindow.start + loadedWindow.length;
|
|
1123
|
+
}
|
|
1124
|
+
function sameSpan(left, right) {
|
|
1125
|
+
if (left === right)
|
|
1126
|
+
return true;
|
|
1127
|
+
if (left === void 0 || right === void 0)
|
|
1128
|
+
return false;
|
|
1129
|
+
return left.start === right.start && left.end === right.end && left.datasetKey === right.datasetKey;
|
|
1130
|
+
}
|
|
1131
|
+
function withoutDatasetRowSpan(range) {
|
|
1132
|
+
if (range.datasetRowSpan === void 0)
|
|
1133
|
+
return range;
|
|
1134
|
+
return Object.freeze({ start: range.start, end: range.end });
|
|
1135
|
+
}
|
|
1136
|
+
function stampDatasetRowSpan(range, snapshot, loadedWindow) {
|
|
1137
|
+
if (loadedWindow === null)
|
|
1138
|
+
return range;
|
|
1139
|
+
if (!windowCarriesSpans(loadedWindow))
|
|
1140
|
+
return withoutDatasetRowSpan(range);
|
|
1141
|
+
const { start, end } = endpointPositions(range, snapshot, loadedWindow);
|
|
1142
|
+
if (start === void 0 || end === void 0) {
|
|
1143
|
+
return range.datasetRowSpan === void 0 || spanReadableInWindow(range.datasetRowSpan, loadedWindow) ? range : withoutDatasetRowSpan(range);
|
|
1144
|
+
}
|
|
1145
|
+
const next = Object.freeze({
|
|
1146
|
+
start,
|
|
1147
|
+
end,
|
|
1148
|
+
datasetKey: loadedWindow.datasetKey
|
|
1149
|
+
});
|
|
1150
|
+
if (sameSpan(range.datasetRowSpan, next))
|
|
1151
|
+
return range;
|
|
1152
|
+
return Object.freeze({ ...range, datasetRowSpan: next });
|
|
1153
|
+
}
|
|
1154
|
+
function adoptIndexedCellRangeSpans(ranges, replaced, snapshot, loadedWindow) {
|
|
1155
|
+
if (!windowCarriesSpans(loadedWindow))
|
|
1156
|
+
return ranges.map((range) => stampDatasetRowSpan(range, snapshot, loadedWindow));
|
|
1157
|
+
const remembered = /* @__PURE__ */ new Map();
|
|
1158
|
+
for (const range of replaced) {
|
|
1159
|
+
const span = range.datasetRowSpan;
|
|
1160
|
+
if (span === void 0)
|
|
1161
|
+
continue;
|
|
1162
|
+
if (!spanReadableInWindow(span, loadedWindow))
|
|
1163
|
+
continue;
|
|
1164
|
+
if (!remembered.has(range.start.rowId))
|
|
1165
|
+
remembered.set(range.start.rowId, span.start);
|
|
1166
|
+
if (!remembered.has(range.end.rowId))
|
|
1167
|
+
remembered.set(range.end.rowId, span.end);
|
|
1168
|
+
}
|
|
1169
|
+
return ranges.map((range) => {
|
|
1170
|
+
const own = endpointPositions(range, snapshot, loadedWindow);
|
|
1171
|
+
const start = own.start ?? remembered.get(range.start.rowId);
|
|
1172
|
+
const end = own.end ?? remembered.get(range.end.rowId);
|
|
1173
|
+
if (start === void 0 || end === void 0)
|
|
1174
|
+
return stampDatasetRowSpan(range, snapshot, loadedWindow);
|
|
1175
|
+
const next = Object.freeze({
|
|
1176
|
+
start,
|
|
1177
|
+
end,
|
|
1178
|
+
datasetKey: loadedWindow.datasetKey
|
|
1179
|
+
});
|
|
1180
|
+
if (sameSpan(range.datasetRowSpan, next))
|
|
1181
|
+
return range;
|
|
1182
|
+
return Object.freeze({ ...range, datasetRowSpan: next });
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
function reconcileIndexedSelection(selection, snapshot, eviction) {
|
|
1186
|
+
const suppliedWindow = eviction?.window ?? null;
|
|
1187
|
+
const previous = eviction?.previous;
|
|
1188
|
+
const populationChanged = suppliedWindow !== null && previous?.window != null && // Value comparison, not `spanReadableInWindow`: two keyless windows are
|
|
1189
|
+
// not evidence of a change. A keyless consumer gets no span trust at all
|
|
1190
|
+
// (see `windowCarriesSpans`), so there is nothing here to invalidate.
|
|
1191
|
+
previous.window.datasetKey !== suppliedWindow.datasetKey;
|
|
1192
|
+
const retentionWindow = populationChanged ? null : suppliedWindow;
|
|
1043
1193
|
let changed = false;
|
|
1044
1194
|
rowSelectionProgram(selection, snapshot);
|
|
1045
1195
|
const ranges = [];
|
|
@@ -1047,11 +1197,41 @@ function reconcileIndexedSelection(selection, snapshot) {
|
|
|
1047
1197
|
const startVisible = visibleAddress(range.start, snapshot);
|
|
1048
1198
|
const endVisible = visibleAddress(range.end, snapshot);
|
|
1049
1199
|
if (startVisible && endVisible) {
|
|
1050
|
-
|
|
1200
|
+
const stamped = stampDatasetRowSpan(range, snapshot, suppliedWindow);
|
|
1201
|
+
if (stamped !== range)
|
|
1202
|
+
changed = true;
|
|
1203
|
+
ranges.push(stamped);
|
|
1051
1204
|
} else if (startVisible || endVisible) {
|
|
1052
1205
|
const survivor = startVisible ? range.start : range.end;
|
|
1053
|
-
|
|
1054
|
-
|
|
1206
|
+
const absentee = startVisible ? range.end : range.start;
|
|
1207
|
+
if (retentionWindow === null || provenDeletedRow(absentee.rowId, retentionWindow, previous)) {
|
|
1208
|
+
ranges.push(stampDatasetRowSpan(
|
|
1209
|
+
Object.freeze({ start: survivor, end: survivor }),
|
|
1210
|
+
snapshot,
|
|
1211
|
+
// `retentionWindow`, not `suppliedWindow`. On a population change
|
|
1212
|
+
// this is null, so the collapsed range gets NO span — which is
|
|
1213
|
+
// the whole point: it is a remnant of a selection the engine
|
|
1214
|
+
// could not locate in the new population, and a span would let
|
|
1215
|
+
// the summary call its one surviving row a proven extent. See
|
|
1216
|
+
// `rangeDatasetSpan`, which reads a missing span under a
|
|
1217
|
+
// span-carrying window as exactly that doubt.
|
|
1218
|
+
retentionWindow
|
|
1219
|
+
));
|
|
1220
|
+
changed = true;
|
|
1221
|
+
} else {
|
|
1222
|
+
const retained = stampDatasetRowSpan(range, snapshot, retentionWindow);
|
|
1223
|
+
if (retained !== range)
|
|
1224
|
+
changed = true;
|
|
1225
|
+
ranges.push(retained);
|
|
1226
|
+
}
|
|
1227
|
+
} else if (retentionWindow != null) {
|
|
1228
|
+
const startDeleted = provenDeletedRow(range.start.rowId, retentionWindow, previous);
|
|
1229
|
+
const endDeleted = provenDeletedRow(range.end.rowId, retentionWindow, previous);
|
|
1230
|
+
if (startDeleted || endDeleted) {
|
|
1231
|
+
changed = true;
|
|
1232
|
+
} else {
|
|
1233
|
+
ranges.push(range);
|
|
1234
|
+
}
|
|
1055
1235
|
} else {
|
|
1056
1236
|
changed = true;
|
|
1057
1237
|
}
|
|
@@ -1133,7 +1313,7 @@ function orderPinnedColumns(columns) {
|
|
|
1133
1313
|
...columns.filter((column) => column.pinned === "right")
|
|
1134
1314
|
];
|
|
1135
1315
|
}
|
|
1136
|
-
function copySelection(selection) {
|
|
1316
|
+
function copySelection(selection, context) {
|
|
1137
1317
|
const rows = selection.rows.kind === "explicit" ? Object.freeze({
|
|
1138
1318
|
kind: "explicit",
|
|
1139
1319
|
rowIds: toImmutableIndexedSet(selection.rows.rowIds),
|
|
@@ -1146,10 +1326,15 @@ function copySelection(selection) {
|
|
|
1146
1326
|
preserveIndexedRowSelectionProgram(selection.rows, rows);
|
|
1147
1327
|
return Object.freeze({
|
|
1148
1328
|
rows,
|
|
1149
|
-
ranges: Object.freeze(selection.ranges.map((range) => Object.freeze({
|
|
1329
|
+
ranges: Object.freeze(adoptIndexedCellRangeSpans(selection.ranges.map((range) => Object.freeze({
|
|
1150
1330
|
start: Object.freeze({ ...range.start }),
|
|
1151
|
-
end: Object.freeze({ ...range.end })
|
|
1152
|
-
|
|
1331
|
+
end: Object.freeze({ ...range.end }),
|
|
1332
|
+
// Copied, not rebuilt from ids: this is the only public write
|
|
1333
|
+
// path, so dropping the span here un-counts every retained range
|
|
1334
|
+
// in the selection — including the ones the gesture never
|
|
1335
|
+
// touched.
|
|
1336
|
+
...range.datasetRowSpan === void 0 ? {} : { datasetRowSpan: Object.freeze({ ...range.datasetRowSpan }) }
|
|
1337
|
+
})), context.replaced, context.snapshot, context.loadedWindow)),
|
|
1153
1338
|
anchor: selection.anchor === null ? null : Object.freeze({ ...selection.anchor })
|
|
1154
1339
|
});
|
|
1155
1340
|
}
|
|
@@ -1183,6 +1368,13 @@ function sameRowRanges(left, right) {
|
|
|
1183
1368
|
return false;
|
|
1184
1369
|
}
|
|
1185
1370
|
}
|
|
1371
|
+
function sameDatasetRowSpan(left, right) {
|
|
1372
|
+
if (left === right)
|
|
1373
|
+
return true;
|
|
1374
|
+
if (left === void 0 || right === void 0)
|
|
1375
|
+
return false;
|
|
1376
|
+
return left.start === right.start && left.end === right.end && left.datasetKey === right.datasetKey;
|
|
1377
|
+
}
|
|
1186
1378
|
function sameSelection(left, right) {
|
|
1187
1379
|
if (left.rows.kind !== right.rows.kind)
|
|
1188
1380
|
return false;
|
|
@@ -1201,7 +1393,14 @@ function sameSelection(left, right) {
|
|
|
1201
1393
|
for (let index = 0; index < left.ranges.length; index += 1) {
|
|
1202
1394
|
const leftRange = left.ranges[index];
|
|
1203
1395
|
const rightRange = right.ranges[index];
|
|
1204
|
-
if (!sameValueZero(leftRange.start.rowId, rightRange.start.rowId) || leftRange.start.columnId !== rightRange.start.columnId || !sameValueZero(leftRange.end.rowId, rightRange.end.rowId) || leftRange.end.columnId !== rightRange.end.columnId
|
|
1396
|
+
if (!sameValueZero(leftRange.start.rowId, rightRange.start.rowId) || leftRange.start.columnId !== rightRange.start.columnId || !sameValueZero(leftRange.end.rowId, rightRange.end.rowId) || leftRange.end.columnId !== rightRange.end.columnId || // The span is part of a range's identity, not decoration on it: while
|
|
1397
|
+
// the rows are evicted it is the ONLY thing that says how large the
|
|
1398
|
+
// selection is, and two ranges over the same ids with different spans
|
|
1399
|
+
// select different numbers of rows. Comparing it is safe precisely
|
|
1400
|
+
// because `copySelection` recovers a missing span from the selection
|
|
1401
|
+
// being replaced — so a controlled `state` echo that drops the field
|
|
1402
|
+
// still compares equal, and the effect stays the no-op it has to be.
|
|
1403
|
+
!sameDatasetRowSpan(leftRange.datasetRowSpan, rightRange.datasetRowSpan)) {
|
|
1205
1404
|
return false;
|
|
1206
1405
|
}
|
|
1207
1406
|
}
|
|
@@ -1222,7 +1421,7 @@ function createGridUiCore(options) {
|
|
|
1222
1421
|
let draining = false;
|
|
1223
1422
|
let projecting = false;
|
|
1224
1423
|
let activeProjectionToken;
|
|
1225
|
-
let
|
|
1424
|
+
let observed;
|
|
1226
1425
|
let state = Object.freeze({
|
|
1227
1426
|
viewport: options.viewport ? normalizeViewport(options.viewport) : EMPTY_VIEWPORT,
|
|
1228
1427
|
focus: Object.freeze({ ref: null, columnId: null }),
|
|
@@ -1292,11 +1491,12 @@ function createGridUiCore(options) {
|
|
|
1292
1491
|
const observationError = (message, cause) => cause instanceof PretableGridUiError && cause.code === "row-model-observation-failed" ? cause : new PretableGridUiError("row-model-observation-failed", message, cause);
|
|
1293
1492
|
const snapshotForInteraction = () => {
|
|
1294
1493
|
try {
|
|
1295
|
-
return
|
|
1494
|
+
return observed?.snapshot ?? options.rowModel.getState().snapshot;
|
|
1296
1495
|
} catch (cause) {
|
|
1297
1496
|
throw new PretableGridUiError("row-model-observation-failed", "The row-model snapshot could not be read for a UI interaction.", cause);
|
|
1298
1497
|
}
|
|
1299
1498
|
};
|
|
1499
|
+
const interactionContext = () => observed ?? { snapshot: snapshotForInteraction(), window: null };
|
|
1300
1500
|
const navigationColumnIds = () => {
|
|
1301
1501
|
if (cachedNavigationLayout !== state.columnLayout) {
|
|
1302
1502
|
cachedNavigationLayout = state.columnLayout;
|
|
@@ -1309,7 +1509,7 @@ function createGridUiCore(options) {
|
|
|
1309
1509
|
return;
|
|
1310
1510
|
disposed = true;
|
|
1311
1511
|
activeProjectionToken = void 0;
|
|
1312
|
-
|
|
1512
|
+
observed = void 0;
|
|
1313
1513
|
releaseIndexedRowSelectionProgram(state.selection.rows);
|
|
1314
1514
|
queuedActions.length = 0;
|
|
1315
1515
|
const captured = Array.from(listeners);
|
|
@@ -1377,7 +1577,12 @@ function createGridUiCore(options) {
|
|
|
1377
1577
|
setSelection(selection) {
|
|
1378
1578
|
let next;
|
|
1379
1579
|
try {
|
|
1380
|
-
|
|
1580
|
+
const context = interactionContext();
|
|
1581
|
+
next = copySelection(selection, {
|
|
1582
|
+
replaced: state.selection.ranges,
|
|
1583
|
+
snapshot: context.snapshot,
|
|
1584
|
+
loadedWindow: context.window
|
|
1585
|
+
});
|
|
1381
1586
|
} catch (cause) {
|
|
1382
1587
|
throw new PretableGridUiError("invalid-ui-state", "The supplied selection could not be captured atomically.", cause);
|
|
1383
1588
|
}
|
|
@@ -1443,6 +1648,14 @@ function createGridUiCore(options) {
|
|
|
1443
1648
|
throw observationError("Indexed row selection summary could not be observed atomically.", cause);
|
|
1444
1649
|
}
|
|
1445
1650
|
},
|
|
1651
|
+
getCellSelectionSummary() {
|
|
1652
|
+
try {
|
|
1653
|
+
const context = interactionContext();
|
|
1654
|
+
return getIndexedCellSelectionSummary(state.selection, context.snapshot, context.window);
|
|
1655
|
+
} catch (cause) {
|
|
1656
|
+
throw observationError("Indexed cell selection summary could not be observed atomically.", cause);
|
|
1657
|
+
}
|
|
1658
|
+
},
|
|
1446
1659
|
selectAllVisibleRows() {
|
|
1447
1660
|
command(() => {
|
|
1448
1661
|
let next;
|
|
@@ -1473,7 +1686,7 @@ function createGridUiCore(options) {
|
|
|
1473
1686
|
status: "editing"
|
|
1474
1687
|
});
|
|
1475
1688
|
command(() => {
|
|
1476
|
-
const snapshot =
|
|
1689
|
+
const snapshot = observed?.snapshot;
|
|
1477
1690
|
let visible = false;
|
|
1478
1691
|
try {
|
|
1479
1692
|
visible = snapshot !== void 0 && snapshot.indexOf({ kind: "data", rowId: input.rowId }) >= 0;
|
|
@@ -1617,7 +1830,8 @@ function createGridUiCore(options) {
|
|
|
1617
1830
|
return;
|
|
1618
1831
|
}
|
|
1619
1832
|
const focus = reconcileIndexedFocus(state.focus, snapshot);
|
|
1620
|
-
const
|
|
1833
|
+
const selectionWindow = options.getSelectionWindow?.() ?? null;
|
|
1834
|
+
const selection = reconcileIndexedSelection(observed === void 0 ? state.selection : projectIndexedSelection(state.selection, observed.snapshot, snapshot, options.rowModel.changesSince(observed.snapshot.revision)), snapshot, { window: selectionWindow, previous: observed });
|
|
1621
1835
|
let editing = state.editing;
|
|
1622
1836
|
if (editing !== null && snapshot.indexOf({ kind: "data", rowId: editing.rowId }) < 0) {
|
|
1623
1837
|
editing = null;
|
|
@@ -1632,7 +1846,7 @@ function createGridUiCore(options) {
|
|
|
1632
1846
|
}
|
|
1633
1847
|
if (disposed || activeProjectionToken !== token)
|
|
1634
1848
|
return;
|
|
1635
|
-
|
|
1849
|
+
observed = { snapshot, window: selectionWindow };
|
|
1636
1850
|
committed = true;
|
|
1637
1851
|
publish({
|
|
1638
1852
|
...state,
|