@react-stately/layout 4.6.0 → 4.7.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/import.mjs +2 -8
- package/dist/main.js +5 -11
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -8
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +15 -17
- package/src/index.ts +2 -8
- package/dist/GridLayout.main.js +0 -238
- package/dist/GridLayout.main.js.map +0 -1
- package/dist/GridLayout.mjs +0 -233
- package/dist/GridLayout.module.js +0 -233
- package/dist/GridLayout.module.js.map +0 -1
- package/dist/ListLayout.main.js +0 -467
- package/dist/ListLayout.main.js.map +0 -1
- package/dist/ListLayout.mjs +0 -462
- package/dist/ListLayout.module.js +0 -462
- package/dist/ListLayout.module.js.map +0 -1
- package/dist/TableLayout.main.js +0 -511
- package/dist/TableLayout.main.js.map +0 -1
- package/dist/TableLayout.mjs +0 -506
- package/dist/TableLayout.module.js +0 -506
- package/dist/TableLayout.module.js.map +0 -1
- package/dist/WaterfallLayout.main.js +0 -237
- package/dist/WaterfallLayout.main.js.map +0 -1
- package/dist/WaterfallLayout.mjs +0 -232
- package/dist/WaterfallLayout.module.js +0 -232
- package/dist/WaterfallLayout.module.js.map +0 -1
- package/dist/types.d.ts +0 -241
- package/dist/types.d.ts.map +0 -1
- package/src/GridLayout.ts +0 -381
- package/src/ListLayout.ts +0 -636
- package/src/TableLayout.ts +0 -634
- package/src/WaterfallLayout.ts +0 -345
package/dist/TableLayout.mjs
DELETED
|
@@ -1,506 +0,0 @@
|
|
|
1
|
-
import {ListLayout as $61ef60fc9b1041f4$export$cacbb3924155d68e} from "./ListLayout.mjs";
|
|
2
|
-
import {getChildNodes as $bmsJv$getChildNodes, getLastItem as $bmsJv$getLastItem} from "@react-stately/collections";
|
|
3
|
-
import {Size as $bmsJv$Size, Rect as $bmsJv$Rect, LayoutInfo as $bmsJv$LayoutInfo} from "@react-stately/virtualizer";
|
|
4
|
-
import {TableColumnLayout as $bmsJv$TableColumnLayout} from "@react-stately/table";
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
-
* governing permissions and limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const $a152112e902709bf$var$DEFAULT_ROW_HEIGHT = 48;
|
|
21
|
-
class $a152112e902709bf$export$62444c3c724b1b20 extends (0, $61ef60fc9b1041f4$export$cacbb3924155d68e) {
|
|
22
|
-
// Backward compatibility for subclassing.
|
|
23
|
-
get collection() {
|
|
24
|
-
return this.virtualizer.collection;
|
|
25
|
-
}
|
|
26
|
-
columnsChanged(newCollection, oldCollection) {
|
|
27
|
-
return !oldCollection || newCollection.columns !== oldCollection.columns && newCollection.columns.length !== oldCollection.columns.length || newCollection.columns.some((c, i)=>c.key !== oldCollection.columns[i].key || c.props.width !== oldCollection.columns[i].props.width || c.props.minWidth !== oldCollection.columns[i].props.minWidth || c.props.maxWidth !== oldCollection.columns[i].props.maxWidth);
|
|
28
|
-
}
|
|
29
|
-
shouldInvalidateLayoutOptions(newOptions, oldOptions) {
|
|
30
|
-
return newOptions.columnWidths !== oldOptions.columnWidths || super.shouldInvalidateLayoutOptions(newOptions, oldOptions);
|
|
31
|
-
}
|
|
32
|
-
update(invalidationContext) {
|
|
33
|
-
var _invalidationContext_layoutOptions;
|
|
34
|
-
let newCollection = this.virtualizer.collection;
|
|
35
|
-
// If columnWidths were provided via layoutOptions, update those.
|
|
36
|
-
// Otherwise, calculate column widths ourselves.
|
|
37
|
-
if ((_invalidationContext_layoutOptions = invalidationContext.layoutOptions) === null || _invalidationContext_layoutOptions === void 0 ? void 0 : _invalidationContext_layoutOptions.columnWidths) {
|
|
38
|
-
for (const [key, val] of invalidationContext.layoutOptions.columnWidths)if (this.columnWidths.get(key) !== val) {
|
|
39
|
-
this.columnWidths = invalidationContext.layoutOptions.columnWidths;
|
|
40
|
-
invalidationContext.sizeChanged = true;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
} else if (invalidationContext.sizeChanged || this.columnsChanged(newCollection, this.lastCollection)) {
|
|
44
|
-
let columnLayout = new (0, $bmsJv$TableColumnLayout)({});
|
|
45
|
-
this.columnWidths = columnLayout.buildColumnWidths(this.virtualizer.visibleRect.width - this.padding * 2, newCollection, new Map());
|
|
46
|
-
invalidationContext.sizeChanged = true;
|
|
47
|
-
}
|
|
48
|
-
super.update(invalidationContext);
|
|
49
|
-
}
|
|
50
|
-
buildCollection() {
|
|
51
|
-
var _collection_head;
|
|
52
|
-
this.stickyColumnIndices = [];
|
|
53
|
-
let collection = this.virtualizer.collection;
|
|
54
|
-
if (((_collection_head = collection.head) === null || _collection_head === void 0 ? void 0 : _collection_head.key) === -1) return [];
|
|
55
|
-
for (let column of collection.columns)// The selection cell and any other sticky columns always need to be visible.
|
|
56
|
-
// In addition, row headers need to be in the DOM for accessibility labeling.
|
|
57
|
-
if (this.isStickyColumn(column) || collection.rowHeaderColumnKeys.has(column.key)) this.stickyColumnIndices.push(column.index);
|
|
58
|
-
let header = this.buildTableHeader();
|
|
59
|
-
this.layoutNodes.set(header.layoutInfo.key, header);
|
|
60
|
-
let body = this.buildBody(header.layoutInfo.rect.maxY + this.gap);
|
|
61
|
-
this.lastPersistedKeys = null;
|
|
62
|
-
body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);
|
|
63
|
-
this.contentSize = new (0, $bmsJv$Size)(body.layoutInfo.rect.width + this.padding * 2, body.layoutInfo.rect.maxY + this.padding);
|
|
64
|
-
return [
|
|
65
|
-
header,
|
|
66
|
-
body
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
buildTableHeader() {
|
|
70
|
-
var _collection_head;
|
|
71
|
-
let collection = this.virtualizer.collection;
|
|
72
|
-
let rect = new (0, $bmsJv$Rect)(this.padding, this.padding, 0, 0);
|
|
73
|
-
var _collection_head_key;
|
|
74
|
-
let layoutInfo = new (0, $bmsJv$LayoutInfo)('header', (_collection_head_key = (_collection_head = collection.head) === null || _collection_head === void 0 ? void 0 : _collection_head.key) !== null && _collection_head_key !== void 0 ? _collection_head_key : 'header', rect);
|
|
75
|
-
layoutInfo.isSticky = true;
|
|
76
|
-
layoutInfo.zIndex = 1;
|
|
77
|
-
let y = this.padding;
|
|
78
|
-
let width = 0;
|
|
79
|
-
let children = [];
|
|
80
|
-
for (let headerRow of collection.headerRows){
|
|
81
|
-
let layoutNode = this.buildChild(headerRow, this.padding, y, layoutInfo.key);
|
|
82
|
-
layoutNode.layoutInfo.parentKey = layoutInfo.key;
|
|
83
|
-
y = layoutNode.layoutInfo.rect.maxY;
|
|
84
|
-
width = Math.max(width, layoutNode.layoutInfo.rect.width);
|
|
85
|
-
layoutNode.index = children.length;
|
|
86
|
-
children.push(layoutNode);
|
|
87
|
-
}
|
|
88
|
-
rect.width = width;
|
|
89
|
-
rect.height = y - this.padding;
|
|
90
|
-
return {
|
|
91
|
-
layoutInfo: layoutInfo,
|
|
92
|
-
children: children,
|
|
93
|
-
validRect: layoutInfo.rect,
|
|
94
|
-
node: collection.head
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
buildHeaderRow(headerRow, x, y) {
|
|
98
|
-
let rect = new (0, $bmsJv$Rect)(x, y, 0, 0);
|
|
99
|
-
let row = new (0, $bmsJv$LayoutInfo)('headerrow', headerRow.key, rect);
|
|
100
|
-
let height = 0;
|
|
101
|
-
let columns = [];
|
|
102
|
-
for (let cell of (0, $bmsJv$getChildNodes)(headerRow, this.virtualizer.collection)){
|
|
103
|
-
let layoutNode = this.buildChild(cell, x, y, row.key);
|
|
104
|
-
layoutNode.layoutInfo.parentKey = row.key;
|
|
105
|
-
x = layoutNode.layoutInfo.rect.maxX;
|
|
106
|
-
height = Math.max(height, layoutNode.layoutInfo.rect.height);
|
|
107
|
-
layoutNode.index = columns.length;
|
|
108
|
-
columns.push(layoutNode);
|
|
109
|
-
}
|
|
110
|
-
for (let [i, layout] of columns.entries())layout.layoutInfo.zIndex = columns.length - i + 1;
|
|
111
|
-
this.setChildHeights(columns, height);
|
|
112
|
-
rect.height = height;
|
|
113
|
-
rect.width = x - rect.x;
|
|
114
|
-
return {
|
|
115
|
-
layoutInfo: row,
|
|
116
|
-
children: columns,
|
|
117
|
-
validRect: rect,
|
|
118
|
-
node: headerRow
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
setChildHeights(children, height) {
|
|
122
|
-
for (let child of children)if (child.layoutInfo.rect.height !== height) {
|
|
123
|
-
// Need to copy the layout info before we mutate it.
|
|
124
|
-
child.layoutInfo = child.layoutInfo.copy();
|
|
125
|
-
child.layoutInfo.rect.height = height;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// used to get the column widths when rendering to the DOM
|
|
129
|
-
getRenderedColumnWidth(node) {
|
|
130
|
-
let collection = this.virtualizer.collection;
|
|
131
|
-
var _node_colSpan;
|
|
132
|
-
let colSpan = (_node_colSpan = node.colSpan) !== null && _node_colSpan !== void 0 ? _node_colSpan : 1;
|
|
133
|
-
var _node_colIndex;
|
|
134
|
-
let colIndex = (_node_colIndex = node.colIndex) !== null && _node_colIndex !== void 0 ? _node_colIndex : node.index;
|
|
135
|
-
let width = 0;
|
|
136
|
-
for(let i = colIndex; i < colIndex + colSpan; i++){
|
|
137
|
-
let column = collection.columns[i];
|
|
138
|
-
var _this_columnWidths_get;
|
|
139
|
-
if ((column === null || column === void 0 ? void 0 : column.key) != null) width += (_this_columnWidths_get = this.columnWidths.get(column.key)) !== null && _this_columnWidths_get !== void 0 ? _this_columnWidths_get : 0;
|
|
140
|
-
}
|
|
141
|
-
return width;
|
|
142
|
-
}
|
|
143
|
-
getEstimatedHeight(node, width, height, estimatedHeight) {
|
|
144
|
-
let isEstimated = false;
|
|
145
|
-
// If no explicit height is available, use an estimated height.
|
|
146
|
-
if (height == null) {
|
|
147
|
-
// If a previous version of this layout info exists, reuse its height.
|
|
148
|
-
// Mark as estimated if the size of the overall collection view changed,
|
|
149
|
-
// or the content of the item changed.
|
|
150
|
-
let previousLayoutNode = this.layoutNodes.get(node.key);
|
|
151
|
-
if (previousLayoutNode) {
|
|
152
|
-
height = previousLayoutNode.layoutInfo.rect.height;
|
|
153
|
-
isEstimated = node !== previousLayoutNode.node || width !== previousLayoutNode.layoutInfo.rect.width || previousLayoutNode.layoutInfo.estimatedSize;
|
|
154
|
-
} else {
|
|
155
|
-
height = estimatedHeight !== null && estimatedHeight !== void 0 ? estimatedHeight : $a152112e902709bf$var$DEFAULT_ROW_HEIGHT;
|
|
156
|
-
isEstimated = true;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
height: height,
|
|
161
|
-
isEstimated: isEstimated
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
getEstimatedRowHeight() {
|
|
165
|
-
var _this_rowHeight, _ref;
|
|
166
|
-
return (_ref = (_this_rowHeight = this.rowHeight) !== null && _this_rowHeight !== void 0 ? _this_rowHeight : this.estimatedRowHeight) !== null && _ref !== void 0 ? _ref : $a152112e902709bf$var$DEFAULT_ROW_HEIGHT;
|
|
167
|
-
}
|
|
168
|
-
buildColumn(node, x, y) {
|
|
169
|
-
let width = this.getRenderedColumnWidth(node);
|
|
170
|
-
var _this_headingHeight, _this_estimatedHeadingHeight;
|
|
171
|
-
let { height: height, isEstimated: isEstimated } = this.getEstimatedHeight(node, width, (_this_headingHeight = this.headingHeight) !== null && _this_headingHeight !== void 0 ? _this_headingHeight : this.rowHeight, (_this_estimatedHeadingHeight = this.estimatedHeadingHeight) !== null && _this_estimatedHeadingHeight !== void 0 ? _this_estimatedHeadingHeight : this.estimatedRowHeight);
|
|
172
|
-
let rect = new (0, $bmsJv$Rect)(x, y, width, height);
|
|
173
|
-
let layoutInfo = new (0, $bmsJv$LayoutInfo)(node.type, node.key, rect);
|
|
174
|
-
layoutInfo.isSticky = this.isStickyColumn(node);
|
|
175
|
-
layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
|
|
176
|
-
layoutInfo.estimatedSize = isEstimated;
|
|
177
|
-
return {
|
|
178
|
-
layoutInfo: layoutInfo,
|
|
179
|
-
children: [],
|
|
180
|
-
validRect: layoutInfo.rect,
|
|
181
|
-
node: node
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
// For subclasses.
|
|
185
|
-
// eslint-disable-next-line
|
|
186
|
-
isStickyColumn(node) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
buildBody(y) {
|
|
190
|
-
let collection = this.virtualizer.collection;
|
|
191
|
-
let rect = new (0, $bmsJv$Rect)(this.padding, y, 0, 0);
|
|
192
|
-
let layoutInfo = new (0, $bmsJv$LayoutInfo)('rowgroup', collection.body.key, rect);
|
|
193
|
-
let startY = y;
|
|
194
|
-
let skipped = 0;
|
|
195
|
-
let width = 0;
|
|
196
|
-
let children = [];
|
|
197
|
-
let rowHeight = this.getEstimatedRowHeight() + this.gap;
|
|
198
|
-
let childNodes = (0, $bmsJv$getChildNodes)(collection.body, collection);
|
|
199
|
-
for (let node of childNodes){
|
|
200
|
-
// Skip rows before the valid rectangle unless they are already cached.
|
|
201
|
-
if (y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
|
|
202
|
-
y += rowHeight;
|
|
203
|
-
skipped++;
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
let layoutNode = this.buildChild(node, this.padding, y, layoutInfo.key);
|
|
207
|
-
layoutNode.layoutInfo.parentKey = layoutInfo.key;
|
|
208
|
-
layoutNode.index = children.length;
|
|
209
|
-
y = layoutNode.layoutInfo.rect.maxY + this.gap;
|
|
210
|
-
width = Math.max(width, layoutNode.layoutInfo.rect.width);
|
|
211
|
-
children.push(layoutNode);
|
|
212
|
-
if (y > this.requestedRect.maxY) {
|
|
213
|
-
var _children_at;
|
|
214
|
-
let rowsAfterRect = collection.size - (children.length + skipped);
|
|
215
|
-
let lastNode = (0, $bmsJv$getLastItem)(childNodes);
|
|
216
|
-
// Estimate the remaining height for rows that we don't need to layout right now.
|
|
217
|
-
y += rowsAfterRect * rowHeight;
|
|
218
|
-
// Always add the loader sentinel if present. This assumes the loader is the last row in the body,
|
|
219
|
-
// will need to refactor when handling multi section loading
|
|
220
|
-
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'loader' && ((_children_at = children.at(-1)) === null || _children_at === void 0 ? void 0 : _children_at.layoutInfo.type) !== 'loader') {
|
|
221
|
-
let loader = this.buildChild(lastNode, this.padding, y, layoutInfo.key);
|
|
222
|
-
loader.layoutInfo.parentKey = layoutInfo.key;
|
|
223
|
-
loader.index = collection.size;
|
|
224
|
-
width = Math.max(width, loader.layoutInfo.rect.width);
|
|
225
|
-
children.push(loader);
|
|
226
|
-
y = loader.layoutInfo.rect.maxY;
|
|
227
|
-
}
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// Make sure that the table body gets a height if empty or performing initial load
|
|
232
|
-
let isEmptyOrLoading = (collection === null || collection === void 0 ? void 0 : collection.size) === 0;
|
|
233
|
-
if (isEmptyOrLoading) y = this.virtualizer.visibleRect.maxY;
|
|
234
|
-
else y -= this.gap;
|
|
235
|
-
rect.width = width;
|
|
236
|
-
rect.height = y - startY;
|
|
237
|
-
return {
|
|
238
|
-
layoutInfo: layoutInfo,
|
|
239
|
-
children: children,
|
|
240
|
-
validRect: layoutInfo.rect.intersection(this.requestedRect),
|
|
241
|
-
node: collection.body
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
buildNode(node, x, y) {
|
|
245
|
-
switch(node.type){
|
|
246
|
-
case 'headerrow':
|
|
247
|
-
return this.buildHeaderRow(node, x, y);
|
|
248
|
-
case 'item':
|
|
249
|
-
return this.buildRow(node, x, y);
|
|
250
|
-
case 'column':
|
|
251
|
-
case 'placeholder':
|
|
252
|
-
return this.buildColumn(node, x, y);
|
|
253
|
-
case 'cell':
|
|
254
|
-
return this.buildCell(node, x, y);
|
|
255
|
-
case 'loader':
|
|
256
|
-
return this.buildLoader(node, x, y);
|
|
257
|
-
default:
|
|
258
|
-
throw new Error('Unknown node type ' + node.type);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
buildRow(node, x, y) {
|
|
262
|
-
var _collection_head;
|
|
263
|
-
let collection = this.virtualizer.collection;
|
|
264
|
-
let rect = new (0, $bmsJv$Rect)(x, y, 0, 0);
|
|
265
|
-
let layoutInfo = new (0, $bmsJv$LayoutInfo)('row', node.key, rect);
|
|
266
|
-
let children = [];
|
|
267
|
-
let height = 0;
|
|
268
|
-
for (let child of (0, $bmsJv$getChildNodes)(node, collection))if (child.type === 'cell') {
|
|
269
|
-
if (x > this.requestedRect.maxX) {
|
|
270
|
-
// Adjust existing cached layoutInfo to ensure that it is out of view.
|
|
271
|
-
// This can happen due to column resizing.
|
|
272
|
-
let layoutNode = this.layoutNodes.get(child.key);
|
|
273
|
-
if (layoutNode) {
|
|
274
|
-
layoutNode.layoutInfo.rect.x = x;
|
|
275
|
-
x += layoutNode.layoutInfo.rect.width;
|
|
276
|
-
} else break;
|
|
277
|
-
} else {
|
|
278
|
-
let layoutNode = this.buildChild(child, x, y, layoutInfo.key);
|
|
279
|
-
x = layoutNode.layoutInfo.rect.maxX;
|
|
280
|
-
height = Math.max(height, layoutNode.layoutInfo.rect.height);
|
|
281
|
-
layoutNode.index = children.length;
|
|
282
|
-
children.push(layoutNode);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
this.setChildHeights(children, height);
|
|
286
|
-
var _collection_head_key;
|
|
287
|
-
rect.width = this.layoutNodes.get((_collection_head_key = (_collection_head = collection.head) === null || _collection_head === void 0 ? void 0 : _collection_head.key) !== null && _collection_head_key !== void 0 ? _collection_head_key : 'header').layoutInfo.rect.width;
|
|
288
|
-
rect.height = height;
|
|
289
|
-
return {
|
|
290
|
-
layoutInfo: layoutInfo,
|
|
291
|
-
children: children,
|
|
292
|
-
validRect: rect.intersection(this.requestedRect),
|
|
293
|
-
node: node
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
buildCell(node, x, y) {
|
|
297
|
-
let width = this.getRenderedColumnWidth(node);
|
|
298
|
-
let { height: height, isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.rowHeight, this.estimatedRowHeight);
|
|
299
|
-
let rect = new (0, $bmsJv$Rect)(x, y, width, height);
|
|
300
|
-
let layoutInfo = new (0, $bmsJv$LayoutInfo)(node.type, node.key, rect);
|
|
301
|
-
layoutInfo.isSticky = this.isStickyColumn(node);
|
|
302
|
-
layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
|
|
303
|
-
layoutInfo.estimatedSize = isEstimated;
|
|
304
|
-
return {
|
|
305
|
-
layoutInfo: layoutInfo,
|
|
306
|
-
children: [],
|
|
307
|
-
validRect: rect,
|
|
308
|
-
node: node
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
getVisibleLayoutInfos(rect) {
|
|
312
|
-
// Adjust rect to keep number of visible rows consistent.
|
|
313
|
-
// (only if height > 1 for getDropTargetFromPoint)
|
|
314
|
-
if (rect.height > 1) {
|
|
315
|
-
let rowHeight = this.getEstimatedRowHeight();
|
|
316
|
-
rect.y = Math.floor(rect.y / rowHeight) * rowHeight;
|
|
317
|
-
rect.height = Math.ceil(rect.height / rowHeight) * rowHeight;
|
|
318
|
-
}
|
|
319
|
-
// If layout hasn't yet been done for the requested rect, union the
|
|
320
|
-
// new rect with the existing valid rect, and recompute.
|
|
321
|
-
this.layoutIfNeeded(rect);
|
|
322
|
-
let res = [];
|
|
323
|
-
this.buildPersistedIndices();
|
|
324
|
-
for (let node of this.rootNodes){
|
|
325
|
-
res.push(node.layoutInfo);
|
|
326
|
-
this.addVisibleLayoutInfos(res, node, rect);
|
|
327
|
-
}
|
|
328
|
-
return res;
|
|
329
|
-
}
|
|
330
|
-
addVisibleLayoutInfos(res, node, rect) {
|
|
331
|
-
if (!node.children || node.children.length === 0) return;
|
|
332
|
-
switch(node.layoutInfo.type){
|
|
333
|
-
case 'header':
|
|
334
|
-
for (let child of node.children){
|
|
335
|
-
res.push(child.layoutInfo);
|
|
336
|
-
this.addVisibleLayoutInfos(res, child, rect);
|
|
337
|
-
}
|
|
338
|
-
break;
|
|
339
|
-
case 'rowgroup':
|
|
340
|
-
{
|
|
341
|
-
let firstVisibleRow = this.binarySearch(node.children, rect.topLeft, 'y');
|
|
342
|
-
let lastVisibleRow = this.binarySearch(node.children, rect.bottomRight, 'y');
|
|
343
|
-
// Add persisted rows before the visible rows.
|
|
344
|
-
let persistedRowIndices = this.persistedIndices.get(node.layoutInfo.key);
|
|
345
|
-
let persistIndex = 0;
|
|
346
|
-
while(persistedRowIndices && persistIndex < persistedRowIndices.length && persistedRowIndices[persistIndex] < firstVisibleRow){
|
|
347
|
-
let idx = persistedRowIndices[persistIndex];
|
|
348
|
-
if (idx < node.children.length) {
|
|
349
|
-
res.push(node.children[idx].layoutInfo);
|
|
350
|
-
this.addVisibleLayoutInfos(res, node.children[idx], rect);
|
|
351
|
-
}
|
|
352
|
-
persistIndex++;
|
|
353
|
-
}
|
|
354
|
-
for(let i = firstVisibleRow; i <= lastVisibleRow; i++){
|
|
355
|
-
// Skip persisted rows that overlap with visible cells.
|
|
356
|
-
while(persistedRowIndices && persistIndex < persistedRowIndices.length && persistedRowIndices[persistIndex] < i)persistIndex++;
|
|
357
|
-
res.push(node.children[i].layoutInfo);
|
|
358
|
-
this.addVisibleLayoutInfos(res, node.children[i], rect);
|
|
359
|
-
}
|
|
360
|
-
// Add persisted rows after the visible rows.
|
|
361
|
-
while(persistedRowIndices && persistIndex < persistedRowIndices.length){
|
|
362
|
-
let idx = persistedRowIndices[persistIndex++];
|
|
363
|
-
if (idx < node.children.length) {
|
|
364
|
-
res.push(node.children[idx].layoutInfo);
|
|
365
|
-
this.addVisibleLayoutInfos(res, node.children[idx], rect);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
// Always include loading sentinel even when virtualized, we assume it is always the last child for now
|
|
369
|
-
let lastRow = node.children.at(-1);
|
|
370
|
-
if ((lastRow === null || lastRow === void 0 ? void 0 : lastRow.layoutInfo.type) === 'loader') res.push(lastRow.layoutInfo);
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
case 'headerrow':
|
|
374
|
-
case 'row':
|
|
375
|
-
{
|
|
376
|
-
let firstVisibleCell = this.binarySearch(node.children, rect.topLeft, 'x');
|
|
377
|
-
let lastVisibleCell = this.binarySearch(node.children, rect.topRight, 'x');
|
|
378
|
-
let stickyIndex = 0;
|
|
379
|
-
// Add persisted/sticky cells before the visible cells.
|
|
380
|
-
let persistedCellIndices = this.persistedIndices.get(node.layoutInfo.key) || this.stickyColumnIndices;
|
|
381
|
-
while(stickyIndex < persistedCellIndices.length && persistedCellIndices[stickyIndex] < firstVisibleCell){
|
|
382
|
-
let idx = persistedCellIndices[stickyIndex];
|
|
383
|
-
if (idx < node.children.length) res.push(node.children[idx].layoutInfo);
|
|
384
|
-
stickyIndex++;
|
|
385
|
-
}
|
|
386
|
-
for(let i = firstVisibleCell; i <= lastVisibleCell; i++){
|
|
387
|
-
// Skip sticky cells that overlap with visible cells.
|
|
388
|
-
while(stickyIndex < persistedCellIndices.length && persistedCellIndices[stickyIndex] < i)stickyIndex++;
|
|
389
|
-
res.push(node.children[i].layoutInfo);
|
|
390
|
-
}
|
|
391
|
-
// Add any remaining sticky cells after the visible cells.
|
|
392
|
-
while(stickyIndex < persistedCellIndices.length){
|
|
393
|
-
let idx = persistedCellIndices[stickyIndex++];
|
|
394
|
-
if (idx < node.children.length) res.push(node.children[idx].layoutInfo);
|
|
395
|
-
}
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
default:
|
|
399
|
-
throw new Error('Unknown node type ' + node.layoutInfo.type);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
binarySearch(items, point, axis) {
|
|
403
|
-
let low = 0;
|
|
404
|
-
let high = items.length - 1;
|
|
405
|
-
while(low <= high){
|
|
406
|
-
let mid = low + high >> 1;
|
|
407
|
-
let item = items[mid];
|
|
408
|
-
if (axis === 'x' && item.layoutInfo.rect.maxX <= point.x || axis === 'y' && item.layoutInfo.rect.maxY <= point.y) low = mid + 1;
|
|
409
|
-
else if (axis === 'x' && item.layoutInfo.rect.x > point.x || axis === 'y' && item.layoutInfo.rect.y > point.y) high = mid - 1;
|
|
410
|
-
else return mid;
|
|
411
|
-
}
|
|
412
|
-
return Math.max(0, Math.min(items.length - 1, low));
|
|
413
|
-
}
|
|
414
|
-
buildPersistedIndices() {
|
|
415
|
-
if (this.virtualizer.persistedKeys === this.lastPersistedKeys) return;
|
|
416
|
-
this.lastPersistedKeys = this.virtualizer.persistedKeys;
|
|
417
|
-
this.persistedIndices.clear();
|
|
418
|
-
// Build a map of parentKey => indices of children to persist.
|
|
419
|
-
for (let key of this.virtualizer.persistedKeys){
|
|
420
|
-
var _this_layoutNodes_get;
|
|
421
|
-
let layoutInfo = (_this_layoutNodes_get = this.layoutNodes.get(key)) === null || _this_layoutNodes_get === void 0 ? void 0 : _this_layoutNodes_get.layoutInfo;
|
|
422
|
-
// Walk up ancestors so parents are also persisted if children are.
|
|
423
|
-
while(layoutInfo && layoutInfo.parentKey){
|
|
424
|
-
var _this_layoutNodes_get1, _this_layoutNodes_get2;
|
|
425
|
-
let collectionNode = this.virtualizer.collection.getItem(layoutInfo.key);
|
|
426
|
-
let indices = this.persistedIndices.get(layoutInfo.parentKey);
|
|
427
|
-
if (!indices) {
|
|
428
|
-
// stickyColumnIndices are always persisted along with any cells from persistedKeys.
|
|
429
|
-
indices = (collectionNode === null || collectionNode === void 0 ? void 0 : collectionNode.type) === 'cell' || (collectionNode === null || collectionNode === void 0 ? void 0 : collectionNode.type) === 'column' ? [
|
|
430
|
-
...this.stickyColumnIndices
|
|
431
|
-
] : [];
|
|
432
|
-
this.persistedIndices.set(layoutInfo.parentKey, indices);
|
|
433
|
-
}
|
|
434
|
-
let index = (_this_layoutNodes_get1 = this.layoutNodes.get(layoutInfo.key)) === null || _this_layoutNodes_get1 === void 0 ? void 0 : _this_layoutNodes_get1.index;
|
|
435
|
-
if (index != null && !indices.includes(index)) indices.push(index);
|
|
436
|
-
layoutInfo = (_this_layoutNodes_get2 = this.layoutNodes.get(layoutInfo.parentKey)) === null || _this_layoutNodes_get2 === void 0 ? void 0 : _this_layoutNodes_get2.layoutInfo;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
for (let indices of this.persistedIndices.values())indices.sort((a, b)=>a - b);
|
|
440
|
-
}
|
|
441
|
-
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
442
|
-
x += this.virtualizer.visibleRect.x;
|
|
443
|
-
y += this.virtualizer.visibleRect.y;
|
|
444
|
-
// Find the closest item within on either side of the point using the gap width.
|
|
445
|
-
let searchRect = new (0, $bmsJv$Rect)(x, Math.max(0, y - this.gap), 1, Math.max(1, this.gap * 2));
|
|
446
|
-
let candidates = this.getVisibleLayoutInfos(searchRect);
|
|
447
|
-
let key = null;
|
|
448
|
-
let minDistance = Infinity;
|
|
449
|
-
for (let candidate of candidates){
|
|
450
|
-
// Ignore items outside the search rect, e.g. persisted keys.
|
|
451
|
-
if (candidate.type !== 'row' || !candidate.rect.intersects(searchRect)) continue;
|
|
452
|
-
let yDist = Math.abs(candidate.rect.y - y);
|
|
453
|
-
let maxYDist = Math.abs(candidate.rect.maxY - y);
|
|
454
|
-
let dist = Math.min(yDist, maxYDist);
|
|
455
|
-
if (dist < minDistance) {
|
|
456
|
-
minDistance = dist;
|
|
457
|
-
key = candidate.key;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
if (key == null || this.virtualizer.collection.size === 0) return {
|
|
461
|
-
type: 'root'
|
|
462
|
-
};
|
|
463
|
-
let layoutInfo = this.getLayoutInfo(key);
|
|
464
|
-
if (!layoutInfo) return null;
|
|
465
|
-
let rect = layoutInfo.rect;
|
|
466
|
-
let target = {
|
|
467
|
-
type: 'item',
|
|
468
|
-
key: layoutInfo.key,
|
|
469
|
-
dropPosition: 'on'
|
|
470
|
-
};
|
|
471
|
-
// If dropping on the item isn't accepted, try the target before or after depending on the y position.
|
|
472
|
-
// Otherwise, if dropping on the item is accepted, still try the before/after positions if within 10px
|
|
473
|
-
// of the top or bottom of the item.
|
|
474
|
-
if (!isValidDropTarget(target)) {
|
|
475
|
-
if (y <= rect.y + rect.height / 2 && isValidDropTarget({
|
|
476
|
-
...target,
|
|
477
|
-
dropPosition: 'before'
|
|
478
|
-
})) target.dropPosition = 'before';
|
|
479
|
-
else if (isValidDropTarget({
|
|
480
|
-
...target,
|
|
481
|
-
dropPosition: 'after'
|
|
482
|
-
})) target.dropPosition = 'after';
|
|
483
|
-
} else if (y <= rect.y + 10 && isValidDropTarget({
|
|
484
|
-
...target,
|
|
485
|
-
dropPosition: 'before'
|
|
486
|
-
})) target.dropPosition = 'before';
|
|
487
|
-
else if (y >= rect.maxY - 10 && isValidDropTarget({
|
|
488
|
-
...target,
|
|
489
|
-
dropPosition: 'after'
|
|
490
|
-
})) target.dropPosition = 'after';
|
|
491
|
-
return target;
|
|
492
|
-
}
|
|
493
|
-
getDropTargetLayoutInfo(target) {
|
|
494
|
-
let layoutInfo = super.getDropTargetLayoutInfo(target);
|
|
495
|
-
layoutInfo.parentKey = this.virtualizer.collection.body.key;
|
|
496
|
-
return layoutInfo;
|
|
497
|
-
}
|
|
498
|
-
constructor(options){
|
|
499
|
-
super(options), this.lastCollection = null, this.columnWidths = new Map(), this.lastPersistedKeys = null, this.persistedIndices = new Map();
|
|
500
|
-
this.stickyColumnIndices = [];
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
export {$a152112e902709bf$export$62444c3c724b1b20 as TableLayout};
|
|
506
|
-
//# sourceMappingURL=TableLayout.module.js.map
|