@jsenv/navi 0.29.344 → 0.29.345
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/dev/jsenv_navi.js +1564 -1376
- package/dist/dev/jsenv_navi.js.map +6 -4
- package/dist/jsenv_navi.js +1564 -1376
- package/dist/jsenv_navi.js.map +6 -4
- package/package.json +1 -1
package/dist/dev/jsenv_navi.js
CHANGED
|
@@ -66030,452 +66030,666 @@ const cssVars = vars => {
|
|
|
66030
66030
|
};
|
|
66031
66031
|
const lengthValue = value => typeof value === "number" ? `${value}px` : value;
|
|
66032
66032
|
|
|
66033
|
-
|
|
66034
|
-
|
|
66035
|
-
|
|
66036
|
-
|
|
66037
|
-
* USAGE:
|
|
66038
|
-
* ```jsx
|
|
66039
|
-
* function ListControlled({ items }) {
|
|
66040
|
-
* const tracker = useItemTracker({
|
|
66041
|
-
* onChange: () => console.log("items changed"),
|
|
66042
|
-
* });
|
|
66043
|
-
*
|
|
66044
|
-
* return (
|
|
66045
|
-
* <ul>
|
|
66046
|
-
* {items.map((item, i) => (
|
|
66047
|
-
* <Row key={item.id} id={item.id} index={i} hidden={item.hidden} value={item.value} tracker={tracker} />
|
|
66048
|
-
* ))}
|
|
66049
|
-
* <Count tracker={tracker} />
|
|
66050
|
-
* </ul>
|
|
66051
|
-
* );
|
|
66052
|
-
* }
|
|
66053
|
-
*
|
|
66054
|
-
* function Row({ id, index, hidden, value, tracker }) {
|
|
66055
|
-
* const visibleIndex = tracker.useTrackItem({ id, index, hidden, value });
|
|
66056
|
-
* if (visibleIndex === -1) return null;
|
|
66057
|
-
* return <li>{value}</li>;
|
|
66058
|
-
* }
|
|
66059
|
-
*
|
|
66060
|
-
* function Count({ tracker }) {
|
|
66061
|
-
* const count = tracker.visibleCountSignal.value; // re-renders only when count changes
|
|
66062
|
-
* return <span>{count} items</span>;
|
|
66063
|
-
* }
|
|
66064
|
-
* ```
|
|
66065
|
-
*
|
|
66066
|
-
* INTERNALS:
|
|
66067
|
-
* - registrations: Map key → data, contains only visible items
|
|
66068
|
-
* - idToKey: Map id → key, stable across renders
|
|
66069
|
-
* - orderedKeys: number[] of visible item keys sorted by explicit order
|
|
66070
|
-
* - keyToOrderedIndex: Map key → orderedKeys index, gives O(1) indexOf equivalent
|
|
66071
|
-
* - keyToExplicitOrder: Map key → explicitly passed index, used to maintain sort order
|
|
66072
|
-
* - allItemsSignal: signal(array), all items including hidden, ordered by explicit index
|
|
66073
|
-
* - visibleItemsSignal: signal(array), non-hidden items only
|
|
66074
|
-
* - countSignal: signal(number), count of all items including hidden
|
|
66075
|
-
* - visibleCountSignal: signal(number), updated in microtask batch, only when count changes
|
|
66076
|
-
* - propSignals: Map propName → signal(array), updated in microtask batch with element equality
|
|
66077
|
-
* - onChangeRef: holds the latest onChange callback, called once per microtask batch
|
|
66078
|
-
*
|
|
66079
|
-
* useTrackItem(id, data, index): registers the item with an explicitly provided index
|
|
66080
|
-
* that determines its position among siblings. The caller (e.g. items.map) knows the
|
|
66081
|
-
* correct order and passes it directly — no render-sequence deduction needed.
|
|
66082
|
-
* Returns the visible rank (position among non-hidden items), or -1 when hidden.
|
|
66083
|
-
* Signals and onChange are deferred to a microtask so multiple items updating
|
|
66084
|
-
* in one commit cause only one notification.
|
|
66085
|
-
*
|
|
66086
|
-
* getTrackedItemByIndex(index): synchronous O(1) lookup of a visible item by
|
|
66087
|
-
* its visible rank. Returns undefined when index is out of range.
|
|
66088
|
-
*
|
|
66089
|
-
* peekItems(): the items as they stand right now, without waiting for the
|
|
66090
|
-
* deferred notification — what a sibling rendering after the items must read
|
|
66091
|
-
* to paint them in the same commit.
|
|
66092
|
-
*/
|
|
66093
|
-
|
|
66094
|
-
const useItemTracker = ({ onChange } = {}) => {
|
|
66095
|
-
const onChangeRef = useRef(onChange);
|
|
66096
|
-
onChangeRef.current = onChange;
|
|
66097
|
-
const trackerRef = useRef(null);
|
|
66098
|
-
let tracker = trackerRef.current;
|
|
66099
|
-
if (!tracker) {
|
|
66100
|
-
trackerRef.current = tracker = createItemTracker((items) => {
|
|
66101
|
-
onChangeRef.current?.(items);
|
|
66102
|
-
});
|
|
66033
|
+
const ListItemHeaderOrFooterResolver = props => {
|
|
66034
|
+
const Next = useNextResolver();
|
|
66035
|
+
if (props.header) {
|
|
66036
|
+
return renderResolver(ListItemHeader, props);
|
|
66103
66037
|
}
|
|
66104
|
-
|
|
66105
|
-
|
|
66106
|
-
|
|
66107
|
-
|
|
66108
|
-
|
|
66038
|
+
if (props.footer) {
|
|
66039
|
+
return renderResolver(ListItemFooter, props);
|
|
66040
|
+
}
|
|
66041
|
+
return jsx(Next, {
|
|
66042
|
+
...props
|
|
66043
|
+
});
|
|
66044
|
+
};
|
|
66045
|
+
const ListItemHeader = props => {
|
|
66046
|
+
const Next = useNextResolver();
|
|
66047
|
+
const {
|
|
66048
|
+
ref
|
|
66049
|
+
} = props;
|
|
66050
|
+
useDisplayedLayoutEffect(ref, headerEl => {
|
|
66051
|
+
const listContainerEl = headerEl.closest(".navi_list_container");
|
|
66052
|
+
const rect = headerEl.getBoundingClientRect();
|
|
66053
|
+
listContainerEl.style.setProperty("--list-header-height", `${rect.height}px`);
|
|
66054
|
+
listContainerEl.style.setProperty("--list-header-width", `${rect.width}px`);
|
|
66055
|
+
}, []);
|
|
66056
|
+
return jsx(Next, {
|
|
66057
|
+
...props,
|
|
66058
|
+
header: undefined,
|
|
66059
|
+
role: "presentation",
|
|
66060
|
+
baseClassName: "navi_list_item_header"
|
|
66061
|
+
});
|
|
66062
|
+
};
|
|
66063
|
+
const ListItemFooter = props => {
|
|
66064
|
+
const Next = useNextResolver();
|
|
66065
|
+
const {
|
|
66066
|
+
ref
|
|
66067
|
+
} = props;
|
|
66068
|
+
useDisplayedLayoutEffect(ref, footerEl => {
|
|
66069
|
+
const listContainerEl = footerEl.closest(".navi_list_container");
|
|
66070
|
+
const rect = footerEl.getBoundingClientRect();
|
|
66071
|
+
listContainerEl.style.setProperty("--list-footer-height", `${rect.height}px`);
|
|
66072
|
+
listContainerEl.style.setProperty("--list-footer-width", `${rect.width}px`);
|
|
66073
|
+
}, []);
|
|
66074
|
+
return jsx(Next, {
|
|
66075
|
+
...props,
|
|
66076
|
+
footer: undefined,
|
|
66077
|
+
role: "presentation",
|
|
66078
|
+
baseClassName: "navi_list_item_footer"
|
|
66109
66079
|
});
|
|
66110
|
-
return tracker;
|
|
66111
66080
|
};
|
|
66112
66081
|
|
|
66113
|
-
|
|
66114
|
-
|
|
66115
|
-
|
|
66116
|
-
|
|
66117
|
-
|
|
66118
|
-
|
|
66119
|
-
|
|
66120
|
-
|
|
66121
|
-
|
|
66122
|
-
|
|
66123
|
-
|
|
66124
|
-
|
|
66125
|
-
|
|
66126
|
-
|
|
66127
|
-
|
|
66128
|
-
|
|
66129
|
-
|
|
66130
|
-
|
|
66131
|
-
|
|
66132
|
-
|
|
66133
|
-
|
|
66134
|
-
|
|
66135
|
-
|
|
66136
|
-
|
|
66137
|
-
|
|
66082
|
+
// Everything the list knows about its rows, in one place: how many the
|
|
66083
|
+
// collection has and where each child's rows start (the places), which rows
|
|
66084
|
+
// are drawn and which of those mount and show (the rows), and what each says
|
|
66085
|
+
// about itself (the items). Two clocks. Places and "is anything standing
|
|
66086
|
+
// above me" answer synchronously, in the middle of a render pass — a row asks
|
|
66087
|
+
// about the rows before it, and those have rendered already. The items and
|
|
66088
|
+
// the counts settle once per frame (a microtask): many rows change in one
|
|
66089
|
+
// commit, and what reads them wants one notification.
|
|
66090
|
+
//
|
|
66091
|
+
// Why places are read off the walk and not off the renders: a child knows how
|
|
66092
|
+
// many rows it stands for but not what was declared before it, and it cannot
|
|
66093
|
+
// deduce that from when it renders — a render is free to skip it. A child that
|
|
66094
|
+
// draws from signals and whose props are all referentially === the previous
|
|
66095
|
+
// ones does not render again (@preact/signals installs a shouldComponentUpdate
|
|
66096
|
+
// that says so), which is what any child nobody rebuilt this frame is — and
|
|
66097
|
+
// children numbered as they render would then slide up into the place of the
|
|
66098
|
+
// one that was skipped. So the list names a slot for each of its children and
|
|
66099
|
+
// declares them here, in order, before any of them renders (see
|
|
66100
|
+
// ListDeclaredChildren). A child then takes its place BY SLOT, and the place
|
|
66101
|
+
// is a signal: it moves when what stands before it changes — a row filtered
|
|
66102
|
+
// out, a run taking in rows, a slot added or moved — and the child follows,
|
|
66103
|
+
// rendered again for it whether or not anything else would have rendered it.
|
|
66104
|
+
//
|
|
66105
|
+
// Why "first" is a signal too: only the row itself knows, once it renders,
|
|
66106
|
+
// that it renders nothing (filtered out by a search), and the rows after it
|
|
66107
|
+
// may have been handed back unchanged. The first mounted row of a scope is
|
|
66108
|
+
// kept as a signal each of them reads; when it leaves, they are rendered again.
|
|
66138
66109
|
|
|
66139
|
-
|
|
66140
|
-
const countModified = countSignal.peek() !== newCount;
|
|
66141
|
-
if (countModified) {
|
|
66142
|
-
countSignal.value = newCount;
|
|
66143
|
-
someChange = true;
|
|
66144
|
-
}
|
|
66110
|
+
const UNGROUPED = Symbol("ungrouped");
|
|
66145
66111
|
|
|
66146
|
-
|
|
66147
|
-
|
|
66148
|
-
|
|
66149
|
-
|
|
66150
|
-
|
|
66151
|
-
|
|
66152
|
-
|
|
66153
|
-
|
|
66154
|
-
|
|
66155
|
-
|
|
66156
|
-
|
|
66157
|
-
|
|
66158
|
-
|
|
66159
|
-
|
|
66160
|
-
|
|
66161
|
-
|
|
66162
|
-
|
|
66163
|
-
|
|
66164
|
-
|
|
66165
|
-
|
|
66166
|
-
|
|
66167
|
-
|
|
66168
|
-
|
|
66169
|
-
|
|
66170
|
-
|
|
66171
|
-
|
|
66172
|
-
|
|
66173
|
-
|
|
66174
|
-
|
|
66175
|
-
|
|
66176
|
-
|
|
66177
|
-
|
|
66112
|
+
const createListRows = () => {
|
|
66113
|
+
const totalSignal = signal(0);
|
|
66114
|
+
// Bumped whenever a run takes in rows. The list itself has to hear about it:
|
|
66115
|
+
// rows arriving outside the render window change nothing it can see (nothing
|
|
66116
|
+
// registers, nothing is drawn), and yet they are what it may have been
|
|
66117
|
+
// waiting for — the row it was told to open on, for one.
|
|
66118
|
+
const pagesSignal = signal(0);
|
|
66119
|
+
// How many runs are re-reading rows they already show. The list wears it as
|
|
66120
|
+
// an attribute: what is drawn is from before, and the app may want to say so
|
|
66121
|
+
// without taking anything away.
|
|
66122
|
+
const refreshingSignal = signal(0);
|
|
66123
|
+
// The slots each walk declared, in order, by the slot the walk stands in
|
|
66124
|
+
// (null for the list's own children). Together they are a tree: a group's
|
|
66125
|
+
// rows live inside the group's slot.
|
|
66126
|
+
const slotIdsByParent = new Map();
|
|
66127
|
+
// Who took a place — a row, or a run of rows — and how many rows of the
|
|
66128
|
+
// collection it stands for. The place itself is a signal, see take.
|
|
66129
|
+
const ownerById = new Map();
|
|
66130
|
+
// The owners standing in each slot, in the order they took their place.
|
|
66131
|
+
// One, as a rule; a child that renders several rows keeps them in the order
|
|
66132
|
+
// they first rendered, which is all it can be told.
|
|
66133
|
+
const ownerIdsBySlot = new Map();
|
|
66134
|
+
const locatorByOwner = new Map();
|
|
66135
|
+
// The slots as the tree reads, first to last, and where each stands in it.
|
|
66136
|
+
// Rebuilt once a walk has changed the tree, read to place the owners.
|
|
66137
|
+
const slotWalk = [];
|
|
66138
|
+
const rankBySlot = new Map();
|
|
66139
|
+
let rowTotal = 0;
|
|
66140
|
+
// Owners have left and the others have not been moved up yet. Done on the
|
|
66141
|
+
// next ask rather than on the spot: rows leave many at a time (a search, a
|
|
66142
|
+
// list unmounting), and moving the others up once is enough.
|
|
66143
|
+
let placesStale = false;
|
|
66144
|
+
// Where the last slot holding an owner stands: an owner arriving at or after
|
|
66145
|
+
// it is placed at the end without going over the others — a whole first
|
|
66146
|
+
// render, rows arriving in order, costs each row nothing but itself.
|
|
66147
|
+
let rankOwnedLast = -1;
|
|
66178
66148
|
|
|
66179
|
-
|
|
66180
|
-
|
|
66181
|
-
|
|
66182
|
-
|
|
66183
|
-
|
|
66184
|
-
|
|
66185
|
-
|
|
66186
|
-
if (allItemsChanged) {
|
|
66187
|
-
itemsSignal.value = allItems;
|
|
66188
|
-
someChange = true;
|
|
66189
|
-
}
|
|
66190
|
-
if (visibleItemsChanged) {
|
|
66191
|
-
visibleItemsSignal.value = visibleItems;
|
|
66192
|
-
someChange = true;
|
|
66193
|
-
}
|
|
66194
|
-
const noMatchCountModified =
|
|
66195
|
-
noMatchCountSignal.peek() !== newNoMatchCount;
|
|
66196
|
-
if (noMatchCountModified) {
|
|
66197
|
-
noMatchCountSignal.value = newNoMatchCount;
|
|
66198
|
-
someChange = true;
|
|
66149
|
+
const rebuildWalk = () => {
|
|
66150
|
+
slotWalk.length = 0;
|
|
66151
|
+
rankBySlot.clear();
|
|
66152
|
+
const visit = (parentSlotId) => {
|
|
66153
|
+
const slotIds = slotIdsByParent.get(parentSlotId);
|
|
66154
|
+
if (!slotIds) {
|
|
66155
|
+
return;
|
|
66199
66156
|
}
|
|
66200
|
-
|
|
66201
|
-
|
|
66157
|
+
for (const slotId of slotIds) {
|
|
66158
|
+
rankBySlot.set(slotId, slotWalk.length);
|
|
66159
|
+
slotWalk.push(slotId);
|
|
66160
|
+
visit(slotId);
|
|
66202
66161
|
}
|
|
66203
|
-
}
|
|
66162
|
+
};
|
|
66163
|
+
visit(null);
|
|
66204
66164
|
};
|
|
66205
|
-
|
|
66206
|
-
|
|
66207
|
-
|
|
66208
|
-
|
|
66209
|
-
|
|
66210
|
-
|
|
66211
|
-
|
|
66212
|
-
|
|
66213
|
-
|
|
66165
|
+
// Every place, in one go: a place is the sum of what stands before it, so
|
|
66166
|
+
// there is nothing to hand out one at a time. Writing a place that did not
|
|
66167
|
+
// change wakes nobody — a signal ignores a value equal to its own.
|
|
66168
|
+
const refreshPlaces = () => {
|
|
66169
|
+
placesStale = false;
|
|
66170
|
+
let index = 0;
|
|
66171
|
+
let rank = 0;
|
|
66172
|
+
rankOwnedLast = -1;
|
|
66173
|
+
while (rank < slotWalk.length) {
|
|
66174
|
+
const ownerIds = ownerIdsBySlot.get(slotWalk[rank]);
|
|
66175
|
+
if (ownerIds) {
|
|
66176
|
+
for (const ownerId of ownerIds) {
|
|
66177
|
+
const owner = ownerById.get(ownerId);
|
|
66178
|
+
owner.placeSignal.value = index;
|
|
66179
|
+
index += owner.rowCount;
|
|
66180
|
+
}
|
|
66181
|
+
rankOwnedLast = rank;
|
|
66214
66182
|
}
|
|
66215
|
-
|
|
66216
|
-
|
|
66217
|
-
|
|
66183
|
+
rank++;
|
|
66184
|
+
}
|
|
66185
|
+
rowTotal = index;
|
|
66186
|
+
totalSignal.value = index;
|
|
66187
|
+
// A run's edges are places too (see refreshFirst).
|
|
66188
|
+
markStale(UNGROUPED);
|
|
66218
66189
|
};
|
|
66219
|
-
|
|
66220
|
-
|
|
66221
|
-
if (
|
|
66190
|
+
const addToSlot = (slotId, ownerId) => {
|
|
66191
|
+
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
66192
|
+
if (ownerIds) {
|
|
66193
|
+
ownerIds.push(ownerId);
|
|
66194
|
+
} else {
|
|
66195
|
+
ownerIdsBySlot.set(slotId, [ownerId]);
|
|
66196
|
+
}
|
|
66197
|
+
warnIfEveryRowInOneSlot(slotId);
|
|
66198
|
+
};
|
|
66199
|
+
// Rows that all stand in the same slot keep the order they first mounted in:
|
|
66200
|
+
// the walk is over the children the list is given, and a component holding
|
|
66201
|
+
// them is one child however many rows it renders. Everything about a place
|
|
66202
|
+
// then stops following what the caller writes — a search reordering the rows
|
|
66203
|
+
// moves nothing. Said once, and only for the shape that can be nothing else:
|
|
66204
|
+
// the list's whole content is one child, and several rows came out of it.
|
|
66205
|
+
let everyRowInOneSlotWarned = false;
|
|
66206
|
+
const warnIfEveryRowInOneSlot = (slotId) => {
|
|
66207
|
+
if (everyRowInOneSlotWarned) {
|
|
66222
66208
|
return;
|
|
66223
66209
|
}
|
|
66224
|
-
|
|
66225
|
-
|
|
66210
|
+
const rootSlotIds = slotIdsByParent.get(null);
|
|
66211
|
+
if (!rootSlotIds || rootSlotIds.length !== 1 || rootSlotIds[0] !== slotId) {
|
|
66212
|
+
return;
|
|
66213
|
+
}
|
|
66214
|
+
if (ownerIdsBySlot.get(slotId).length < 2) {
|
|
66215
|
+
return;
|
|
66216
|
+
}
|
|
66217
|
+
everyRowInOneSlotWarned = true;
|
|
66218
|
+
console.warn(
|
|
66219
|
+
`List: every row stands in the same slot, so they keep the order they first rendered in — reordering them (a search, a sort) will not move them. The list's rows must be its own children: give it the rows (or a <List.Items>), not a component rendering them.`,
|
|
66220
|
+
);
|
|
66226
66221
|
};
|
|
66227
|
-
|
|
66228
|
-
|
|
66229
|
-
|
|
66230
|
-
|
|
66231
|
-
let lo = 0;
|
|
66232
|
-
let hi = orderedKeys.length;
|
|
66233
|
-
while (lo < hi) {
|
|
66234
|
-
const mid = (lo + hi) >> 1;
|
|
66235
|
-
if (keyToExplicitOrder.get(orderedKeys[mid]) <= explicitOrder) {
|
|
66236
|
-
lo = mid + 1;
|
|
66237
|
-
} else {
|
|
66238
|
-
hi = mid;
|
|
66239
|
-
}
|
|
66222
|
+
const removeFromSlot = (slotId, ownerId) => {
|
|
66223
|
+
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
66224
|
+
if (!ownerIds) {
|
|
66225
|
+
return;
|
|
66240
66226
|
}
|
|
66241
|
-
|
|
66242
|
-
|
|
66243
|
-
|
|
66227
|
+
const index = ownerIds.indexOf(ownerId);
|
|
66228
|
+
if (index !== -1) {
|
|
66229
|
+
ownerIds.splice(index, 1);
|
|
66230
|
+
}
|
|
66231
|
+
if (ownerIds.length === 0) {
|
|
66232
|
+
ownerIdsBySlot.delete(slotId);
|
|
66244
66233
|
}
|
|
66245
66234
|
};
|
|
66246
|
-
|
|
66247
|
-
|
|
66248
|
-
|
|
66249
|
-
|
|
66250
|
-
|
|
66251
|
-
const
|
|
66252
|
-
|
|
66253
|
-
lo = mid + 1;
|
|
66254
|
-
} else {
|
|
66255
|
-
hi = mid;
|
|
66235
|
+
// A slot the walk no longer names: whatever stood in it is gone, and so is
|
|
66236
|
+
// whatever a walk inside it had declared.
|
|
66237
|
+
const dropSlot = (slotId) => {
|
|
66238
|
+
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
66239
|
+
if (ownerIds) {
|
|
66240
|
+
for (const ownerId of ownerIds) {
|
|
66241
|
+
ownerById.delete(ownerId);
|
|
66256
66242
|
}
|
|
66243
|
+
ownerIdsBySlot.delete(slotId);
|
|
66257
66244
|
}
|
|
66258
|
-
|
|
66259
|
-
|
|
66260
|
-
|
|
66245
|
+
const childSlotIds = slotIdsByParent.get(slotId);
|
|
66246
|
+
if (childSlotIds) {
|
|
66247
|
+
slotIdsByParent.delete(slotId);
|
|
66248
|
+
for (const childSlotId of childSlotIds) {
|
|
66249
|
+
dropSlot(childSlotId);
|
|
66250
|
+
}
|
|
66261
66251
|
}
|
|
66262
66252
|
};
|
|
66263
66253
|
|
|
66264
|
-
|
|
66265
|
-
|
|
66266
|
-
|
|
66267
|
-
|
|
66268
|
-
|
|
66269
|
-
|
|
66270
|
-
|
|
66271
|
-
|
|
66254
|
+
// ---- the rows drawn ----
|
|
66255
|
+
// rowId → { ownerId, place, groupId, data, mounted, visible, item }
|
|
66256
|
+
const rowById = new Map();
|
|
66257
|
+
// groupId → { firstSignal, countSignal, noMatchCountSignal }
|
|
66258
|
+
const groupById = new Map();
|
|
66259
|
+
// ownerId → { from, to }, for the runs (see declareWindow).
|
|
66260
|
+
const windowByOwner = new Map();
|
|
66261
|
+
// The first place something stands at, outside any group: the mounted rows
|
|
66262
|
+
// and the rows a run holds above its window. Per group, the group's first
|
|
66263
|
+
// mounted row.
|
|
66264
|
+
const firstStandingSignal = signal(-1);
|
|
66265
|
+
// The scopes whose first row left: recounted on the next ask, or at the end
|
|
66266
|
+
// of the frame, whichever comes first. A row mounting before the first one
|
|
66267
|
+
// moves it at once, no recount needed — the first can only ever move up.
|
|
66268
|
+
const staleScopes = new Set();
|
|
66269
|
+
const scopeOf = (groupId) => (groupId === undefined ? UNGROUPED : groupId);
|
|
66270
|
+
const groupOf = (groupId) => {
|
|
66271
|
+
let group = groupById.get(groupId);
|
|
66272
|
+
if (!group) {
|
|
66273
|
+
group = {
|
|
66274
|
+
firstSignal: signal(-1),
|
|
66275
|
+
countSignal: signal(0),
|
|
66276
|
+
noMatchCountSignal: signal(0),
|
|
66277
|
+
};
|
|
66278
|
+
groupById.set(groupId, group);
|
|
66272
66279
|
}
|
|
66280
|
+
return group;
|
|
66273
66281
|
};
|
|
66274
|
-
|
|
66275
|
-
|
|
66276
|
-
|
|
66277
|
-
|
|
66278
|
-
|
|
66279
|
-
|
|
66280
|
-
|
|
66281
|
-
|
|
66282
|
-
orderedKeys.splice(idx, 1);
|
|
66283
|
-
keyToOrderedIndex.delete(key);
|
|
66284
|
-
for (let i = idx; i < orderedKeys.length; i++) {
|
|
66285
|
-
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
66286
|
-
}
|
|
66282
|
+
const firstSignalOf = (scope) =>
|
|
66283
|
+
scope === UNGROUPED ? firstStandingSignal : groupOf(scope).firstSignal;
|
|
66284
|
+
const refreshFirst = (scope) => {
|
|
66285
|
+
staleScopes.delete(scope);
|
|
66286
|
+
let first = -1;
|
|
66287
|
+
const consider = (place) => {
|
|
66288
|
+
if (place !== undefined && (first === -1 || place < first)) {
|
|
66289
|
+
first = place;
|
|
66287
66290
|
}
|
|
66288
|
-
|
|
66289
|
-
|
|
66290
|
-
|
|
66291
|
-
|
|
66292
|
-
return;
|
|
66293
|
-
}
|
|
66294
|
-
|
|
66295
|
-
// Maintain allRegistrations and allOrderedKeys for all non-presentation items.
|
|
66296
|
-
allRegistrations.set(key, data);
|
|
66297
|
-
allKeys.add(key);
|
|
66298
|
-
const currentAllIdx = keyToAllOrderedIndex.get(key);
|
|
66299
|
-
const previousOrder = keyToExplicitOrder.get(key);
|
|
66300
|
-
keyToExplicitOrder.set(key, index);
|
|
66301
|
-
if (currentAllIdx === undefined) {
|
|
66302
|
-
insertAllKey(key, index);
|
|
66303
|
-
} else if (previousOrder !== index) {
|
|
66304
|
-
allOrderedKeys.splice(currentAllIdx, 1);
|
|
66305
|
-
keyToAllOrderedIndex.delete(key);
|
|
66306
|
-
for (let i = currentAllIdx; i < allOrderedKeys.length; i++) {
|
|
66307
|
-
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
66291
|
+
};
|
|
66292
|
+
for (const row of rowById.values()) {
|
|
66293
|
+
if (row.mounted && scopeOf(row.groupId) === scope) {
|
|
66294
|
+
consider(row.place);
|
|
66308
66295
|
}
|
|
66309
|
-
insertAllKey(key, index);
|
|
66310
66296
|
}
|
|
66311
|
-
|
|
66312
|
-
|
|
66313
|
-
|
|
66314
|
-
|
|
66315
|
-
|
|
66316
|
-
|
|
66317
|
-
|
|
66318
|
-
|
|
66319
|
-
|
|
66297
|
+
if (scope === UNGROUPED) {
|
|
66298
|
+
for (const [ownerId, window] of windowByOwner) {
|
|
66299
|
+
const owner = ownerById.get(ownerId);
|
|
66300
|
+
if (!owner) {
|
|
66301
|
+
continue;
|
|
66302
|
+
}
|
|
66303
|
+
const start = owner.placeSignal.peek();
|
|
66304
|
+
if (window.from > start) {
|
|
66305
|
+
consider(start);
|
|
66306
|
+
}
|
|
66307
|
+
if (window.to < start + owner.rowCount) {
|
|
66308
|
+
consider(window.to);
|
|
66320
66309
|
}
|
|
66321
66310
|
}
|
|
66322
|
-
return;
|
|
66323
|
-
}
|
|
66324
|
-
|
|
66325
|
-
registrations.set(key, data);
|
|
66326
|
-
const currentIdx = keyToOrderedIndex.get(key);
|
|
66327
|
-
if (currentIdx === undefined) {
|
|
66328
|
-
insertKey(key, index);
|
|
66329
|
-
return;
|
|
66330
66311
|
}
|
|
66331
|
-
|
|
66312
|
+
firstSignalOf(scope).value = first;
|
|
66313
|
+
};
|
|
66314
|
+
const markStale = (scope) => {
|
|
66315
|
+
if (staleScopes.has(scope)) {
|
|
66332
66316
|
return;
|
|
66333
66317
|
}
|
|
66334
|
-
|
|
66335
|
-
|
|
66336
|
-
|
|
66337
|
-
|
|
66318
|
+
staleScopes.add(scope);
|
|
66319
|
+
queueMicrotask(() => {
|
|
66320
|
+
if (staleScopes.has(scope)) {
|
|
66321
|
+
refreshFirst(scope);
|
|
66322
|
+
}
|
|
66323
|
+
});
|
|
66324
|
+
};
|
|
66325
|
+
const leaveFirst = (row) => {
|
|
66326
|
+
const scope = scopeOf(row.groupId);
|
|
66327
|
+
if (firstSignalOf(scope).peek() === row.place) {
|
|
66328
|
+
markStale(scope);
|
|
66338
66329
|
}
|
|
66339
|
-
insertKey(key, index);
|
|
66340
66330
|
};
|
|
66341
66331
|
|
|
66342
|
-
|
|
66343
|
-
|
|
66344
|
-
|
|
66345
|
-
|
|
66346
|
-
|
|
66347
|
-
|
|
66348
|
-
|
|
66349
|
-
|
|
66332
|
+
// ---- the items, settled once per frame ----
|
|
66333
|
+
const itemsSignal = signal([]);
|
|
66334
|
+
const visibleItemsSignal = signal([]);
|
|
66335
|
+
const countSignal = signal(0);
|
|
66336
|
+
const visibleCountSignal = signal(0);
|
|
66337
|
+
const noMatchCountSignal = signal(0);
|
|
66338
|
+
let notifyScheduled = false;
|
|
66339
|
+
const runNotify = () => {
|
|
66340
|
+
batch(() => {
|
|
66341
|
+
const itemRows = [];
|
|
66342
|
+
for (const row of rowById.values()) {
|
|
66343
|
+
if (row.item) {
|
|
66344
|
+
itemRows.push(row);
|
|
66345
|
+
}
|
|
66350
66346
|
}
|
|
66351
|
-
|
|
66352
|
-
|
|
66353
|
-
|
|
66354
|
-
|
|
66355
|
-
|
|
66347
|
+
itemRows.sort(compareRowPlaces);
|
|
66348
|
+
const items = [];
|
|
66349
|
+
const visibleItems = [];
|
|
66350
|
+
let noMatchCount = 0;
|
|
66351
|
+
const countByGroup = new Map();
|
|
66352
|
+
const noMatchCountByGroup = new Map();
|
|
66353
|
+
const prevItems = itemsSignal.peek();
|
|
66354
|
+
const prevVisibleItems = visibleItemsSignal.peek();
|
|
66355
|
+
let itemsChanged = prevItems.length !== itemRows.length;
|
|
66356
|
+
let visibleItemsChanged = false;
|
|
66357
|
+
for (const row of itemRows) {
|
|
66358
|
+
const item = row.data;
|
|
66359
|
+
// Compared by reference: any prop change (selected, disabled, …) is a
|
|
66360
|
+
// new props object.
|
|
66361
|
+
if (!itemsChanged && item !== prevItems[items.length]) {
|
|
66362
|
+
itemsChanged = true;
|
|
66363
|
+
}
|
|
66364
|
+
items.push(item);
|
|
66365
|
+
const noMatch = item.match === false;
|
|
66366
|
+
if (noMatch) {
|
|
66367
|
+
noMatchCount++;
|
|
66368
|
+
}
|
|
66369
|
+
if (row.groupId !== undefined) {
|
|
66370
|
+
countByGroup.set(
|
|
66371
|
+
row.groupId,
|
|
66372
|
+
(countByGroup.get(row.groupId) || 0) + 1,
|
|
66373
|
+
);
|
|
66374
|
+
if (noMatch) {
|
|
66375
|
+
noMatchCountByGroup.set(
|
|
66376
|
+
row.groupId,
|
|
66377
|
+
(noMatchCountByGroup.get(row.groupId) || 0) + 1,
|
|
66378
|
+
);
|
|
66379
|
+
}
|
|
66380
|
+
}
|
|
66381
|
+
if (row.visible) {
|
|
66382
|
+
if (
|
|
66383
|
+
!visibleItemsChanged &&
|
|
66384
|
+
item !== prevVisibleItems[visibleItems.length]
|
|
66385
|
+
) {
|
|
66386
|
+
visibleItemsChanged = true;
|
|
66387
|
+
}
|
|
66388
|
+
visibleItems.push(item);
|
|
66389
|
+
}
|
|
66390
|
+
}
|
|
66391
|
+
if (visibleItems.length !== prevVisibleItems.length) {
|
|
66392
|
+
visibleItemsChanged = true;
|
|
66393
|
+
}
|
|
66394
|
+
let someChange = false;
|
|
66395
|
+
if (countSignal.peek() !== items.length) {
|
|
66396
|
+
countSignal.value = items.length;
|
|
66397
|
+
someChange = true;
|
|
66398
|
+
}
|
|
66399
|
+
if (visibleCountSignal.peek() !== visibleItems.length) {
|
|
66400
|
+
visibleCountSignal.value = visibleItems.length;
|
|
66401
|
+
someChange = true;
|
|
66402
|
+
}
|
|
66403
|
+
if (itemsChanged) {
|
|
66404
|
+
itemsSignal.value = items;
|
|
66405
|
+
someChange = true;
|
|
66406
|
+
}
|
|
66407
|
+
if (visibleItemsChanged) {
|
|
66408
|
+
visibleItemsSignal.value = visibleItems;
|
|
66409
|
+
someChange = true;
|
|
66410
|
+
}
|
|
66411
|
+
if (noMatchCountSignal.peek() !== noMatchCount) {
|
|
66412
|
+
noMatchCountSignal.value = noMatchCount;
|
|
66413
|
+
someChange = true;
|
|
66414
|
+
}
|
|
66415
|
+
for (const [groupId, group] of groupById) {
|
|
66416
|
+
group.countSignal.value = countByGroup.get(groupId) || 0;
|
|
66417
|
+
group.noMatchCountSignal.value = noMatchCountByGroup.get(groupId) || 0;
|
|
66418
|
+
}
|
|
66419
|
+
if (someChange && listRows.onChange) {
|
|
66420
|
+
listRows.onChange();
|
|
66421
|
+
}
|
|
66422
|
+
});
|
|
66356
66423
|
};
|
|
66357
|
-
|
|
66358
|
-
|
|
66359
|
-
|
|
66360
|
-
idToKey.set(id, keyCounter++);
|
|
66424
|
+
const notify = () => {
|
|
66425
|
+
if (notifyScheduled) {
|
|
66426
|
+
return;
|
|
66361
66427
|
}
|
|
66362
|
-
|
|
66363
|
-
|
|
66364
|
-
|
|
66365
|
-
|
|
66366
|
-
|
|
66367
|
-
|
|
66368
|
-
|
|
66369
|
-
|
|
66370
|
-
const { id, index } = data;
|
|
66371
|
-
const key = keyForId(id);
|
|
66372
|
-
|
|
66373
|
-
syncItem(key, index, data);
|
|
66374
|
-
notify();
|
|
66375
|
-
|
|
66376
|
-
useLayoutEffect(() => {
|
|
66377
|
-
return () => {
|
|
66378
|
-
unregisterKey(key);
|
|
66379
|
-
notify();
|
|
66380
|
-
};
|
|
66381
|
-
}, []);
|
|
66382
|
-
|
|
66383
|
-
if (data.filtered || data.hidden || data.role === "presentation") {
|
|
66384
|
-
return -1;
|
|
66385
|
-
}
|
|
66386
|
-
return keyToOrderedIndex.get(key) ?? -1;
|
|
66387
|
-
};
|
|
66388
|
-
|
|
66389
|
-
const getTrackedItemByIndex = (index) => {
|
|
66390
|
-
const key = orderedKeys[index];
|
|
66391
|
-
if (key === undefined) {
|
|
66392
|
-
return undefined;
|
|
66393
|
-
}
|
|
66394
|
-
return registrations.get(key);
|
|
66395
|
-
};
|
|
66396
|
-
|
|
66397
|
-
// The items as they stand right now, notification pending or not — same
|
|
66398
|
-
// content as itemsSignal, minus the wait.
|
|
66399
|
-
//
|
|
66400
|
-
// Items register during their own render, while the signal is only updated
|
|
66401
|
-
// on a deferred microtask (see notify): a sibling rendering after them would
|
|
66402
|
-
// otherwise paint from an empty list and correct itself a frame later. That
|
|
66403
|
-
// frame is visible whenever the painted size feeds a layout decision — a
|
|
66404
|
-
// dialog sizing itself on its content measures the empty version and shifts
|
|
66405
|
-
// once the real one lands. Reading this instead makes the first paint the
|
|
66406
|
-
// right one. Callers must still subscribe to itemsSignal to re-render on
|
|
66407
|
-
// LATER changes; this is the value to display, not the notification.
|
|
66408
|
-
const peekItems = () => {
|
|
66409
|
-
if (!notifyScheduled) {
|
|
66410
|
-
return itemsSignal.peek();
|
|
66411
|
-
}
|
|
66412
|
-
const items = [];
|
|
66413
|
-
for (const key of allOrderedKeys) {
|
|
66414
|
-
items.push(allRegistrations.get(key));
|
|
66415
|
-
}
|
|
66416
|
-
return items;
|
|
66428
|
+
notifyScheduled = true;
|
|
66429
|
+
queueMicrotask(() => {
|
|
66430
|
+
if (!notifyScheduled) {
|
|
66431
|
+
return;
|
|
66432
|
+
}
|
|
66433
|
+
notifyScheduled = false;
|
|
66434
|
+
runNotify();
|
|
66435
|
+
});
|
|
66417
66436
|
};
|
|
66418
66437
|
|
|
66419
|
-
|
|
66420
|
-
|
|
66421
|
-
|
|
66422
|
-
|
|
66438
|
+
const listRows = {
|
|
66439
|
+
totalSignal,
|
|
66440
|
+
pagesSignal,
|
|
66441
|
+
refreshingSignal,
|
|
66442
|
+
// The rows that are items, in place order — every one drawn, and the ones
|
|
66443
|
+
// that show — and what the search made of them. Written once per frame.
|
|
66423
66444
|
itemsSignal,
|
|
66424
66445
|
visibleItemsSignal,
|
|
66425
66446
|
countSignal,
|
|
66426
66447
|
visibleCountSignal,
|
|
66427
66448
|
noMatchCountSignal,
|
|
66428
|
-
|
|
66449
|
+
// Called once per frame in which the items changed. Set by the list.
|
|
66450
|
+
onChange: null,
|
|
66451
|
+
// What a run needs to know about the list it lives in: how many rows the
|
|
66452
|
+
// list is willing to draw at once, which end it opens on, and how much
|
|
66453
|
+
// room one row is given — a row whose content has not arrived must take
|
|
66454
|
+
// exactly that, or the rows drawn would not reach where the list says they
|
|
66455
|
+
// are.
|
|
66456
|
+
renderBudget: 0,
|
|
66457
|
+
scrolled: "start",
|
|
66458
|
+
// The list is on its way somewhere: what the window frames is not what it
|
|
66459
|
+
// is about to frame, so a run must not fetch for it (see holdWindow).
|
|
66460
|
+
holdPending: false,
|
|
66461
|
+
// Called by a run just before rows land in it: what is on screen must not
|
|
66462
|
+
// move because something arrived above it. Set by the list itself.
|
|
66463
|
+
captureAnchor: () => {},
|
|
66464
|
+
horizontal: false,
|
|
66465
|
+
virtualItemSizeSignal: null,
|
|
66466
|
+
renderSkeleton: undefined,
|
|
66467
|
+
// The children a walk stands over, in order — said in one call, before any
|
|
66468
|
+
// of them renders, so that what a child asks next is answered against the
|
|
66469
|
+
// whole picture and not against the children that happened to render
|
|
66470
|
+
// first. Said again on every render of the walk, and heard only when
|
|
66471
|
+
// something moved.
|
|
66472
|
+
declareSlots: (parentSlotId, slotIds) => {
|
|
66473
|
+
const slotIdsPrevious = slotIdsByParent.get(parentSlotId);
|
|
66474
|
+
if (slotIdsPrevious && sameSlotIds(slotIdsPrevious, slotIds)) {
|
|
66475
|
+
return;
|
|
66476
|
+
}
|
|
66477
|
+
if (slotIdsPrevious) {
|
|
66478
|
+
const slotIdSet = new Set(slotIds);
|
|
66479
|
+
for (const slotId of slotIdsPrevious) {
|
|
66480
|
+
if (!slotIdSet.has(slotId)) {
|
|
66481
|
+
dropSlot(slotId);
|
|
66482
|
+
}
|
|
66483
|
+
}
|
|
66484
|
+
}
|
|
66485
|
+
slotIdsByParent.set(parentSlotId, slotIds);
|
|
66486
|
+
rebuildWalk();
|
|
66487
|
+
refreshPlaces();
|
|
66488
|
+
},
|
|
66489
|
+
// Whether something has taken this slot for its own: what it renders
|
|
66490
|
+
// inside is then its to place (a run draws its groups with their rows
|
|
66491
|
+
// already placed), and no walk inside it has anything to declare.
|
|
66492
|
+
slotHasOwner: (slotId) => ownerIdsBySlot.has(slotId),
|
|
66493
|
+
// Whether any run of rows lives in this list: what makes a render window
|
|
66494
|
+
// mean anything (see List's renderBudget).
|
|
66495
|
+
hasRuns: () => locatorByOwner.size > 0,
|
|
66496
|
+
setRowLocator: (ownerId, locate) => {
|
|
66497
|
+
locatorByOwner.set(ownerId, locate);
|
|
66498
|
+
},
|
|
66499
|
+
dropRowLocator: (ownerId) => {
|
|
66500
|
+
locatorByOwner.delete(ownerId);
|
|
66501
|
+
},
|
|
66502
|
+
// Where the row named by that id sits, asked of whoever holds it.
|
|
66503
|
+
locateRow: (id) => {
|
|
66504
|
+
for (const locate of locatorByOwner.values()) {
|
|
66505
|
+
const index = locate(id);
|
|
66506
|
+
if (index !== null) {
|
|
66507
|
+
return index;
|
|
66508
|
+
}
|
|
66509
|
+
}
|
|
66510
|
+
return null;
|
|
66511
|
+
},
|
|
66512
|
+
// The place the owner's rows start at — read from a signal, so that the
|
|
66513
|
+
// owner is rendered again when it moves (see the top of this file). Asked on
|
|
66514
|
+
// every render, and answered without a second look for as long as the
|
|
66515
|
+
// owner stands in the same slot for the same number of rows.
|
|
66516
|
+
take: (ownerId, rowCount, slotId) => {
|
|
66517
|
+
let owner = ownerById.get(ownerId);
|
|
66518
|
+
if (owner) {
|
|
66519
|
+
if (owner.slotId !== slotId || owner.rowCount !== rowCount) {
|
|
66520
|
+
removeFromSlot(owner.slotId, ownerId);
|
|
66521
|
+
addToSlot(slotId, ownerId);
|
|
66522
|
+
owner.slotId = slotId;
|
|
66523
|
+
owner.rowCount = rowCount;
|
|
66524
|
+
placesStale = true;
|
|
66525
|
+
}
|
|
66526
|
+
if (placesStale) {
|
|
66527
|
+
refreshPlaces();
|
|
66528
|
+
}
|
|
66529
|
+
return owner.placeSignal.value;
|
|
66530
|
+
}
|
|
66531
|
+
if (placesStale) {
|
|
66532
|
+
refreshPlaces();
|
|
66533
|
+
}
|
|
66534
|
+
const rank = rankBySlot.get(slotId);
|
|
66535
|
+
addToSlot(slotId, ownerId);
|
|
66536
|
+
if (rank !== undefined && rank >= rankOwnedLast) {
|
|
66537
|
+
owner = { slotId, rowCount, placeSignal: signal(rowTotal) };
|
|
66538
|
+
ownerById.set(ownerId, owner);
|
|
66539
|
+
rowTotal += rowCount;
|
|
66540
|
+
rankOwnedLast = rank;
|
|
66541
|
+
totalSignal.value = rowTotal;
|
|
66542
|
+
return owner.placeSignal.value;
|
|
66543
|
+
}
|
|
66544
|
+
owner = { slotId, rowCount, placeSignal: signal(0) };
|
|
66545
|
+
ownerById.set(ownerId, owner);
|
|
66546
|
+
refreshPlaces();
|
|
66547
|
+
return owner.placeSignal.value;
|
|
66548
|
+
},
|
|
66549
|
+
// The owner stands for no row of the collection: it was filtered out by a
|
|
66550
|
+
// search, or it is gone.
|
|
66551
|
+
drop: (ownerId) => {
|
|
66552
|
+
const owner = ownerById.get(ownerId);
|
|
66553
|
+
if (!owner) {
|
|
66554
|
+
return;
|
|
66555
|
+
}
|
|
66556
|
+
ownerById.delete(ownerId);
|
|
66557
|
+
removeFromSlot(owner.slotId, ownerId);
|
|
66558
|
+
windowByOwner.delete(ownerId);
|
|
66559
|
+
if (placesStale) {
|
|
66560
|
+
return;
|
|
66561
|
+
}
|
|
66562
|
+
placesStale = true;
|
|
66563
|
+
queueMicrotask(() => {
|
|
66564
|
+
if (placesStale) {
|
|
66565
|
+
refreshPlaces();
|
|
66566
|
+
}
|
|
66567
|
+
});
|
|
66568
|
+
},
|
|
66569
|
+
|
|
66570
|
+
// ---- the rows drawn ----
|
|
66571
|
+
|
|
66572
|
+
// A run says which of its rows it draws. The others stand: rows above the
|
|
66573
|
+
// window are above every row drawn, whether or not any of the drawn ones
|
|
66574
|
+
// mounts (see refreshFirst).
|
|
66575
|
+
declareWindow: (ownerId, from, to) => {
|
|
66576
|
+
const window = windowByOwner.get(ownerId);
|
|
66577
|
+
if (window && window.from === from && window.to === to) {
|
|
66578
|
+
return;
|
|
66579
|
+
}
|
|
66580
|
+
windowByOwner.set(ownerId, { from, to });
|
|
66581
|
+
markStale(UNGROUPED);
|
|
66582
|
+
},
|
|
66583
|
+
// A row says what it is, where it renders: its place, the group it is
|
|
66584
|
+
// in, and its data — from which follows whether it mounts at all
|
|
66585
|
+
// (filtered out), whether it shows (hidden keeps the room, not the
|
|
66586
|
+
// content), and whether it is an item (a group wrapper, a skeleton, are
|
|
66587
|
+
// rows of the list but items of nobody). Said in the name of the
|
|
66588
|
+
// component, not of the item id: two components may stand for one item for
|
|
66589
|
+
// a moment, one leaving as the other arrives.
|
|
66590
|
+
draw: (rowId, { ownerId, place, groupId, data }) => {
|
|
66591
|
+
const mounted = !data.filtered;
|
|
66592
|
+
const visible = mounted && !data.hidden;
|
|
66593
|
+
const item = !data.skeleton && data.role !== "presentation";
|
|
66594
|
+
let row = rowById.get(rowId);
|
|
66595
|
+
if (row) {
|
|
66596
|
+
if (
|
|
66597
|
+
row.mounted &&
|
|
66598
|
+
(row.place !== place || row.groupId !== groupId || !mounted)
|
|
66599
|
+
) {
|
|
66600
|
+
leaveFirst(row);
|
|
66601
|
+
}
|
|
66602
|
+
row.ownerId = ownerId;
|
|
66603
|
+
row.place = place;
|
|
66604
|
+
row.groupId = groupId;
|
|
66605
|
+
row.data = data;
|
|
66606
|
+
row.mounted = mounted;
|
|
66607
|
+
row.visible = visible;
|
|
66608
|
+
row.item = item;
|
|
66609
|
+
} else {
|
|
66610
|
+
row = { ownerId, place, groupId, data, mounted, visible, item };
|
|
66611
|
+
rowById.set(rowId, row);
|
|
66612
|
+
}
|
|
66613
|
+
if (mounted) {
|
|
66614
|
+
const firstSignal = firstSignalOf(scopeOf(groupId));
|
|
66615
|
+
const first = firstSignal.peek();
|
|
66616
|
+
if (first === -1 || place < first) {
|
|
66617
|
+
firstSignal.value = place;
|
|
66618
|
+
}
|
|
66619
|
+
}
|
|
66620
|
+
notify();
|
|
66621
|
+
},
|
|
66622
|
+
// The row is gone. A declared row is its own owner and gives its place
|
|
66623
|
+
// back with it; a run's row leaves the run's places alone.
|
|
66624
|
+
erase: (rowId) => {
|
|
66625
|
+
const row = rowById.get(rowId);
|
|
66626
|
+
if (!row) {
|
|
66627
|
+
return;
|
|
66628
|
+
}
|
|
66629
|
+
rowById.delete(rowId);
|
|
66630
|
+
if (row.mounted) {
|
|
66631
|
+
leaveFirst(row);
|
|
66632
|
+
}
|
|
66633
|
+
if (row.ownerId === rowId) {
|
|
66634
|
+
listRows.drop(rowId);
|
|
66635
|
+
}
|
|
66636
|
+
notify();
|
|
66637
|
+
},
|
|
66638
|
+
// Whether nothing of the list stands above this row: in its group, no
|
|
66639
|
+
// other row of the group mounts before it; outside groups, no row mounts
|
|
66640
|
+
// before it and no run has rows above its window before it. Answered from
|
|
66641
|
+
// a signal, so a row rendered from a kept vnode is rendered again when the
|
|
66642
|
+
// row before it leaves or comes back.
|
|
66643
|
+
isFirst: (rowId) => {
|
|
66644
|
+
const row = rowById.get(rowId);
|
|
66645
|
+
const scope = scopeOf(row.groupId);
|
|
66646
|
+
if (staleScopes.has(scope)) {
|
|
66647
|
+
refreshFirst(scope);
|
|
66648
|
+
}
|
|
66649
|
+
return firstSignalOf(scope).value === row.place;
|
|
66650
|
+
},
|
|
66651
|
+
// What a group knows about its rows: how many, and how many of them the
|
|
66652
|
+
// search left out (see ListItemGroup).
|
|
66653
|
+
group: (groupId) => groupOf(groupId),
|
|
66654
|
+
dropGroup: (groupId) => {
|
|
66655
|
+
groupById.delete(groupId);
|
|
66656
|
+
staleScopes.delete(groupId);
|
|
66657
|
+
},
|
|
66658
|
+
// Written when a frame's rows have settled (see notify); the value to act
|
|
66659
|
+
// on is peeked from wherever the change is heard.
|
|
66660
|
+
flushSync: () => {
|
|
66661
|
+
if (!notifyScheduled) {
|
|
66662
|
+
return;
|
|
66663
|
+
}
|
|
66664
|
+
notifyScheduled = false;
|
|
66665
|
+
runNotify();
|
|
66666
|
+
},
|
|
66429
66667
|
};
|
|
66668
|
+
return listRows;
|
|
66430
66669
|
};
|
|
66431
|
-
|
|
66432
|
-
|
|
66433
|
-
|
|
66434
|
-
if (props.header) {
|
|
66435
|
-
return renderResolver(ListItemHeader, props);
|
|
66670
|
+
const sameSlotIds = (left, right) => {
|
|
66671
|
+
if (left.length !== right.length) {
|
|
66672
|
+
return false;
|
|
66436
66673
|
}
|
|
66437
|
-
|
|
66438
|
-
|
|
66674
|
+
let index = 0;
|
|
66675
|
+
while (index < left.length) {
|
|
66676
|
+
if (left[index] !== right[index]) {
|
|
66677
|
+
return false;
|
|
66678
|
+
}
|
|
66679
|
+
index++;
|
|
66439
66680
|
}
|
|
66440
|
-
return
|
|
66441
|
-
...props
|
|
66442
|
-
});
|
|
66681
|
+
return true;
|
|
66443
66682
|
};
|
|
66444
|
-
|
|
66445
|
-
|
|
66446
|
-
|
|
66447
|
-
|
|
66448
|
-
|
|
66449
|
-
|
|
66450
|
-
|
|
66451
|
-
|
|
66452
|
-
|
|
66453
|
-
|
|
66454
|
-
}, []);
|
|
66455
|
-
return jsx(Next, {
|
|
66456
|
-
...props,
|
|
66457
|
-
header: undefined,
|
|
66458
|
-
role: "presentation",
|
|
66459
|
-
baseClassName: "navi_list_item_header"
|
|
66460
|
-
});
|
|
66461
|
-
};
|
|
66462
|
-
const ListItemFooter = props => {
|
|
66463
|
-
const Next = useNextResolver();
|
|
66464
|
-
const {
|
|
66465
|
-
ref
|
|
66466
|
-
} = props;
|
|
66467
|
-
useDisplayedLayoutEffect(ref, footerEl => {
|
|
66468
|
-
const listContainerEl = footerEl.closest(".navi_list_container");
|
|
66469
|
-
const rect = footerEl.getBoundingClientRect();
|
|
66470
|
-
listContainerEl.style.setProperty("--list-footer-height", `${rect.height}px`);
|
|
66471
|
-
listContainerEl.style.setProperty("--list-footer-width", `${rect.width}px`);
|
|
66472
|
-
}, []);
|
|
66473
|
-
return jsx(Next, {
|
|
66474
|
-
...props,
|
|
66475
|
-
footer: undefined,
|
|
66476
|
-
role: "presentation",
|
|
66477
|
-
baseClassName: "navi_list_item_footer"
|
|
66478
|
-
});
|
|
66683
|
+
|
|
66684
|
+
// Rows in place order; a row with no place (a declared row filtered out) last.
|
|
66685
|
+
const compareRowPlaces = (left, right) => {
|
|
66686
|
+
if (left.place === undefined) {
|
|
66687
|
+
return right.place === undefined ? 0 : 1;
|
|
66688
|
+
}
|
|
66689
|
+
if (right.place === undefined) {
|
|
66690
|
+
return -1;
|
|
66691
|
+
}
|
|
66692
|
+
return left.place - right.place;
|
|
66479
66693
|
};
|
|
66480
66694
|
|
|
66481
66695
|
// What a row may say it is waiting on, all of them about the row as a thing
|
|
@@ -67283,8 +67497,10 @@ const applySearchHighlight = (el, highlight) => {
|
|
|
67283
67497
|
};
|
|
67284
67498
|
|
|
67285
67499
|
installImportMetaCssBuild(import.meta);
|
|
67286
|
-
const
|
|
67287
|
-
|
|
67500
|
+
const ListRowsContext = createContext(null);
|
|
67501
|
+
// The group a row is declared in, by id (see ListItemGroup): what its count
|
|
67502
|
+
// and its separator are scoped to.
|
|
67503
|
+
const ListGroupContext = createContext(undefined);
|
|
67288
67504
|
const PendingScrollRefContext = createContext(null);
|
|
67289
67505
|
// Controls how List.Item behaves when match=false (set via List searchNoMatchMode prop):
|
|
67290
67506
|
// "remove" — remove from DOM (default)
|
|
@@ -67323,21 +67539,15 @@ const SeparatorContext = createContext(null);
|
|
|
67323
67539
|
// Set by <List itemTransition>: each row then gets a view-transition-name of
|
|
67324
67540
|
// its own, so a change wrapped in a view transition animates row by row.
|
|
67325
67541
|
const ItemTransitionContext = createContext(false);
|
|
67326
|
-
// What the list knows about the collection as a whole: how many rows it has,
|
|
67327
|
-
// which of them it actually holds, and where each child's rows start. Filled in
|
|
67328
|
-
// by the children as they render (see createListVirtual), read by everything
|
|
67329
|
-
// that must reserve room for what is not rendered.
|
|
67330
|
-
const ListVirtualContext = createContext(null);
|
|
67331
67542
|
// Set around each row a run of items renders (see ListItems): which row of the
|
|
67332
|
-
// collection it is, where it stands among the rows the list holds, and
|
|
67333
|
-
// run
|
|
67334
|
-
//
|
|
67335
|
-
//
|
|
67336
|
-
// own — instead of a bare <List.Item> — works the same way.
|
|
67543
|
+
// collection it is, where it stands among the rows the list holds, and which
|
|
67544
|
+
// run it belongs to. Carried by context rather than injected into whatever
|
|
67545
|
+
// vnode renderItem returned, so that returning a component of one's own —
|
|
67546
|
+
// instead of a bare <List.Item> — works the same way.
|
|
67337
67547
|
const ListRowContext = createContext(null);
|
|
67338
67548
|
// The slot a child of the list stands in, by id (see ListDeclaredChildren). A
|
|
67339
67549
|
// row takes its place in the collection by slot: the place is then the list's
|
|
67340
|
-
// to move, and the row's to follow — see
|
|
67550
|
+
// to move, and the row's to follow — see list_rows.js.
|
|
67341
67551
|
const ListSlotContext = createContext(null);
|
|
67342
67552
|
const css$x = /* css */`@layer navi {
|
|
67343
67553
|
.navi_list_container {
|
|
@@ -67828,7 +68038,7 @@ const ListUI = props => {
|
|
|
67828
68038
|
overflow,
|
|
67829
68039
|
overflowX,
|
|
67830
68040
|
overflowY,
|
|
67831
|
-
|
|
68041
|
+
listRows,
|
|
67832
68042
|
...rest
|
|
67833
68043
|
} = props;
|
|
67834
68044
|
const scrollBoxPaddingProps = {};
|
|
@@ -67897,16 +68107,19 @@ const ListUI = props => {
|
|
|
67897
68107
|
observer.disconnect();
|
|
67898
68108
|
};
|
|
67899
68109
|
}, [lockSize]);
|
|
67900
|
-
|
|
67901
|
-
|
|
67902
|
-
|
|
67903
|
-
|
|
68110
|
+
listRows.onChange = () => {
|
|
68111
|
+
onListVisibleItemsChange?.(listRows.visibleItemsSignal.peek());
|
|
68112
|
+
};
|
|
68113
|
+
// Code in a layout effect of the list reads the rows as they stand after
|
|
68114
|
+
// the commit; the rows settle on a microtask, which preact does not wait for.
|
|
68115
|
+
useLayoutEffect(() => {
|
|
68116
|
+
listRows.flushSync();
|
|
67904
68117
|
});
|
|
67905
68118
|
// What the runs ask for and stand for: the steady budget, whatever the
|
|
67906
68119
|
// window of the first paint draws — a run asking for the rows of the first
|
|
67907
68120
|
// picture and then for the rest is two round trips for one opening.
|
|
67908
|
-
|
|
67909
|
-
|
|
68121
|
+
listRows.renderBudget = renderBudgetAfterPaint;
|
|
68122
|
+
listRows.scrolled = scrolled ?? defaultScrolled;
|
|
67910
68123
|
const {
|
|
67911
68124
|
virtualItemSizeSignal,
|
|
67912
68125
|
renderWindow,
|
|
@@ -67915,11 +68128,10 @@ const ListUI = props => {
|
|
|
67915
68128
|
captureAnchor
|
|
67916
68129
|
} = useListScrollSync({
|
|
67917
68130
|
ref,
|
|
67918
|
-
|
|
68131
|
+
listRows,
|
|
67919
68132
|
renderBudget,
|
|
67920
68133
|
renderBudgetSteady: renderBudgetAfterPaint,
|
|
67921
68134
|
virtualItemSize,
|
|
67922
|
-
virtual,
|
|
67923
68135
|
scrolled,
|
|
67924
68136
|
defaultScrolled,
|
|
67925
68137
|
onScrolledChange,
|
|
@@ -67938,28 +68150,28 @@ const ListUI = props => {
|
|
|
67938
68150
|
if (props.renderBudget === undefined || renderBudgetWarnedRef.current) {
|
|
67939
68151
|
return;
|
|
67940
68152
|
}
|
|
67941
|
-
if (
|
|
68153
|
+
if (listRows.hasRuns() || listRows.itemsSignal.peek().length === 0) {
|
|
67942
68154
|
return;
|
|
67943
68155
|
}
|
|
67944
68156
|
renderBudgetWarnedRef.current = true;
|
|
67945
68157
|
console.warn(`List: renderBudget=${renderBudget} has no effect here. The render window frames the rows a run draws (<List.Items itemsAction>); items declared one by one (<List.Item>) are all rendered. Move the items to <List.Items> to cap the number of DOM nodes, or drop the prop.`);
|
|
67946
68158
|
});
|
|
67947
|
-
|
|
67948
|
-
|
|
67949
|
-
|
|
67950
|
-
|
|
68159
|
+
listRows.captureAnchor = captureAnchor;
|
|
68160
|
+
listRows.virtualItemSizeSignal = virtualItemSizeSignal;
|
|
68161
|
+
listRows.horizontal = Boolean(horizontal);
|
|
68162
|
+
listRows.renderSkeleton = renderSkeleton;
|
|
67951
68163
|
|
|
67952
68164
|
// A row is addressed by id from outside (--navi-scroll, --navi-select): the
|
|
67953
|
-
// ones drawn have
|
|
68165
|
+
// ones drawn have said so (see list_rows.js), and the ones a run
|
|
67954
68166
|
// holds without drawing are known only to that run (see List.Items' row
|
|
67955
68167
|
// locator). Both answer here, so a row is reachable whether or not the
|
|
67956
68168
|
// window happens to frame it.
|
|
67957
68169
|
const getItemById = itemId => {
|
|
67958
|
-
const itemDrawn =
|
|
68170
|
+
const itemDrawn = listRows.itemsSignal.peek().find(item => item.id === itemId);
|
|
67959
68171
|
if (itemDrawn) {
|
|
67960
68172
|
return itemDrawn;
|
|
67961
68173
|
}
|
|
67962
|
-
const rowIndex =
|
|
68174
|
+
const rowIndex = listRows.locateRow(itemId);
|
|
67963
68175
|
if (rowIndex === null) {
|
|
67964
68176
|
return undefined;
|
|
67965
68177
|
}
|
|
@@ -67968,13 +68180,13 @@ const ListUI = props => {
|
|
|
67968
68180
|
index: rowIndex
|
|
67969
68181
|
};
|
|
67970
68182
|
};
|
|
67971
|
-
const noMatchCount =
|
|
68183
|
+
const noMatchCount = listRows.noMatchCountSignal.value;
|
|
67972
68184
|
// What the list stands for, which is not always what it holds: a run saying
|
|
67973
68185
|
// it covers 60 rows is not an empty list while it waits for the first of
|
|
67974
68186
|
// them (see List.Items).
|
|
67975
68187
|
// eslint-disable-next-line no-unused-expressions
|
|
67976
|
-
|
|
67977
|
-
const itemCount =
|
|
68188
|
+
listRows.pagesSignal.value;
|
|
68189
|
+
const itemCount = listRows.countSignal.value || listRows.totalSignal.value;
|
|
67978
68190
|
const allNoMatch = noMatchCount > 0 && noMatchCount === itemCount;
|
|
67979
68191
|
const searching = Boolean(searchText);
|
|
67980
68192
|
const fallbackDisabled = fallback !== undefined && !fallback;
|
|
@@ -68072,7 +68284,7 @@ const ListUI = props => {
|
|
|
68072
68284
|
expand: expand,
|
|
68073
68285
|
"navi-nothing-to-display": nothingToDisplay ? "" : undefined,
|
|
68074
68286
|
"navi-loading": loading ? "" : undefined,
|
|
68075
|
-
"navi-refreshing":
|
|
68287
|
+
"navi-refreshing": listRows.refreshingSignal.value ? "" : undefined,
|
|
68076
68288
|
"navi-error": error ? "" : undefined,
|
|
68077
68289
|
styleCSSVars: LIST_STYLE_CSS_VARS,
|
|
68078
68290
|
pseudoClasses: LIST_PSEUDO_CLASSES,
|
|
@@ -68108,9 +68320,8 @@ const ListUI = props => {
|
|
|
68108
68320
|
spacing: spacing,
|
|
68109
68321
|
columns: columns,
|
|
68110
68322
|
itemColumns: itemColumns,
|
|
68111
|
-
|
|
68323
|
+
listRows: listRows,
|
|
68112
68324
|
renderWindow: renderWindow,
|
|
68113
|
-
virtual: virtual,
|
|
68114
68325
|
pendingScrollRef: pendingScrollRef,
|
|
68115
68326
|
overflow: overflow,
|
|
68116
68327
|
overflowX: overflowX,
|
|
@@ -68131,11 +68342,11 @@ const ListFirstResolver = props => {
|
|
|
68131
68342
|
props.ref = props.ref || refDefault;
|
|
68132
68343
|
const idDefault = useId();
|
|
68133
68344
|
props.id = props.id || idDefault;
|
|
68134
|
-
const
|
|
68135
|
-
if (!
|
|
68136
|
-
|
|
68345
|
+
const listRowsRef = useRef(null);
|
|
68346
|
+
if (!listRowsRef.current) {
|
|
68347
|
+
listRowsRef.current = createListRows();
|
|
68137
68348
|
}
|
|
68138
|
-
props.
|
|
68349
|
+
props.listRows = listRowsRef.current;
|
|
68139
68350
|
const parallelGuard = useParallelGuard(props.parallelGuard ?? PARALLEL_GUARD_DEFAULT);
|
|
68140
68351
|
return jsx(ParallelGuardContext.Provider, {
|
|
68141
68352
|
value: parallelGuard,
|
|
@@ -68161,9 +68372,8 @@ const ListContent = ({
|
|
|
68161
68372
|
spacing,
|
|
68162
68373
|
columns,
|
|
68163
68374
|
itemColumns,
|
|
68164
|
-
|
|
68375
|
+
listRows,
|
|
68165
68376
|
renderWindow,
|
|
68166
|
-
virtual,
|
|
68167
68377
|
pendingScrollRef,
|
|
68168
68378
|
overflow,
|
|
68169
68379
|
overflowX,
|
|
@@ -68217,9 +68427,8 @@ const ListContent = ({
|
|
|
68217
68427
|
columns: columns,
|
|
68218
68428
|
itemColumns: itemColumns,
|
|
68219
68429
|
...listProps,
|
|
68220
|
-
|
|
68430
|
+
listRows: listRows,
|
|
68221
68431
|
renderWindow: renderWindow,
|
|
68222
|
-
virtual: virtual,
|
|
68223
68432
|
children: children
|
|
68224
68433
|
})
|
|
68225
68434
|
})
|
|
@@ -68243,11 +68452,10 @@ const LIST_STYLE_CSS_VARS = {
|
|
|
68243
68452
|
const LIST_PSEUDO_CLASSES = [":hover", ":focus", ":focus-visible", ":focus-within", ":read-only", ":disabled", ":-navi-void", ":-navi-expanded"];
|
|
68244
68453
|
const useListScrollSync = ({
|
|
68245
68454
|
ref,
|
|
68246
|
-
|
|
68455
|
+
listRows,
|
|
68247
68456
|
renderBudget,
|
|
68248
68457
|
renderBudgetSteady,
|
|
68249
68458
|
virtualItemSize,
|
|
68250
|
-
virtual,
|
|
68251
68459
|
scrolled,
|
|
68252
68460
|
defaultScrolled,
|
|
68253
68461
|
onScrolledChange,
|
|
@@ -68257,7 +68465,7 @@ const useListScrollSync = ({
|
|
|
68257
68465
|
}) => {
|
|
68258
68466
|
const debugScroll = useDebugScroll();
|
|
68259
68467
|
const virtualItemSizeSignal = useVirtualItemSizeSignal(ref, virtualItemSize, horizontal, {
|
|
68260
|
-
|
|
68468
|
+
listRows,
|
|
68261
68469
|
renderBudget,
|
|
68262
68470
|
scrolledWanted: scrolled ?? defaultScrolled
|
|
68263
68471
|
});
|
|
@@ -68282,7 +68490,7 @@ const useListScrollSync = ({
|
|
|
68282
68490
|
ref,
|
|
68283
68491
|
scrollerElResolved,
|
|
68284
68492
|
renderBudget,
|
|
68285
|
-
totalSignal:
|
|
68493
|
+
totalSignal: listRows.totalSignal,
|
|
68286
68494
|
virtualItemSizeSignal,
|
|
68287
68495
|
horizontal
|
|
68288
68496
|
});
|
|
@@ -68307,7 +68515,7 @@ const useListScrollSync = ({
|
|
|
68307
68515
|
anchorRef.current = captureScrollAnchor({
|
|
68308
68516
|
scrollerEl: getScroller(),
|
|
68309
68517
|
listEl: getListEl(),
|
|
68310
|
-
items:
|
|
68518
|
+
items: listRows.visibleItemsSignal.peek(),
|
|
68311
68519
|
horizontal
|
|
68312
68520
|
});
|
|
68313
68521
|
};
|
|
@@ -68339,7 +68547,7 @@ const useListScrollSync = ({
|
|
|
68339
68547
|
start,
|
|
68340
68548
|
end
|
|
68341
68549
|
} = renderWindowRef.current;
|
|
68342
|
-
const total =
|
|
68550
|
+
const total = listRows.totalSignal.peek();
|
|
68343
68551
|
let framedStart = start;
|
|
68344
68552
|
let framedEnd = start + renderBudget;
|
|
68345
68553
|
if (total > 0 && framedEnd > total) {
|
|
@@ -68383,19 +68591,19 @@ const useListScrollSync = ({
|
|
|
68383
68591
|
// jumped.
|
|
68384
68592
|
const holdWindow = () => {
|
|
68385
68593
|
if (startPlaceRef.current.userTookOver) {
|
|
68386
|
-
|
|
68594
|
+
listRows.holdPending = false;
|
|
68387
68595
|
return;
|
|
68388
68596
|
}
|
|
68389
68597
|
// Held somewhere it has not reached yet: what the window frames right now
|
|
68390
68598
|
// is not what it will frame, so nothing should be fetched for it.
|
|
68391
|
-
|
|
68392
|
-
const total =
|
|
68599
|
+
listRows.holdPending = scrolledWanted !== "start" && scrolledWanted !== undefined;
|
|
68600
|
+
const total = listRows.totalSignal.peek();
|
|
68393
68601
|
if (total <= renderBudget) {
|
|
68394
68602
|
// The whole collection is what the list draws: wherever in it the list is
|
|
68395
68603
|
// held, the window is already its place. Nowhere to move to means nothing
|
|
68396
68604
|
// to wait for — a hold left standing here is a list that never asks for
|
|
68397
68605
|
// anything again.
|
|
68398
|
-
|
|
68606
|
+
listRows.holdPending = false;
|
|
68399
68607
|
return;
|
|
68400
68608
|
}
|
|
68401
68609
|
const half = Math.floor(renderBudget / 2);
|
|
@@ -68405,7 +68613,7 @@ const useListScrollSync = ({
|
|
|
68405
68613
|
} else if (typeof scrolledWanted === "number") {
|
|
68406
68614
|
wantedStart = scrolledWanted - half;
|
|
68407
68615
|
} else if (scrolledWanted && scrolledWanted.id !== undefined) {
|
|
68408
|
-
const rowIndex =
|
|
68616
|
+
const rowIndex = listRows.locateRow(scrolledWanted.id);
|
|
68409
68617
|
if (rowIndex !== null) {
|
|
68410
68618
|
wantedStart = rowIndex - half;
|
|
68411
68619
|
} else if (typeof scrolledWanted.index === "number") {
|
|
@@ -68432,14 +68640,14 @@ const useListScrollSync = ({
|
|
|
68432
68640
|
end
|
|
68433
68641
|
} = renderWindowRef.current;
|
|
68434
68642
|
if (wantedStart === start && end - start === renderBudget) {
|
|
68435
|
-
|
|
68643
|
+
listRows.holdPending = false;
|
|
68436
68644
|
return;
|
|
68437
68645
|
}
|
|
68438
68646
|
renderWindowRef.current = {
|
|
68439
68647
|
start: wantedStart,
|
|
68440
68648
|
end: wantedStart + renderBudget
|
|
68441
68649
|
};
|
|
68442
|
-
|
|
68650
|
+
listRows.holdPending = false;
|
|
68443
68651
|
};
|
|
68444
68652
|
const pendingScrollRef = useRef();
|
|
68445
68653
|
const scrollToItem = (item, {
|
|
@@ -68450,7 +68658,7 @@ const useListScrollSync = ({
|
|
|
68450
68658
|
if (!item) {
|
|
68451
68659
|
return;
|
|
68452
68660
|
}
|
|
68453
|
-
const items =
|
|
68661
|
+
const items = listRows.itemsSignal.peek();
|
|
68454
68662
|
const itemCount = items.length;
|
|
68455
68663
|
if (itemCount === 0) {
|
|
68456
68664
|
return;
|
|
@@ -68579,7 +68787,7 @@ const useListScrollSync = ({
|
|
|
68579
68787
|
return;
|
|
68580
68788
|
}
|
|
68581
68789
|
hasBeenDisplayedRef.current = true;
|
|
68582
|
-
const items =
|
|
68790
|
+
const items = listRows.itemsSignal.peek();
|
|
68583
68791
|
const firstSelected = items.find(i => {
|
|
68584
68792
|
if (i.selected) {
|
|
68585
68793
|
return true;
|
|
@@ -68664,7 +68872,7 @@ const useListScrollSync = ({
|
|
|
68664
68872
|
scrollValues: savedScroll,
|
|
68665
68873
|
scrollerEl: listScrollContainerEl,
|
|
68666
68874
|
listEl: getListEl(),
|
|
68667
|
-
|
|
68875
|
+
listRows,
|
|
68668
68876
|
virtualItemSizeSignal,
|
|
68669
68877
|
renderWindowRef,
|
|
68670
68878
|
horizontal
|
|
@@ -68681,7 +68889,7 @@ const useListScrollSync = ({
|
|
|
68681
68889
|
});
|
|
68682
68890
|
return undefined;
|
|
68683
68891
|
}
|
|
68684
|
-
const visibleItems =
|
|
68892
|
+
const visibleItems = listRows.visibleItemsSignal.peek();
|
|
68685
68893
|
const topItems = visibleItems.slice(0, renderBudget);
|
|
68686
68894
|
const topMatchScoresKey = topItems.map(i => `${i.id}:${i.matchInfo?.matchScore ?? ""}`).join(",");
|
|
68687
68895
|
const currentTopMatchScore = topMatchScoresKeyRef.current;
|
|
@@ -68719,7 +68927,7 @@ const useListScrollSync = ({
|
|
|
68719
68927
|
if (scrolledWanted === "start" || scrolledWanted === undefined || startPlaceRef.current.userTookOver || !ref.current) {
|
|
68720
68928
|
return;
|
|
68721
68929
|
}
|
|
68722
|
-
if (
|
|
68930
|
+
if (listRows.totalSignal.peek() === 0 || virtualItemSizeSignal.peek() === 0) {
|
|
68723
68931
|
return;
|
|
68724
68932
|
}
|
|
68725
68933
|
// Coming back to a named row: it has to be on screen to be put back where
|
|
@@ -68731,13 +68939,13 @@ const useListScrollSync = ({
|
|
|
68731
68939
|
// Only whoever holds the rows can say where that one sits: the list
|
|
68732
68940
|
// itself knows the rows it has drawn, and this one is precisely the one
|
|
68733
68941
|
// it has not drawn yet.
|
|
68734
|
-
const rowIndex =
|
|
68942
|
+
const rowIndex = listRows.locateRow(scrolledWanted.id);
|
|
68735
68943
|
if (rowIndex === null) {
|
|
68736
68944
|
// Not there yet. Where it stood is enough to be roughly right in the
|
|
68737
68945
|
// meantime — the scrollbar lands near its final place instead of at the
|
|
68738
68946
|
// top, and the exact position is taken once the row itself can be
|
|
68739
68947
|
// measured.
|
|
68740
|
-
if (
|
|
68948
|
+
if (listRows.pagesSignal.peek() === 0) {
|
|
68741
68949
|
if (typeof scrolledWanted.index === "number") {
|
|
68742
68950
|
const rowPosition = scrolledWanted.index * virtualItemSizeSignal.peek();
|
|
68743
68951
|
anchorRef.current = null;
|
|
@@ -68854,7 +69062,7 @@ const useListScrollSync = ({
|
|
|
68854
69062
|
const position = captureScrollAnchor({
|
|
68855
69063
|
scrollerEl: getScroller(),
|
|
68856
69064
|
listEl: getListEl(),
|
|
68857
|
-
items:
|
|
69065
|
+
items: listRows.visibleItemsSignal.peek(),
|
|
68858
69066
|
horizontal
|
|
68859
69067
|
});
|
|
68860
69068
|
if (!position) {
|
|
@@ -68942,7 +69150,7 @@ const useListScrollSync = ({
|
|
|
68942
69150
|
anchorRef.current = null;
|
|
68943
69151
|
return;
|
|
68944
69152
|
}
|
|
68945
|
-
const items =
|
|
69153
|
+
const items = listRows.visibleItemsSignal.peek();
|
|
68946
69154
|
const itemNow = items.find(i => i.id === anchor.id);
|
|
68947
69155
|
if (!itemNow) {
|
|
68948
69156
|
anchorRef.current = null;
|
|
@@ -68964,7 +69172,7 @@ const useListScrollSync = ({
|
|
|
68964
69172
|
const windowSize = end - start;
|
|
68965
69173
|
const startShifted = start + indexShift;
|
|
68966
69174
|
let startWanted = startShifted < 0 ? 0 : startShifted;
|
|
68967
|
-
const total =
|
|
69175
|
+
const total = listRows.totalSignal.peek();
|
|
68968
69176
|
// Same normalization as the scroll listener: a window running past the
|
|
68969
69177
|
// last row slides back instead of framing fewer rows than its budget
|
|
68970
69178
|
// allows — every row that fits in it must stay rendered.
|
|
@@ -69022,7 +69230,7 @@ const useListScrollSync = ({
|
|
|
69022
69230
|
const windowSlidRef = useRef(false);
|
|
69023
69231
|
const budgetWarnedRef = useRef(false);
|
|
69024
69232
|
const evaluateWindow = reason => {
|
|
69025
|
-
const total =
|
|
69233
|
+
const total = listRows.totalSignal.peek();
|
|
69026
69234
|
if (total <= renderBudget) {
|
|
69027
69235
|
return;
|
|
69028
69236
|
}
|
|
@@ -69044,7 +69252,7 @@ const useListScrollSync = ({
|
|
|
69044
69252
|
},
|
|
69045
69253
|
scrollerEl,
|
|
69046
69254
|
listEl,
|
|
69047
|
-
|
|
69255
|
+
listRows,
|
|
69048
69256
|
virtualItemSizeSignal,
|
|
69049
69257
|
renderWindowRef,
|
|
69050
69258
|
horizontal
|
|
@@ -69726,12 +69934,12 @@ const getScrollInfo = ({
|
|
|
69726
69934
|
scrollValues,
|
|
69727
69935
|
scrollerEl,
|
|
69728
69936
|
listEl,
|
|
69729
|
-
|
|
69937
|
+
listRows,
|
|
69730
69938
|
virtualItemSizeSignal,
|
|
69731
69939
|
renderWindowRef,
|
|
69732
69940
|
horizontal
|
|
69733
69941
|
}) => {
|
|
69734
|
-
const items =
|
|
69942
|
+
const items = listRows.itemsSignal.peek();
|
|
69735
69943
|
const viewportRect = getScrollerViewportRect(scrollerEl);
|
|
69736
69944
|
const listRect = listEl.getBoundingClientRect();
|
|
69737
69945
|
let hitEl = null;
|
|
@@ -69856,7 +70064,7 @@ const measureItemSize = (listEl, horizontal) => {
|
|
|
69856
70064
|
};
|
|
69857
70065
|
};
|
|
69858
70066
|
const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
69859
|
-
|
|
70067
|
+
listRows,
|
|
69860
70068
|
renderBudget,
|
|
69861
70069
|
scrolledWanted
|
|
69862
70070
|
}) => {
|
|
@@ -69916,7 +70124,7 @@ const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
|
69916
70124
|
// size is for, and a list drawing every row it has would pay a layout on
|
|
69917
70125
|
// each of its renders for a number nothing reads.
|
|
69918
70126
|
const sizeAlreadyKnown = virtualSizeSignal.peek() !== 0;
|
|
69919
|
-
const rowsHeldOffScreen =
|
|
70127
|
+
const rowsHeldOffScreen = listRows.totalSignal.peek() > renderBudget;
|
|
69920
70128
|
if (!virtualItemSizeProp && sizeAlreadyKnown && rowsHeldOffScreen && ref.current) {
|
|
69921
70129
|
const listEl = ref.current.querySelector(".navi_list");
|
|
69922
70130
|
const measure = listEl ? measureItemSize(listEl, horizontal) : null;
|
|
@@ -69932,7 +70140,7 @@ const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
|
69932
70140
|
// screen, and a list held somewhere (placeWhereHeld) before it knows where
|
|
69933
70141
|
// that is. A list drawing every row it has, opening at its start, would
|
|
69934
70142
|
// pay a layout in every commit for a number nobody reads.
|
|
69935
|
-
const sizeRead =
|
|
70143
|
+
const sizeRead = listRows.totalSignal.peek() > renderBudget || scrolledWanted !== undefined && scrolledWanted !== "start";
|
|
69936
70144
|
if (!sizeRead) {
|
|
69937
70145
|
return undefined;
|
|
69938
70146
|
}
|
|
@@ -69984,9 +70192,8 @@ const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
|
69984
70192
|
// item after each commit and writes to the signal, causing only the fillers to
|
|
69985
70193
|
// re-render.
|
|
69986
70194
|
const UnorderedList = ({
|
|
69987
|
-
|
|
70195
|
+
listRows,
|
|
69988
70196
|
renderWindow,
|
|
69989
|
-
virtual,
|
|
69990
70197
|
fallback,
|
|
69991
70198
|
fallbackShown,
|
|
69992
70199
|
searchFallback,
|
|
@@ -70036,17 +70243,14 @@ const UnorderedList = ({
|
|
|
70036
70243
|
value: separator ?? null,
|
|
70037
70244
|
children: jsx(ItemTransitionContext.Provider, {
|
|
70038
70245
|
value: Boolean(itemTransition),
|
|
70039
|
-
children: jsx(
|
|
70040
|
-
value:
|
|
70041
|
-
children: jsx(
|
|
70042
|
-
value:
|
|
70043
|
-
children: jsx(
|
|
70044
|
-
value: null,
|
|
70045
|
-
children: jsx(
|
|
70046
|
-
|
|
70047
|
-
children: jsx(ListDeclaredChildren, {
|
|
70048
|
-
children: children
|
|
70049
|
-
})
|
|
70246
|
+
children: jsx(ListRowsContext.Provider, {
|
|
70247
|
+
value: listRows,
|
|
70248
|
+
children: jsx(ListRowContext.Provider, {
|
|
70249
|
+
value: null,
|
|
70250
|
+
children: jsx(ListItemColumnsContext.Provider, {
|
|
70251
|
+
value: columns ? null : itemColumns || null,
|
|
70252
|
+
children: jsx(ListDeclaredChildren, {
|
|
70253
|
+
children: children
|
|
70050
70254
|
})
|
|
70051
70255
|
})
|
|
70052
70256
|
})
|
|
@@ -70097,8 +70301,8 @@ const VirtualFiller = ({
|
|
|
70097
70301
|
edge,
|
|
70098
70302
|
itemCount
|
|
70099
70303
|
}) => {
|
|
70100
|
-
const
|
|
70101
|
-
const sizeToFill = itemCount *
|
|
70304
|
+
const listRows = useContext(ListRowsContext);
|
|
70305
|
+
const sizeToFill = itemCount * listRows.virtualItemSizeSignal.value;
|
|
70102
70306
|
if (!sizeToFill) {
|
|
70103
70307
|
return null;
|
|
70104
70308
|
}
|
|
@@ -70241,12 +70445,11 @@ const ListItemUI = props => {
|
|
|
70241
70445
|
}
|
|
70242
70446
|
const idDefault = useId();
|
|
70243
70447
|
props.id = props.id || idDefault;
|
|
70244
|
-
const
|
|
70245
|
-
const
|
|
70448
|
+
const listRows = useContext(ListRowsContext);
|
|
70449
|
+
const groupId = useContext(ListGroupContext);
|
|
70246
70450
|
const searchNoMatchMode = useContext(SearchNoMatchModeContext);
|
|
70247
70451
|
// The run this row belongs to, when it comes from one (see ListItems): it
|
|
70248
|
-
//
|
|
70249
|
-
// the row mounts is decided here, and told back to the run.
|
|
70452
|
+
// gave the row its place and decided it is inside the render window.
|
|
70250
70453
|
const row = useContext(ListRowContext);
|
|
70251
70454
|
const slotId = useContext(ListSlotContext);
|
|
70252
70455
|
// There is no standalone match/matchScore/highlight prop — participation
|
|
@@ -70254,7 +70457,7 @@ const ListItemUI = props => {
|
|
|
70254
70457
|
// (e.g. useSearchText's getItemMatchInfo(item): { match, matchScore,
|
|
70255
70458
|
// matchRanges }), so there is exactly one way to wire it up.
|
|
70256
70459
|
const matchInfo = props.matchInfo;
|
|
70257
|
-
// Expose match on the
|
|
70460
|
+
// Expose match on the row: the list counts non-matching rows via
|
|
70258
70461
|
// `item.match === false` (drives noMatchCount → allNoMatch → the searchFallback
|
|
70259
70462
|
// / hide-when-empty behavior). Without this a matchInfo-based search would
|
|
70260
70463
|
// filter items out but never register them as "no match".
|
|
@@ -70278,33 +70481,27 @@ const ListItemUI = props => {
|
|
|
70278
70481
|
// name of this very component (idDefault, not the row's id): two components
|
|
70279
70482
|
// may stand for the same row for a moment, one leaving as the other arrives,
|
|
70280
70483
|
// and the one leaving must give back its own place, not the newcomer's.
|
|
70281
|
-
if (row) {
|
|
70484
|
+
if (!row) {
|
|
70282
70485
|
if (props.filtered) {
|
|
70283
|
-
|
|
70486
|
+
listRows.drop(idDefault);
|
|
70284
70487
|
} else {
|
|
70285
|
-
|
|
70488
|
+
props.index = listRows.take(idDefault, 1, slotId);
|
|
70286
70489
|
}
|
|
70287
|
-
} else if (props.filtered) {
|
|
70288
|
-
virtual.drop(idDefault);
|
|
70289
|
-
} else {
|
|
70290
|
-
props.index = virtual.take(idDefault, 1, slotId);
|
|
70291
70490
|
}
|
|
70491
|
+
// Every row that renders says so, whether it was declared one by one or
|
|
70492
|
+
// drawn by a run: what it is (its value, whether it is selected) and whether
|
|
70493
|
+
// it mounts at all are written where it renders, in one place.
|
|
70494
|
+
listRows.draw(idDefault, {
|
|
70495
|
+
ownerId: row ? row.ownerId : idDefault,
|
|
70496
|
+
place: props.index,
|
|
70497
|
+
groupId,
|
|
70498
|
+
data: props
|
|
70499
|
+
});
|
|
70292
70500
|
useLayoutEffect(() => {
|
|
70293
70501
|
return () => {
|
|
70294
|
-
|
|
70295
|
-
row.run.unmount(idDefault);
|
|
70296
|
-
} else {
|
|
70297
|
-
virtual.drop(idDefault);
|
|
70298
|
-
}
|
|
70502
|
+
listRows.erase(idDefault);
|
|
70299
70503
|
};
|
|
70300
70504
|
}, []);
|
|
70301
|
-
// Every row that is drawn registers itself, whether it was declared one by
|
|
70302
|
-
// one or drawn by a run: what it says about itself (its value, whether it is
|
|
70303
|
-
// selected) is written where it is drawn, in one place.
|
|
70304
|
-
const item = props;
|
|
70305
|
-
tracker.useTrackItem(item);
|
|
70306
|
-
const groupTracker = useContext(GroupItemTrackerContext);
|
|
70307
|
-
const groupVisibleIndex = groupTracker ? groupTracker.useTrackItem(item) : null;
|
|
70308
70505
|
const separator = useContext(SeparatorContext);
|
|
70309
70506
|
if (props.filtered) {
|
|
70310
70507
|
return null;
|
|
@@ -70312,32 +70509,13 @@ const ListItemUI = props => {
|
|
|
70312
70509
|
const listItemVnode = jsx(ListItemReal, {
|
|
70313
70510
|
...props
|
|
70314
70511
|
});
|
|
70315
|
-
|
|
70316
|
-
|
|
70317
|
-
|
|
70318
|
-
// The separator a row wears is the one at the gap above it, so the first row
|
|
70319
|
-
// that mounts wears none. "Am I first?" is answered by whoever handed out
|
|
70320
|
-
// the place — the run for its rows, the list's virtual for a declared one
|
|
70321
|
-
// (virtual.take above) — not by the tracker's visibleIndex: during a reorder
|
|
70322
|
-
// render pass (items resorted by search score) the other items still carry
|
|
70323
|
-
// stale keyToExplicitOrder values, the binary search reads them, no item
|
|
70324
|
-
// comes out at 0 and a spurious separator appears at the top. Inside a
|
|
70325
|
-
// declared group, each group has its own tracker and its items do not
|
|
70326
|
-
// reorder, so groupVisibleIndex is reliable there.
|
|
70327
|
-
let isFirst;
|
|
70328
|
-
if (row) {
|
|
70329
|
-
isFirst = row.run.isFirst(props.index, row.groupKey);
|
|
70330
|
-
} else if (groupVisibleIndex === null || props.hidden) {
|
|
70331
|
-
isFirst = props.index === 0;
|
|
70332
|
-
} else {
|
|
70333
|
-
isFirst = groupVisibleIndex === 0;
|
|
70334
|
-
}
|
|
70335
|
-
if (isFirst) {
|
|
70512
|
+
// The separator a row wears is the one at the gap above it: none when
|
|
70513
|
+
// nothing of the list stands above it (see list_rows.js).
|
|
70514
|
+
if (!separator || listRows.isFirst(idDefault)) {
|
|
70336
70515
|
return listItemVnode;
|
|
70337
70516
|
}
|
|
70338
70517
|
// The gap index, only used as the function-form argument.
|
|
70339
|
-
|
|
70340
|
-
let separatorVnode = resolveSeparatorVnode(separator, gapIndex);
|
|
70518
|
+
let separatorVnode = resolveSeparatorVnode(separator, props.index - 1);
|
|
70341
70519
|
if (props.hidden) {
|
|
70342
70520
|
// A row kept in the DOM but hidden keeps its separator, hidden with it:
|
|
70343
70521
|
// the point of keeping a row that matches nothing is that nothing moves,
|
|
@@ -70666,441 +70844,45 @@ const ListItem = /*#__PURE__*/createComponentResolver([ListItemFirstResolver, Li
|
|
|
70666
70844
|
pure: true
|
|
70667
70845
|
});
|
|
70668
70846
|
|
|
70669
|
-
//
|
|
70670
|
-
//
|
|
70671
|
-
//
|
|
70672
|
-
//
|
|
70673
|
-
// A child knows how many rows it stands for but not what was declared before
|
|
70674
|
-
// it, and it cannot deduce that from when it renders: a render is free to skip
|
|
70675
|
-
// it. A child that draws from signals and whose props are all referentially
|
|
70676
|
-
// === the previous ones does not render again (@preact/signals installs a
|
|
70677
|
-
// shouldComponentUpdate that says so), which is what any child nobody rebuilt
|
|
70678
|
-
// this frame is — and children numbered as they render would then slide up
|
|
70679
|
-
// into the place of the one that was skipped.
|
|
70847
|
+
// The walk that gives the list's children their places: a slot for each of
|
|
70848
|
+
// them, declared to the list's rows all at once before any child renders,
|
|
70849
|
+
// and handed to the child through a provider of its own — which is what lets
|
|
70850
|
+
// the row reach it however deep the caller buried it in components of theirs.
|
|
70680
70851
|
//
|
|
70681
|
-
//
|
|
70682
|
-
//
|
|
70683
|
-
//
|
|
70684
|
-
//
|
|
70685
|
-
//
|
|
70686
|
-
|
|
70687
|
-
|
|
70688
|
-
|
|
70689
|
-
const
|
|
70690
|
-
|
|
70691
|
-
|
|
70692
|
-
|
|
70693
|
-
|
|
70694
|
-
const
|
|
70695
|
-
|
|
70696
|
-
|
|
70697
|
-
|
|
70698
|
-
|
|
70699
|
-
|
|
70700
|
-
|
|
70701
|
-
|
|
70702
|
-
|
|
70703
|
-
|
|
70704
|
-
|
|
70705
|
-
const
|
|
70706
|
-
|
|
70707
|
-
|
|
70708
|
-
|
|
70709
|
-
|
|
70710
|
-
|
|
70711
|
-
|
|
70712
|
-
|
|
70713
|
-
|
|
70714
|
-
|
|
70715
|
-
let rowTotal = 0;
|
|
70716
|
-
// Owners have left and the others have not been moved up yet. Done on the
|
|
70717
|
-
// next ask rather than on the spot: rows leave many at a time (a search, a
|
|
70718
|
-
// list unmounting), and moving the others up once is enough.
|
|
70719
|
-
let placesStale = false;
|
|
70720
|
-
// Where the last slot holding an owner stands: an owner arriving at or after
|
|
70721
|
-
// it is placed at the end without going over the others — a whole first
|
|
70722
|
-
// render, rows arriving in order, costs each row nothing but itself.
|
|
70723
|
-
let rankOwnedLast = -1;
|
|
70724
|
-
const rebuildWalk = () => {
|
|
70725
|
-
slotWalk.length = 0;
|
|
70726
|
-
rankBySlot.clear();
|
|
70727
|
-
const visit = parentSlotId => {
|
|
70728
|
-
const slotIds = slotIdsByParent.get(parentSlotId);
|
|
70729
|
-
if (!slotIds) {
|
|
70730
|
-
return;
|
|
70731
|
-
}
|
|
70732
|
-
for (const slotId of slotIds) {
|
|
70733
|
-
rankBySlot.set(slotId, slotWalk.length);
|
|
70734
|
-
slotWalk.push(slotId);
|
|
70735
|
-
visit(slotId);
|
|
70736
|
-
}
|
|
70737
|
-
};
|
|
70738
|
-
visit(null);
|
|
70739
|
-
};
|
|
70740
|
-
// Every place, in one go: a place is the sum of what stands before it, so
|
|
70741
|
-
// there is nothing to hand out one at a time. Writing a place that did not
|
|
70742
|
-
// change wakes nobody — a signal ignores a value equal to its own.
|
|
70743
|
-
const refreshPlaces = () => {
|
|
70744
|
-
placesStale = false;
|
|
70745
|
-
let index = 0;
|
|
70746
|
-
let rank = 0;
|
|
70747
|
-
rankOwnedLast = -1;
|
|
70748
|
-
while (rank < slotWalk.length) {
|
|
70749
|
-
const ownerIds = ownerIdsBySlot.get(slotWalk[rank]);
|
|
70750
|
-
if (ownerIds) {
|
|
70751
|
-
for (const ownerId of ownerIds) {
|
|
70752
|
-
const owner = ownerById.get(ownerId);
|
|
70753
|
-
owner.placeSignal.value = index;
|
|
70754
|
-
index += owner.rowCount;
|
|
70755
|
-
}
|
|
70756
|
-
rankOwnedLast = rank;
|
|
70757
|
-
}
|
|
70758
|
-
rank++;
|
|
70759
|
-
}
|
|
70760
|
-
rowTotal = index;
|
|
70761
|
-
totalSignal.value = index;
|
|
70762
|
-
};
|
|
70763
|
-
const addToSlot = (slotId, ownerId) => {
|
|
70764
|
-
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
70765
|
-
if (ownerIds) {
|
|
70766
|
-
ownerIds.push(ownerId);
|
|
70767
|
-
} else {
|
|
70768
|
-
ownerIdsBySlot.set(slotId, [ownerId]);
|
|
70769
|
-
}
|
|
70770
|
-
warnIfEveryRowInOneSlot(slotId);
|
|
70771
|
-
};
|
|
70772
|
-
// Rows that all stand in the same slot keep the order they first mounted in:
|
|
70773
|
-
// the walk is over the children the list is given, and a component holding
|
|
70774
|
-
// them is one child however many rows it renders. Everything about a place
|
|
70775
|
-
// then stops following what the caller writes — a search reordering the rows
|
|
70776
|
-
// moves nothing. Said once, and only for the shape that can be nothing else:
|
|
70777
|
-
// the list's whole content is one child, and several rows came out of it.
|
|
70778
|
-
let everyRowInOneSlotWarned = false;
|
|
70779
|
-
const warnIfEveryRowInOneSlot = slotId => {
|
|
70780
|
-
if (everyRowInOneSlotWarned) {
|
|
70781
|
-
return;
|
|
70782
|
-
}
|
|
70783
|
-
const rootSlotIds = slotIdsByParent.get(null);
|
|
70784
|
-
if (!rootSlotIds || rootSlotIds.length !== 1 || rootSlotIds[0] !== slotId) {
|
|
70785
|
-
return;
|
|
70786
|
-
}
|
|
70787
|
-
if (ownerIdsBySlot.get(slotId).length < 2) {
|
|
70788
|
-
return;
|
|
70789
|
-
}
|
|
70790
|
-
everyRowInOneSlotWarned = true;
|
|
70791
|
-
console.warn(`List: every row stands in the same slot, so they keep the order they first rendered in — reordering them (a search, a sort) will not move them. The list's rows must be its own children: give it the rows (or a <List.Items>), not a component rendering them.`);
|
|
70792
|
-
};
|
|
70793
|
-
const removeFromSlot = (slotId, ownerId) => {
|
|
70794
|
-
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
70795
|
-
if (!ownerIds) {
|
|
70796
|
-
return;
|
|
70797
|
-
}
|
|
70798
|
-
const index = ownerIds.indexOf(ownerId);
|
|
70799
|
-
if (index !== -1) {
|
|
70800
|
-
ownerIds.splice(index, 1);
|
|
70801
|
-
}
|
|
70802
|
-
if (ownerIds.length === 0) {
|
|
70803
|
-
ownerIdsBySlot.delete(slotId);
|
|
70804
|
-
}
|
|
70805
|
-
};
|
|
70806
|
-
// A slot the walk no longer names: whatever stood in it is gone, and so is
|
|
70807
|
-
// whatever a walk inside it had declared.
|
|
70808
|
-
const dropSlot = slotId => {
|
|
70809
|
-
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
70810
|
-
if (ownerIds) {
|
|
70811
|
-
for (const ownerId of ownerIds) {
|
|
70812
|
-
ownerById.delete(ownerId);
|
|
70813
|
-
}
|
|
70814
|
-
ownerIdsBySlot.delete(slotId);
|
|
70815
|
-
}
|
|
70816
|
-
const childSlotIds = slotIdsByParent.get(slotId);
|
|
70817
|
-
if (childSlotIds) {
|
|
70818
|
-
slotIdsByParent.delete(slotId);
|
|
70819
|
-
for (const childSlotId of childSlotIds) {
|
|
70820
|
-
dropSlot(childSlotId);
|
|
70821
|
-
}
|
|
70822
|
-
}
|
|
70823
|
-
};
|
|
70824
|
-
const virtual = {
|
|
70825
|
-
totalSignal,
|
|
70826
|
-
pagesSignal,
|
|
70827
|
-
refreshingSignal,
|
|
70828
|
-
// What a run needs to know about the list it lives in: how many rows the
|
|
70829
|
-
// list is willing to draw at once, which end it opens on, and how much
|
|
70830
|
-
// room one row is given — a row whose content has not arrived must take
|
|
70831
|
-
// exactly that, or the rows drawn would not reach where the list says they
|
|
70832
|
-
// are.
|
|
70833
|
-
renderBudget: 0,
|
|
70834
|
-
scrolled: "start",
|
|
70835
|
-
// The list is on its way somewhere: what the window frames is not what it
|
|
70836
|
-
// is about to frame, so a run must not fetch for it (see holdWindow).
|
|
70837
|
-
holdPending: false,
|
|
70838
|
-
// Called by a run just before rows land in it: what is on screen must not
|
|
70839
|
-
// move because something arrived above it. Set by the list itself.
|
|
70840
|
-
captureAnchor: () => {},
|
|
70841
|
-
horizontal: false,
|
|
70842
|
-
virtualItemSizeSignal: null,
|
|
70843
|
-
renderSkeleton: undefined,
|
|
70844
|
-
// The children a walk stands over, in order — said in one call, before any
|
|
70845
|
-
// of them renders, so that what a child asks next is answered against the
|
|
70846
|
-
// whole picture and not against the children that happened to render
|
|
70847
|
-
// first. Said again on every render of the walk, and heard only when
|
|
70848
|
-
// something moved.
|
|
70849
|
-
declareSlots: (parentSlotId, slotIds) => {
|
|
70850
|
-
const slotIdsPrevious = slotIdsByParent.get(parentSlotId);
|
|
70851
|
-
if (slotIdsPrevious && sameSlotIds(slotIdsPrevious, slotIds)) {
|
|
70852
|
-
return;
|
|
70853
|
-
}
|
|
70854
|
-
if (slotIdsPrevious) {
|
|
70855
|
-
const slotIdSet = new Set(slotIds);
|
|
70856
|
-
for (const slotId of slotIdsPrevious) {
|
|
70857
|
-
if (!slotIdSet.has(slotId)) {
|
|
70858
|
-
dropSlot(slotId);
|
|
70859
|
-
}
|
|
70860
|
-
}
|
|
70861
|
-
}
|
|
70862
|
-
slotIdsByParent.set(parentSlotId, slotIds);
|
|
70863
|
-
rebuildWalk();
|
|
70864
|
-
refreshPlaces();
|
|
70865
|
-
},
|
|
70866
|
-
// Whether something has taken this slot for its own: what it renders
|
|
70867
|
-
// inside is then its to place (a run draws its groups with their rows
|
|
70868
|
-
// already placed), and no walk inside it has anything to declare.
|
|
70869
|
-
slotHasOwner: slotId => ownerIdsBySlot.has(slotId),
|
|
70870
|
-
// Whether any run of rows lives in this list: what makes a render window
|
|
70871
|
-
// mean anything (see List's renderBudget).
|
|
70872
|
-
hasRuns: () => locatorByOwner.size > 0,
|
|
70873
|
-
setRowLocator: (ownerId, locate) => {
|
|
70874
|
-
locatorByOwner.set(ownerId, locate);
|
|
70875
|
-
},
|
|
70876
|
-
dropRowLocator: ownerId => {
|
|
70877
|
-
locatorByOwner.delete(ownerId);
|
|
70878
|
-
},
|
|
70879
|
-
// Where the row named by that id sits, asked of whoever holds it.
|
|
70880
|
-
locateRow: id => {
|
|
70881
|
-
for (const locate of locatorByOwner.values()) {
|
|
70882
|
-
const index = locate(id);
|
|
70883
|
-
if (index !== null) {
|
|
70884
|
-
return index;
|
|
70885
|
-
}
|
|
70886
|
-
}
|
|
70887
|
-
return null;
|
|
70888
|
-
},
|
|
70889
|
-
// The place the owner's rows start at — read from a signal, so that the
|
|
70890
|
-
// owner is rendered again when it moves (see createListVirtual). Asked on
|
|
70891
|
-
// every render, and answered without a second look for as long as the
|
|
70892
|
-
// owner stands in the same slot for the same number of rows.
|
|
70893
|
-
take: (ownerId, rowCount, slotId) => {
|
|
70894
|
-
let owner = ownerById.get(ownerId);
|
|
70895
|
-
if (owner) {
|
|
70896
|
-
if (owner.slotId !== slotId || owner.rowCount !== rowCount) {
|
|
70897
|
-
removeFromSlot(owner.slotId, ownerId);
|
|
70898
|
-
addToSlot(slotId, ownerId);
|
|
70899
|
-
owner.slotId = slotId;
|
|
70900
|
-
owner.rowCount = rowCount;
|
|
70901
|
-
placesStale = true;
|
|
70902
|
-
}
|
|
70903
|
-
if (placesStale) {
|
|
70904
|
-
refreshPlaces();
|
|
70905
|
-
}
|
|
70906
|
-
return owner.placeSignal.value;
|
|
70907
|
-
}
|
|
70908
|
-
if (placesStale) {
|
|
70909
|
-
refreshPlaces();
|
|
70910
|
-
}
|
|
70911
|
-
const rank = rankBySlot.get(slotId);
|
|
70912
|
-
addToSlot(slotId, ownerId);
|
|
70913
|
-
if (rank !== undefined && rank >= rankOwnedLast) {
|
|
70914
|
-
owner = {
|
|
70915
|
-
slotId,
|
|
70916
|
-
rowCount,
|
|
70917
|
-
placeSignal: signal(rowTotal)
|
|
70918
|
-
};
|
|
70919
|
-
ownerById.set(ownerId, owner);
|
|
70920
|
-
rowTotal += rowCount;
|
|
70921
|
-
rankOwnedLast = rank;
|
|
70922
|
-
totalSignal.value = rowTotal;
|
|
70923
|
-
return owner.placeSignal.value;
|
|
70924
|
-
}
|
|
70925
|
-
owner = {
|
|
70926
|
-
slotId,
|
|
70927
|
-
rowCount,
|
|
70928
|
-
placeSignal: signal(0)
|
|
70929
|
-
};
|
|
70930
|
-
ownerById.set(ownerId, owner);
|
|
70931
|
-
refreshPlaces();
|
|
70932
|
-
return owner.placeSignal.value;
|
|
70933
|
-
},
|
|
70934
|
-
// The owner stands for no row of the collection: it was filtered out by a
|
|
70935
|
-
// search, or it is gone.
|
|
70936
|
-
drop: ownerId => {
|
|
70937
|
-
const owner = ownerById.get(ownerId);
|
|
70938
|
-
if (!owner) {
|
|
70939
|
-
return;
|
|
70940
|
-
}
|
|
70941
|
-
ownerById.delete(ownerId);
|
|
70942
|
-
removeFromSlot(owner.slotId, ownerId);
|
|
70943
|
-
if (placesStale) {
|
|
70944
|
-
return;
|
|
70945
|
-
}
|
|
70946
|
-
placesStale = true;
|
|
70947
|
-
queueMicrotask(() => {
|
|
70948
|
-
if (placesStale) {
|
|
70949
|
-
refreshPlaces();
|
|
70950
|
-
}
|
|
70951
|
-
});
|
|
70952
|
-
}
|
|
70953
|
-
};
|
|
70954
|
-
return virtual;
|
|
70955
|
-
};
|
|
70956
|
-
const sameSlotIds = (left, right) => {
|
|
70957
|
-
if (left.length !== right.length) {
|
|
70958
|
-
return false;
|
|
70959
|
-
}
|
|
70960
|
-
let index = 0;
|
|
70961
|
-
while (index < left.length) {
|
|
70962
|
-
if (left[index] !== right[index]) {
|
|
70963
|
-
return false;
|
|
70964
|
-
}
|
|
70965
|
-
index++;
|
|
70966
|
-
}
|
|
70967
|
-
return true;
|
|
70968
|
-
};
|
|
70969
|
-
|
|
70970
|
-
// Which of a run's rows mount, and which of them comes first. A run draws
|
|
70971
|
-
// every row of its window, and only the row itself knows, once it renders,
|
|
70972
|
-
// that it renders nothing (filtered out by a search, see ListItemUI). The
|
|
70973
|
-
// separator a row wears is the one at the gap above it, so the first row that
|
|
70974
|
-
// mounts wears none — and "first" is read off the rows that mount, not off
|
|
70975
|
-
// the collection. Rows say so as they render, in order, and the answer is a
|
|
70976
|
-
// signal: a row rendered from a kept vnode is rendered again when the row
|
|
70977
|
-
// before it leaves or comes back. Grouped rows are counted per group, the gap
|
|
70978
|
-
// above a group's first row being the group wrapper's own.
|
|
70979
|
-
const createRunRows = () => {
|
|
70980
|
-
// rowId → { index, groupKey }
|
|
70981
|
-
const rowById = new Map();
|
|
70982
|
-
// groupKey (undefined outside groups) → the index of the group's first
|
|
70983
|
-
// mounted row, -1 when none.
|
|
70984
|
-
const firstSignalByGroup = new Map();
|
|
70985
|
-
// Where the window starts: a run cut by the window has rows above its first
|
|
70986
|
-
// drawn one, and so does a run standing after declared rows.
|
|
70987
|
-
const windowFromSignal = signal(0);
|
|
70988
|
-
// Groups whose first row left: recounted on the next ask, or at the end of
|
|
70989
|
-
// the frame, whichever comes first.
|
|
70990
|
-
const staleGroupKeys = new Set();
|
|
70991
|
-
const firstSignalOf = groupKey => {
|
|
70992
|
-
let firstSignal = firstSignalByGroup.get(groupKey);
|
|
70993
|
-
if (!firstSignal) {
|
|
70994
|
-
firstSignal = signal(-1);
|
|
70995
|
-
firstSignalByGroup.set(groupKey, firstSignal);
|
|
70996
|
-
}
|
|
70997
|
-
return firstSignal;
|
|
70998
|
-
};
|
|
70999
|
-
const refresh = groupKey => {
|
|
71000
|
-
staleGroupKeys.delete(groupKey);
|
|
71001
|
-
let first = -1;
|
|
71002
|
-
for (const row of rowById.values()) {
|
|
71003
|
-
if (row.groupKey === groupKey && (first === -1 || row.index < first)) {
|
|
71004
|
-
first = row.index;
|
|
71005
|
-
}
|
|
71006
|
-
}
|
|
71007
|
-
firstSignalOf(groupKey).value = first;
|
|
71008
|
-
};
|
|
71009
|
-
const leave = row => {
|
|
71010
|
-
if (firstSignalOf(row.groupKey).peek() !== row.index) {
|
|
71011
|
-
return;
|
|
71012
|
-
}
|
|
71013
|
-
staleGroupKeys.add(row.groupKey);
|
|
71014
|
-
queueMicrotask(() => {
|
|
71015
|
-
if (staleGroupKeys.has(row.groupKey)) {
|
|
71016
|
-
refresh(row.groupKey);
|
|
71017
|
-
}
|
|
71018
|
-
});
|
|
71019
|
-
};
|
|
71020
|
-
return {
|
|
71021
|
-
setWindowFrom: windowFrom => {
|
|
71022
|
-
windowFromSignal.value = windowFrom;
|
|
71023
|
-
},
|
|
71024
|
-
mount: (rowId, index, groupKey) => {
|
|
71025
|
-
const row = rowById.get(rowId);
|
|
71026
|
-
if (row) {
|
|
71027
|
-
if (row.index === index && row.groupKey === groupKey) {
|
|
71028
|
-
return;
|
|
71029
|
-
}
|
|
71030
|
-
leave(row);
|
|
71031
|
-
row.index = index;
|
|
71032
|
-
row.groupKey = groupKey;
|
|
71033
|
-
} else {
|
|
71034
|
-
rowById.set(rowId, {
|
|
71035
|
-
index,
|
|
71036
|
-
groupKey
|
|
71037
|
-
});
|
|
71038
|
-
}
|
|
71039
|
-
const firstSignal = firstSignalOf(groupKey);
|
|
71040
|
-
const first = firstSignal.peek();
|
|
71041
|
-
if (first === -1 || index < first) {
|
|
71042
|
-
firstSignal.value = index;
|
|
71043
|
-
}
|
|
71044
|
-
},
|
|
71045
|
-
unmount: rowId => {
|
|
71046
|
-
const row = rowById.get(rowId);
|
|
71047
|
-
if (!row) {
|
|
71048
|
-
return;
|
|
71049
|
-
}
|
|
71050
|
-
rowById.delete(rowId);
|
|
71051
|
-
leave(row);
|
|
71052
|
-
},
|
|
71053
|
-
isFirst: (index, groupKey) => {
|
|
71054
|
-
if (staleGroupKeys.has(groupKey)) {
|
|
71055
|
-
refresh(groupKey);
|
|
71056
|
-
}
|
|
71057
|
-
if (firstSignalOf(groupKey).value !== index) {
|
|
71058
|
-
return false;
|
|
71059
|
-
}
|
|
71060
|
-
return groupKey !== undefined || windowFromSignal.value === 0;
|
|
71061
|
-
}
|
|
71062
|
-
};
|
|
71063
|
-
};
|
|
71064
|
-
|
|
71065
|
-
// The walk that gives the list's children their places: a slot for each of
|
|
71066
|
-
// them, declared to the list's virtual all at once before any child renders,
|
|
71067
|
-
// and handed to the child through a provider of its own — which is what lets
|
|
71068
|
-
// the row reach it however deep the caller buried it in components of theirs.
|
|
71069
|
-
//
|
|
71070
|
-
// A slot is named the way preact tells the child apart: by key when it has
|
|
71071
|
-
// one, by position otherwise, and inside the array it was given in — a nested
|
|
71072
|
-
// array is one child to preact, so what follows the array keeps its name
|
|
71073
|
-
// however many rows the array holds. A child preact would not render (null,
|
|
71074
|
-
// a boolean) has no slot: it is not there.
|
|
71075
|
-
const ListDeclaredChildren = ({
|
|
71076
|
-
children
|
|
71077
|
-
}) => {
|
|
71078
|
-
const virtual = useContext(ListVirtualContext);
|
|
71079
|
-
const parentSlotId = useContext(ListSlotContext);
|
|
71080
|
-
if (parentSlotId !== null && virtual.slotHasOwner(parentSlotId)) {
|
|
71081
|
-
return children;
|
|
71082
|
-
}
|
|
71083
|
-
const slotIds = [];
|
|
71084
|
-
const declared = [];
|
|
71085
|
-
declareChildren(children, parentSlotId === null ? "" : `${parentSlotId}/`, slotIds, declared);
|
|
71086
|
-
virtual.declareSlots(parentSlotId, slotIds);
|
|
71087
|
-
return jsx(Fragment, {
|
|
71088
|
-
children: declared
|
|
71089
|
-
});
|
|
71090
|
-
};
|
|
71091
|
-
const declareChildren = (children, prefix, slotIds, declared) => {
|
|
71092
|
-
const childArray = Array.isArray(children) ? children : [children];
|
|
71093
|
-
let index = 0;
|
|
71094
|
-
for (const child of childArray) {
|
|
71095
|
-
if (Array.isArray(child)) {
|
|
71096
|
-
declareChildren(child, `${prefix}${index}/`, slotIds, declared);
|
|
71097
|
-
} else if (child !== null && child !== undefined && child !== false && child !== true) {
|
|
71098
|
-
const slotId = child.key === undefined || child.key === null ? `${prefix}i${index}` : `${prefix}k${child.key}`;
|
|
71099
|
-
slotIds.push(slotId);
|
|
71100
|
-
declared.push(jsx(ListSlotContext.Provider, {
|
|
71101
|
-
value: slotId,
|
|
71102
|
-
children: child
|
|
71103
|
-
}, slotId));
|
|
70852
|
+
// A slot is named the way preact tells the child apart: by key when it has
|
|
70853
|
+
// one, by position otherwise, and inside the array it was given in — a nested
|
|
70854
|
+
// array is one child to preact, so what follows the array keeps its name
|
|
70855
|
+
// however many rows the array holds. A child preact would not render (null,
|
|
70856
|
+
// a boolean) has no slot: it is not there.
|
|
70857
|
+
const ListDeclaredChildren = ({
|
|
70858
|
+
children
|
|
70859
|
+
}) => {
|
|
70860
|
+
const listRows = useContext(ListRowsContext);
|
|
70861
|
+
const parentSlotId = useContext(ListSlotContext);
|
|
70862
|
+
if (parentSlotId !== null && listRows.slotHasOwner(parentSlotId)) {
|
|
70863
|
+
return children;
|
|
70864
|
+
}
|
|
70865
|
+
const slotIds = [];
|
|
70866
|
+
const declared = [];
|
|
70867
|
+
declareChildren(children, parentSlotId === null ? "" : `${parentSlotId}/`, slotIds, declared);
|
|
70868
|
+
listRows.declareSlots(parentSlotId, slotIds);
|
|
70869
|
+
return jsx(Fragment, {
|
|
70870
|
+
children: declared
|
|
70871
|
+
});
|
|
70872
|
+
};
|
|
70873
|
+
const declareChildren = (children, prefix, slotIds, declared) => {
|
|
70874
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
70875
|
+
let index = 0;
|
|
70876
|
+
for (const child of childArray) {
|
|
70877
|
+
if (Array.isArray(child)) {
|
|
70878
|
+
declareChildren(child, `${prefix}${index}/`, slotIds, declared);
|
|
70879
|
+
} else if (child !== null && child !== undefined && child !== false && child !== true) {
|
|
70880
|
+
const slotId = child.key === undefined || child.key === null ? `${prefix}i${index}` : `${prefix}k${child.key}`;
|
|
70881
|
+
slotIds.push(slotId);
|
|
70882
|
+
declared.push(jsx(ListSlotContext.Provider, {
|
|
70883
|
+
value: slotId,
|
|
70884
|
+
children: child
|
|
70885
|
+
}, slotId));
|
|
71104
70886
|
}
|
|
71105
70887
|
index++;
|
|
71106
70888
|
}
|
|
@@ -71242,15 +71024,10 @@ const ListItems = ({
|
|
|
71242
71024
|
onRequestStateChange
|
|
71243
71025
|
}) => {
|
|
71244
71026
|
const ownerId = useId();
|
|
71245
|
-
const
|
|
71027
|
+
const listRows = useContext(ListRowsContext);
|
|
71246
71028
|
const slotId = useContext(ListSlotContext);
|
|
71247
71029
|
const renderWindow = useContext(RenderWindowContext);
|
|
71248
71030
|
const separator = useContext(SeparatorContext);
|
|
71249
|
-
const runRowsRef = useRef(null);
|
|
71250
|
-
if (!runRowsRef.current) {
|
|
71251
|
-
runRowsRef.current = createRunRows();
|
|
71252
|
-
}
|
|
71253
|
-
const runRows = runRowsRef.current;
|
|
71254
71031
|
// The vnode drawn for a row, kept by item: a run rendering again (its window
|
|
71255
71032
|
// moving, its first paint's budget giving way to the full one) hands preact
|
|
71256
71033
|
// the same vnode for a row that has not changed, and preact leaves that
|
|
@@ -71273,7 +71050,7 @@ const ListItems = ({
|
|
|
71273
71050
|
memoryBudget,
|
|
71274
71051
|
onRequestStateChange
|
|
71275
71052
|
});
|
|
71276
|
-
const renderRowSkeleton = renderSkeleton === undefined ?
|
|
71053
|
+
const renderRowSkeleton = renderSkeleton === undefined ? listRows.renderSkeleton : renderSkeleton;
|
|
71277
71054
|
// A row on its way takes the room the list reserves for it: anything else
|
|
71278
71055
|
// and the rows drawn stop short of where the scroll says they are. Read
|
|
71279
71056
|
// where a row is actually missing, and not before: the size settles after
|
|
@@ -71285,9 +71062,9 @@ const ListItems = ({
|
|
|
71285
71062
|
return skeletonRow;
|
|
71286
71063
|
}
|
|
71287
71064
|
skeletonRow = {};
|
|
71288
|
-
const virtualItemSize =
|
|
71065
|
+
const virtualItemSize = listRows.virtualItemSizeSignal.value;
|
|
71289
71066
|
if (virtualItemSize) {
|
|
71290
|
-
if (
|
|
71067
|
+
if (listRows.horizontal) {
|
|
71291
71068
|
skeletonRow.rowMinWidth = `${virtualItemSize}px`;
|
|
71292
71069
|
} else {
|
|
71293
71070
|
skeletonRow.rowMinHeight = `${virtualItemSize}px`;
|
|
@@ -71295,7 +71072,7 @@ const ListItems = ({
|
|
|
71295
71072
|
}
|
|
71296
71073
|
return skeletonRow;
|
|
71297
71074
|
};
|
|
71298
|
-
const runStart =
|
|
71075
|
+
const runStart = listRows.take(ownerId, store.rowCount, slotId);
|
|
71299
71076
|
const runEnd = runStart + store.rowCount;
|
|
71300
71077
|
// The two ways to count the same row. The list numbers its rows from its own
|
|
71301
71078
|
// first one, whatever draws it; the store numbers the collection's, straight
|
|
@@ -71310,7 +71087,7 @@ const ListItems = ({
|
|
|
71310
71087
|
const windowFrom = renderWindow.start > runStart ? renderWindow.start : runStart;
|
|
71311
71088
|
const windowTo = renderWindow.end < runEnd ? renderWindow.end : runEnd;
|
|
71312
71089
|
store.forget(rankOf(windowFrom), rankOf(windowTo));
|
|
71313
|
-
|
|
71090
|
+
listRows.declareWindow(ownerId, windowFrom, windowTo);
|
|
71314
71091
|
|
|
71315
71092
|
// The row answers to its own id when the item carries one — that is what
|
|
71316
71093
|
// addresses it from outside (--navi-select, --navi-scroll, startAt) — and
|
|
@@ -71320,7 +71097,7 @@ const ListItems = ({
|
|
|
71320
71097
|
// Where a row named from outside actually sits. Only the run can answer:
|
|
71321
71098
|
// rows it holds but does not draw are nowhere else — a list only knows the
|
|
71322
71099
|
// rows it has drawn (they register themselves, see ListItemUI).
|
|
71323
|
-
|
|
71100
|
+
listRows.setRowLocator(ownerId, id => {
|
|
71324
71101
|
let found = null;
|
|
71325
71102
|
store.eachHeld((item, rank) => {
|
|
71326
71103
|
const rowIndex = rowOf(rank);
|
|
@@ -71332,8 +71109,8 @@ const ListItems = ({
|
|
|
71332
71109
|
});
|
|
71333
71110
|
useLayoutEffect(() => {
|
|
71334
71111
|
return () => {
|
|
71335
|
-
|
|
71336
|
-
|
|
71112
|
+
listRows.dropRowLocator(ownerId);
|
|
71113
|
+
listRows.drop(ownerId);
|
|
71337
71114
|
};
|
|
71338
71115
|
}, []);
|
|
71339
71116
|
|
|
@@ -71359,7 +71136,7 @@ const ListItems = ({
|
|
|
71359
71136
|
let askStart = missingStart;
|
|
71360
71137
|
let askEnd = missingEnd;
|
|
71361
71138
|
if (missingStart !== -1) {
|
|
71362
|
-
const rowsPerPage = pageSize ||
|
|
71139
|
+
const rowsPerPage = pageSize || listRows.renderBudget;
|
|
71363
71140
|
const holeSize = missingEnd - missingStart + 1;
|
|
71364
71141
|
if (holeSize < rowsPerPage) {
|
|
71365
71142
|
// Which way the page grows: away from the rows already held, which is
|
|
@@ -71474,7 +71251,7 @@ const ListItems = ({
|
|
|
71474
71251
|
rows.push(jsx("li", {
|
|
71475
71252
|
className: "navi_list_failed_rows",
|
|
71476
71253
|
style: {
|
|
71477
|
-
"--size-to-fill": `${failedRowCount *
|
|
71254
|
+
"--size-to-fill": `${failedRowCount * listRows.virtualItemSizeSignal.value}px`
|
|
71478
71255
|
},
|
|
71479
71256
|
children: renderError ? renderError({
|
|
71480
71257
|
error: store.failure.error,
|
|
@@ -71512,13 +71289,12 @@ const ListItems = ({
|
|
|
71512
71289
|
}
|
|
71513
71290
|
if (rowVnode) {
|
|
71514
71291
|
pushRow(jsx(ListRunSkeletonRow, {
|
|
71515
|
-
run: runRows,
|
|
71516
71292
|
row: {
|
|
71517
71293
|
id: key,
|
|
71518
71294
|
index: rowIndex,
|
|
71295
|
+
ownerId,
|
|
71519
71296
|
...getSkeletonRow()
|
|
71520
71297
|
},
|
|
71521
|
-
groupKey: groupKey,
|
|
71522
71298
|
separator: separator,
|
|
71523
71299
|
children: rowVnode
|
|
71524
71300
|
}, key), item, rowIndex, groupKey);
|
|
@@ -71529,7 +71305,7 @@ const ListItems = ({
|
|
|
71529
71305
|
let rowVnode;
|
|
71530
71306
|
let rowContextValue;
|
|
71531
71307
|
const rowVnodeKept = rowVnodesByItem.get(item);
|
|
71532
|
-
if (rowVnodeKept && rowVnodeKept.rowIndex === rowIndex && rowVnodeKept.refreshing === renderItemState.refreshing
|
|
71308
|
+
if (rowVnodeKept && rowVnodeKept.rowIndex === rowIndex && rowVnodeKept.refreshing === renderItemState.refreshing) {
|
|
71533
71309
|
rowVnode = rowVnodeKept.vnode;
|
|
71534
71310
|
rowContextValue = rowVnodeKept.rowContextValue;
|
|
71535
71311
|
} else {
|
|
@@ -71542,8 +71318,7 @@ const ListItems = ({
|
|
|
71542
71318
|
id: key,
|
|
71543
71319
|
index: rowIndex,
|
|
71544
71320
|
item,
|
|
71545
|
-
|
|
71546
|
-
groupKey
|
|
71321
|
+
ownerId
|
|
71547
71322
|
};
|
|
71548
71323
|
rowVnodesByItem.set(item, {
|
|
71549
71324
|
vnode: rowVnode,
|
|
@@ -71570,28 +71345,37 @@ const ListItems = ({
|
|
|
71570
71345
|
return rows;
|
|
71571
71346
|
};
|
|
71572
71347
|
|
|
71573
|
-
// A run's row that has not arrived, standing where the real one will
|
|
71574
|
-
//
|
|
71575
|
-
// above it
|
|
71348
|
+
// A run's row that has not arrived, standing where the real one will. It never
|
|
71349
|
+
// reaches ListItemUI (see ListItemSkeletonResolver), so it is drawn among the
|
|
71350
|
+
// rows here, and wears the separator of the gap above it the way a real row
|
|
71351
|
+
// does there.
|
|
71352
|
+
const SKELETON_ROW_DATA = {
|
|
71353
|
+
skeleton: true
|
|
71354
|
+
};
|
|
71576
71355
|
const ListRunSkeletonRow = ({
|
|
71577
|
-
run,
|
|
71578
71356
|
row,
|
|
71579
|
-
groupKey,
|
|
71580
71357
|
separator,
|
|
71581
71358
|
children
|
|
71582
71359
|
}) => {
|
|
71360
|
+
const listRows = useContext(ListRowsContext);
|
|
71361
|
+
const groupId = useContext(ListGroupContext);
|
|
71583
71362
|
const rowId = useId();
|
|
71584
|
-
|
|
71363
|
+
listRows.draw(rowId, {
|
|
71364
|
+
ownerId: row.ownerId,
|
|
71365
|
+
place: row.index,
|
|
71366
|
+
groupId,
|
|
71367
|
+
data: SKELETON_ROW_DATA
|
|
71368
|
+
});
|
|
71585
71369
|
useLayoutEffect(() => {
|
|
71586
71370
|
return () => {
|
|
71587
|
-
|
|
71371
|
+
listRows.erase(rowId);
|
|
71588
71372
|
};
|
|
71589
71373
|
}, []);
|
|
71590
71374
|
const rowVnode = jsx(ListRowContext.Provider, {
|
|
71591
71375
|
value: row,
|
|
71592
71376
|
children: children
|
|
71593
71377
|
});
|
|
71594
|
-
if (!separator ||
|
|
71378
|
+
if (!separator || listRows.isFirst(rowId)) {
|
|
71595
71379
|
return rowVnode;
|
|
71596
71380
|
}
|
|
71597
71381
|
return jsxs(Fragment, {
|
|
@@ -71753,7 +71537,7 @@ const useItemStore = ({
|
|
|
71753
71537
|
// where the hole is, and cleared by a retry — which is what makes the same
|
|
71754
71538
|
// range askable again (see the request memory just above).
|
|
71755
71539
|
const [failure, setFailure] = useState(null);
|
|
71756
|
-
const
|
|
71540
|
+
const listRows = useContext(ListRowsContext);
|
|
71757
71541
|
// The rows are there, which is what the list waits for to place itself on the
|
|
71758
71542
|
// row it is held at (see placeWhereHeld). Said from an effect: a signal read
|
|
71759
71543
|
// during this very render must not be written during it.
|
|
@@ -71762,12 +71546,12 @@ const useItemStore = ({
|
|
|
71762
71546
|
return;
|
|
71763
71547
|
}
|
|
71764
71548
|
itemsHeldRef.current = true;
|
|
71765
|
-
|
|
71549
|
+
listRows.pagesSignal.value = listRows.pagesSignal.peek() + 1;
|
|
71766
71550
|
});
|
|
71767
71551
|
// Before the first answer a run does not know how many rows it stands for.
|
|
71768
71552
|
// It stands for a windowful of them: a list that is about to be filled looks
|
|
71769
71553
|
// like rows on their way, not like an empty list.
|
|
71770
|
-
const rowCount = pages.count ?? count ??
|
|
71554
|
+
const rowCount = pages.count ?? count ?? listRows.renderBudget;
|
|
71771
71555
|
// A run that never received anything has nothing to keep on screen: asking
|
|
71772
71556
|
// again is its first ask, not a refresh.
|
|
71773
71557
|
if (staleRef.current && pages.count === undefined) {
|
|
@@ -71777,9 +71561,9 @@ const useItemStore = ({
|
|
|
71777
71561
|
if (!refreshing) {
|
|
71778
71562
|
return null;
|
|
71779
71563
|
}
|
|
71780
|
-
|
|
71564
|
+
listRows.refreshingSignal.value = listRows.refreshingSignal.peek() + 1;
|
|
71781
71565
|
return () => {
|
|
71782
|
-
|
|
71566
|
+
listRows.refreshingSignal.value = listRows.refreshingSignal.peek() - 1;
|
|
71783
71567
|
};
|
|
71784
71568
|
}, [refreshing]);
|
|
71785
71569
|
|
|
@@ -71878,7 +71662,7 @@ const useItemStore = ({
|
|
|
71878
71662
|
// how many rows there are, so it asks for the rows the list would open
|
|
71879
71663
|
// on — counting back from the end when that is where it opens, the way
|
|
71880
71664
|
// an HTTP range does.
|
|
71881
|
-
const budget =
|
|
71665
|
+
const budget = listRows.renderBudget;
|
|
71882
71666
|
let start = missingStart;
|
|
71883
71667
|
let end = missingEnd;
|
|
71884
71668
|
let around;
|
|
@@ -71889,11 +71673,11 @@ const useItemStore = ({
|
|
|
71889
71673
|
// The list is held on a row nothing on screen leads to: the rows it holds
|
|
71890
71674
|
// do not contain it, so no window it could draw will ever bring it. Only
|
|
71891
71675
|
// asking for it by name does.
|
|
71892
|
-
const wanted =
|
|
71676
|
+
const wanted = listRows.scrolled;
|
|
71893
71677
|
const askingAroundWantedRow = revalidating &&
|
|
71894
71678
|
// Only while the hold stands: once the user has taken the list over,
|
|
71895
71679
|
// the reading position is where they are, not where it opened.
|
|
71896
|
-
|
|
71680
|
+
listRows.holdPending && wanted && typeof wanted === "object" && wanted.id !== undefined && listRows.locateRow(wanted.id) === null;
|
|
71897
71681
|
if (askingAroundWantedRow) {
|
|
71898
71682
|
around = wanted.id;
|
|
71899
71683
|
// Where it stood when it was written down is enough to frame the ask;
|
|
@@ -71916,7 +71700,7 @@ const useItemStore = ({
|
|
|
71916
71700
|
around = firstHeld.id;
|
|
71917
71701
|
}
|
|
71918
71702
|
} else if (pages.count === undefined) {
|
|
71919
|
-
const scrolled =
|
|
71703
|
+
const scrolled = listRows.scrolled;
|
|
71920
71704
|
if (scrolled === "end") {
|
|
71921
71705
|
// Counting back from the end, the way an HTTP range does: a list
|
|
71922
71706
|
// opening on its last rows asks for them before it knows how many
|
|
@@ -71947,7 +71731,7 @@ const useItemStore = ({
|
|
|
71947
71731
|
// way somewhere the window does not frame yet, `count` that it knows
|
|
71948
71732
|
// how many rows it stands for.
|
|
71949
71733
|
const debugAsk = outcome => {
|
|
71950
|
-
debugScroll(`ask ${start}-${end}: ${outcome}`, `(revalidating=${revalidating} holdPending=${
|
|
71734
|
+
debugScroll(`ask ${start}-${end}: ${outcome}`, `(revalidating=${revalidating} holdPending=${listRows.holdPending} count=${pages.count})`);
|
|
71951
71735
|
};
|
|
71952
71736
|
if (start === -1) {
|
|
71953
71737
|
// Nothing missing and nothing to revalidate: the run has what it
|
|
@@ -71955,7 +71739,7 @@ const useItemStore = ({
|
|
|
71955
71739
|
debugAsk("nothing missing");
|
|
71956
71740
|
return;
|
|
71957
71741
|
}
|
|
71958
|
-
if (
|
|
71742
|
+
if (listRows.holdPending && pages.count !== undefined && !askingAroundWantedRow) {
|
|
71959
71743
|
// The one ask a hold lets through: the row the list is held on is
|
|
71960
71744
|
// what would lift the hold, and nothing else is going to bring it.
|
|
71961
71745
|
debugAsk("held on a row not reached yet");
|
|
@@ -72046,7 +71830,7 @@ const useItemStore = ({
|
|
|
72046
71830
|
const pageCount = Array.isArray(page) ? pageItems.length : page.count ?? pageStart + pageItems.length;
|
|
72047
71831
|
// Before the rows land: what is on screen has to stay where it is,
|
|
72048
71832
|
// and the DOM still shows the state to hold onto.
|
|
72049
|
-
|
|
71833
|
+
listRows.captureAnchor();
|
|
72050
71834
|
if (revalidating) {
|
|
72051
71835
|
// The rows held stood for a composition that has moved on; the
|
|
72052
71836
|
// ones outside the window are forgotten and asked for again if the
|
|
@@ -72068,7 +71852,7 @@ const useItemStore = ({
|
|
|
72068
71852
|
replace: revalidating
|
|
72069
71853
|
});
|
|
72070
71854
|
}
|
|
72071
|
-
|
|
71855
|
+
listRows.pagesSignal.value = listRows.pagesSignal.peek() + 1;
|
|
72072
71856
|
setPageVersion(version => version + 1);
|
|
72073
71857
|
};
|
|
72074
71858
|
const failed = error => {
|
|
@@ -72136,10 +71920,16 @@ const ListItemGroup = ({
|
|
|
72136
71920
|
...rest
|
|
72137
71921
|
}) => {
|
|
72138
71922
|
const groupId = useId();
|
|
72139
|
-
const
|
|
71923
|
+
const listRows = useContext(ListRowsContext);
|
|
71924
|
+
const group = listRows.group(groupId);
|
|
71925
|
+
useLayoutEffect(() => {
|
|
71926
|
+
return () => {
|
|
71927
|
+
listRows.dropGroup(groupId);
|
|
71928
|
+
};
|
|
71929
|
+
}, []);
|
|
72140
71930
|
const searchNoMatchMode = useContext(SearchNoMatchModeContext);
|
|
72141
|
-
const groupItemCount =
|
|
72142
|
-
const groupNoMatchCount =
|
|
71931
|
+
const groupItemCount = group.countSignal.value;
|
|
71932
|
+
const groupNoMatchCount = group.noMatchCountSignal.value;
|
|
72143
71933
|
// Every row of this group failed the search: the label has nothing left to
|
|
72144
71934
|
// title. "remove" empties the group on its own (and hiddenWhileEmpty takes it
|
|
72145
71935
|
// out of the flow), "muted" keeps the rows readable so the label stays useful
|
|
@@ -72183,8 +71973,8 @@ const ListItemGroup = ({
|
|
|
72183
71973
|
className: "navi_list_item_group_list",
|
|
72184
71974
|
role: "group",
|
|
72185
71975
|
"aria-labelledby": groupId,
|
|
72186
|
-
children: jsx(
|
|
72187
|
-
value:
|
|
71976
|
+
children: jsx(ListGroupContext.Provider, {
|
|
71977
|
+
value: groupId,
|
|
72188
71978
|
children: jsx(ListDeclaredChildren, {
|
|
72189
71979
|
children: children
|
|
72190
71980
|
})
|
|
@@ -78146,414 +77936,812 @@ const SplitButton = props => {
|
|
|
78146
77936
|
});
|
|
78147
77937
|
};
|
|
78148
77938
|
|
|
78149
|
-
// What the Picker's popup answers to — Picker's own popup props, named here so
|
|
78150
|
-
// a caller reaches all of them through the split button (see picker.jsx's JSDoc
|
|
78151
|
-
// for what each one says).
|
|
78152
|
-
const POPUP_PROP_SET = new Set(["mode", "popupLayer", "popupTestId", "positionArea", "popoverMode", "popoverSpacing", "popupWidthFitContent", "popoverMaxHeight", "dialogMinWidth", "dialogMinHeight", "dialogMaxWidth", "dialogMaxHeight", "dialogExpand", "dialogExpandX", "dialogExpandY", "dockedOnSmallTouchScreen", "marginWithContainer", "backdrop", "backdropVariant", "backdropColor", "backdropFilter", "pointerInteractionOutsideEffect", "escapeEffect", "closeOnFocusOut", "scrollCapture", "focusCapture", "popupBackgroundColor", "popupBorderRadius", "animation"]);
|
|
78153
|
-
const splitPopupProps = props => {
|
|
78154
|
-
const popupProps = {};
|
|
78155
|
-
const boxProps = {};
|
|
78156
|
-
for (const key of Object.keys(props)) {
|
|
78157
|
-
if (POPUP_PROP_SET.has(key)) {
|
|
78158
|
-
popupProps[key] = props[key];
|
|
77939
|
+
// What the Picker's popup answers to — Picker's own popup props, named here so
|
|
77940
|
+
// a caller reaches all of them through the split button (see picker.jsx's JSDoc
|
|
77941
|
+
// for what each one says).
|
|
77942
|
+
const POPUP_PROP_SET = new Set(["mode", "popupLayer", "popupTestId", "positionArea", "popoverMode", "popoverSpacing", "popupWidthFitContent", "popoverMaxHeight", "dialogMinWidth", "dialogMinHeight", "dialogMaxWidth", "dialogMaxHeight", "dialogExpand", "dialogExpandX", "dialogExpandY", "dockedOnSmallTouchScreen", "marginWithContainer", "backdrop", "backdropVariant", "backdropColor", "backdropFilter", "pointerInteractionOutsideEffect", "escapeEffect", "closeOnFocusOut", "scrollCapture", "focusCapture", "popupBackgroundColor", "popupBorderRadius", "animation"]);
|
|
77943
|
+
const splitPopupProps = props => {
|
|
77944
|
+
const popupProps = {};
|
|
77945
|
+
const boxProps = {};
|
|
77946
|
+
for (const key of Object.keys(props)) {
|
|
77947
|
+
if (POPUP_PROP_SET.has(key)) {
|
|
77948
|
+
popupProps[key] = props[key];
|
|
77949
|
+
} else {
|
|
77950
|
+
boxProps[key] = props[key];
|
|
77951
|
+
}
|
|
77952
|
+
}
|
|
77953
|
+
return [popupProps, boxProps];
|
|
77954
|
+
};
|
|
77955
|
+
|
|
77956
|
+
/**
|
|
77957
|
+
* applySearch — matches value against searchText.
|
|
77958
|
+
*
|
|
77959
|
+
* Accent-insensitive: "gue" matches "Guérin", "e" matches "é".
|
|
77960
|
+
* Case-insensitive: "bob" matches "Bob", with a score bonus for case-exact matches.
|
|
77961
|
+
* Multi-word: if searchText contains spaces, each word must appear somewhere in
|
|
77962
|
+
* the value for it to match. Ranges for all words are returned.
|
|
77963
|
+
*
|
|
77964
|
+
* Score table:
|
|
77965
|
+
*
|
|
77966
|
+
* Situation Score
|
|
77967
|
+
* ─────────────────────────────────────── ───────────────────────────
|
|
77968
|
+
* phrase at start of value 1
|
|
77969
|
+
* multi-word, one word at start (all match) 0.75
|
|
77970
|
+
* phrase / word at word boundary 0.625
|
|
77971
|
+
* phrase / words mid-word 0.5
|
|
77972
|
+
* + case-exact bonus +0.125
|
|
77973
|
+
* multi-word partial: score × (matched/total)
|
|
77974
|
+
*
|
|
77975
|
+
* matchRanges: [start, end] pairs (exclusive end) for CSS Highlight API.
|
|
77976
|
+
* Intended to be passed to useSearch as the matchFn parameter.
|
|
77977
|
+
*/
|
|
77978
|
+
const applySearch = (searchText, value) => {
|
|
77979
|
+
if (!searchText) {
|
|
77980
|
+
return { match: true, matchScore: 0, matchRanges: [] };
|
|
77981
|
+
}
|
|
77982
|
+
if (searchText.length > 100) {
|
|
77983
|
+
searchText = searchText.slice(0, 100);
|
|
77984
|
+
}
|
|
77985
|
+
const str = String(value);
|
|
77986
|
+
const foldedStr = foldAccents(str).toLowerCase();
|
|
77987
|
+
const { foldedSearch, words, originalWords } = getSearchInfo(searchText);
|
|
77988
|
+
|
|
77989
|
+
// Try exact phrase match first (gives best score).
|
|
77990
|
+
const phraseRanges = [];
|
|
77991
|
+
let phraseIdx = foldedStr.indexOf(foldedSearch);
|
|
77992
|
+
while (phraseIdx !== -1) {
|
|
77993
|
+
phraseRanges.push([phraseIdx, phraseIdx + foldedSearch.length]);
|
|
77994
|
+
phraseIdx = foldedStr.indexOf(foldedSearch, phraseIdx + 1);
|
|
77995
|
+
}
|
|
77996
|
+
if (phraseRanges.length > 0) {
|
|
77997
|
+
const atStart = foldedStr.startsWith(foldedSearch);
|
|
77998
|
+
const atWordBoundary = phraseRanges.some(([start]) =>
|
|
77999
|
+
isWordBoundary(foldedStr, start),
|
|
78000
|
+
);
|
|
78001
|
+
const caseExact = str.includes(searchText);
|
|
78002
|
+
let baseScore;
|
|
78003
|
+
if (atStart) {
|
|
78004
|
+
baseScore = SCORE_PHRASE_AT_START;
|
|
78005
|
+
} else if (atWordBoundary) {
|
|
78006
|
+
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
78007
|
+
} else {
|
|
78008
|
+
baseScore = SCORE_MID_WORD;
|
|
78009
|
+
}
|
|
78010
|
+
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
78011
|
+
return { match: true, matchScore, matchRanges: mergeRanges(phraseRanges) };
|
|
78012
|
+
}
|
|
78013
|
+
|
|
78014
|
+
// Multi-word OR: split on whitespace, any word matching contributes to the score.
|
|
78015
|
+
// Items where all words match rank higher than partial matches.
|
|
78016
|
+
// Note: words always has at least 1 element here (searchText is non-empty and
|
|
78017
|
+
// foldedSearch.split filters empty strings). This path also handles the case
|
|
78018
|
+
// where searchText has trailing/leading spaces: the phrase match above tries
|
|
78019
|
+
// the literal (e.g. "tc " in "tc adapter"), and if that fails we fall through
|
|
78020
|
+
// here to try each word individually (e.g. "tc" matches "tca").
|
|
78021
|
+
const matchRanges = [];
|
|
78022
|
+
let matchedWordCount = 0;
|
|
78023
|
+
let anyWordAtStart = false;
|
|
78024
|
+
let anyWordAtWordBoundary = false;
|
|
78025
|
+
let allMatchedWordsExact = true;
|
|
78026
|
+
for (let w = 0; w < words.length; w++) {
|
|
78027
|
+
const word = words[w];
|
|
78028
|
+
const originalWord = originalWords[w];
|
|
78029
|
+
let idx = foldedStr.indexOf(word);
|
|
78030
|
+
if (idx === -1) {
|
|
78031
|
+
continue;
|
|
78032
|
+
}
|
|
78033
|
+
matchedWordCount++;
|
|
78034
|
+
let wordHasExactMatch = false;
|
|
78035
|
+
while (idx !== -1) {
|
|
78036
|
+
matchRanges.push([idx, idx + word.length]);
|
|
78037
|
+
if (idx === 0) {
|
|
78038
|
+
anyWordAtStart = true;
|
|
78039
|
+
anyWordAtWordBoundary = true;
|
|
78040
|
+
} else if (isWordBoundary(foldedStr, idx)) {
|
|
78041
|
+
anyWordAtWordBoundary = true;
|
|
78042
|
+
}
|
|
78043
|
+
if (str.slice(idx, idx + word.length) === originalWord) {
|
|
78044
|
+
wordHasExactMatch = true;
|
|
78045
|
+
}
|
|
78046
|
+
idx = foldedStr.indexOf(word, idx + 1);
|
|
78047
|
+
}
|
|
78048
|
+
if (!wordHasExactMatch) {
|
|
78049
|
+
allMatchedWordsExact = false;
|
|
78050
|
+
}
|
|
78051
|
+
}
|
|
78052
|
+
if (matchedWordCount === 0) {
|
|
78053
|
+
return tryAcronymMatch(foldedStr, str, searchText);
|
|
78054
|
+
}
|
|
78055
|
+
const wordRatio = matchedWordCount / words.length;
|
|
78056
|
+
let baseScore;
|
|
78057
|
+
if (anyWordAtStart) {
|
|
78058
|
+
baseScore = SCORE_MULTI_WORD_AT_START;
|
|
78059
|
+
} else if (anyWordAtWordBoundary) {
|
|
78060
|
+
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
78061
|
+
} else {
|
|
78062
|
+
baseScore = SCORE_MID_WORD;
|
|
78063
|
+
}
|
|
78064
|
+
const matchScore =
|
|
78065
|
+
(baseScore + (allMatchedWordsExact ? SCORE_BONUS_CASE_EXACT : 0)) *
|
|
78066
|
+
wordRatio;
|
|
78067
|
+
return { match: true, matchScore, matchRanges: mergeRanges(matchRanges) };
|
|
78068
|
+
};
|
|
78069
|
+
|
|
78070
|
+
// Returns true when position idx in str is at a word boundary,
|
|
78071
|
+
// meaning it is either the start of the string or the preceding character
|
|
78072
|
+
// is not a Unicode letter or digit.
|
|
78073
|
+
const isWordBoundary = (str, idx) => {
|
|
78074
|
+
if (idx === 0) {
|
|
78075
|
+
return true;
|
|
78076
|
+
}
|
|
78077
|
+
return !/[\p{L}\p{N}]/u.test(str[idx - 1]);
|
|
78078
|
+
};
|
|
78079
|
+
|
|
78080
|
+
// Strip diacritics for accent-insensitive matching.
|
|
78081
|
+
// NFC normalization first ensures precomposed characters (é → single code unit),
|
|
78082
|
+
// so the folded string has the same length as the NFC source — ranges computed
|
|
78083
|
+
// on the folded string map 1:1 to positions in the original string.
|
|
78084
|
+
const foldAccents = (str) => {
|
|
78085
|
+
return str
|
|
78086
|
+
.normalize("NFC")
|
|
78087
|
+
.normalize("NFD")
|
|
78088
|
+
.replace(/\p{Mn}/gu, "");
|
|
78089
|
+
};
|
|
78090
|
+
|
|
78091
|
+
const SCORE_PHRASE_AT_START = 1;
|
|
78092
|
+
const SCORE_MULTI_WORD_AT_START = 0.75;
|
|
78093
|
+
const SCORE_AT_WORD_BOUNDARY = 0.625;
|
|
78094
|
+
const SCORE_MID_WORD = 0.5;
|
|
78095
|
+
const SCORE_ACRONYM = 0.4;
|
|
78096
|
+
const SCORE_BONUS_CASE_EXACT = 0.125;
|
|
78097
|
+
|
|
78098
|
+
// Acronym match: each char of searchText (spaces stripped) must be the first
|
|
78099
|
+
// letter of a word in value, in order (greedy subsequence on word-starts).
|
|
78100
|
+
// e.g. "TC" matches "Total Count" highlighting the T and C.
|
|
78101
|
+
const tryAcronymMatch = (foldedStr, str, searchText) => {
|
|
78102
|
+
const acronymChars = foldAccents(searchText).toLowerCase().replace(/\s/g, "");
|
|
78103
|
+
if (acronymChars.length < 2) {
|
|
78104
|
+
// Single-char acronym is too ambiguous — skip.
|
|
78105
|
+
return { match: false, matchScore: 0, matchRanges: [] };
|
|
78106
|
+
}
|
|
78107
|
+
const wordStarts = [];
|
|
78108
|
+
for (let i = 0; i < foldedStr.length; i++) {
|
|
78109
|
+
if (isWordBoundary(foldedStr, i)) {
|
|
78110
|
+
wordStarts.push(i);
|
|
78111
|
+
}
|
|
78112
|
+
}
|
|
78113
|
+
const matchedPositions = [];
|
|
78114
|
+
let wordIdx = 0;
|
|
78115
|
+
const originalAcronym = searchText.replace(/\s/g, "");
|
|
78116
|
+
for (let si = 0; si < acronymChars.length; si++) {
|
|
78117
|
+
const ch = acronymChars[si];
|
|
78118
|
+
let found = false;
|
|
78119
|
+
while (wordIdx < wordStarts.length) {
|
|
78120
|
+
const pos = wordStarts[wordIdx];
|
|
78121
|
+
wordIdx++;
|
|
78122
|
+
if (foldedStr[pos] === ch) {
|
|
78123
|
+
matchedPositions.push(pos);
|
|
78124
|
+
found = true;
|
|
78125
|
+
break;
|
|
78126
|
+
}
|
|
78127
|
+
}
|
|
78128
|
+
if (!found) {
|
|
78129
|
+
return { match: false, matchScore: 0, matchRanges: [] };
|
|
78130
|
+
}
|
|
78131
|
+
}
|
|
78132
|
+
const atStart = matchedPositions[0] === 0;
|
|
78133
|
+
const caseExact = matchedPositions.every(
|
|
78134
|
+
(p, i) => str[p] === originalAcronym[i],
|
|
78135
|
+
);
|
|
78136
|
+
const baseScore = atStart ? SCORE_ACRONYM + 0.05 : SCORE_ACRONYM;
|
|
78137
|
+
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
78138
|
+
const matchRanges = matchedPositions.map((p) => [p, p + 1]);
|
|
78139
|
+
return { match: true, matchScore, matchRanges };
|
|
78140
|
+
};
|
|
78141
|
+
|
|
78142
|
+
// LRU cache for pre-computed search info, avoids recomputing foldAccents/toLowerCase
|
|
78143
|
+
// for the same searchText across all items in a list render.
|
|
78144
|
+
const searchCache = new Map();
|
|
78145
|
+
const SEARCH_CACHE_MAX_SIZE = 20;
|
|
78146
|
+
const getSearchInfo = (searchText) => {
|
|
78147
|
+
if (searchCache.has(searchText)) {
|
|
78148
|
+
const cached = searchCache.get(searchText);
|
|
78149
|
+
searchCache.delete(searchText);
|
|
78150
|
+
searchCache.set(searchText, cached);
|
|
78151
|
+
return cached;
|
|
78152
|
+
}
|
|
78153
|
+
const foldedSearch = foldAccents(searchText).toLowerCase();
|
|
78154
|
+
const words = foldedSearch.split(/\s+/).filter(Boolean);
|
|
78155
|
+
const originalWords = searchText.split(/\s+/).filter(Boolean);
|
|
78156
|
+
const info = { foldedSearch, words, originalWords };
|
|
78157
|
+
searchCache.set(searchText, info);
|
|
78158
|
+
if (searchCache.size > SEARCH_CACHE_MAX_SIZE) {
|
|
78159
|
+
searchCache.delete(searchCache.keys().next().value);
|
|
78160
|
+
}
|
|
78161
|
+
return info;
|
|
78162
|
+
};
|
|
78163
|
+
|
|
78164
|
+
// Merge overlapping or adjacent [start, end] ranges (sorted by start).
|
|
78165
|
+
const mergeRanges = (ranges) => {
|
|
78166
|
+
if (ranges.length < 2) {
|
|
78167
|
+
return ranges;
|
|
78168
|
+
}
|
|
78169
|
+
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
78170
|
+
const merged = [sorted[0]];
|
|
78171
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
78172
|
+
const last = merged[merged.length - 1];
|
|
78173
|
+
const current = sorted[i];
|
|
78174
|
+
if (current[0] <= last[1]) {
|
|
78175
|
+
if (current[1] > last[1]) {
|
|
78176
|
+
last[1] = current[1];
|
|
78177
|
+
}
|
|
78178
|
+
} else {
|
|
78179
|
+
merged.push(current);
|
|
78180
|
+
}
|
|
78181
|
+
}
|
|
78182
|
+
return merged;
|
|
78183
|
+
};
|
|
78184
|
+
|
|
78185
|
+
/**
|
|
78186
|
+
* createSearch — builds a matchFn compatible with useSearch that searches
|
|
78187
|
+
* across multiple named fields of an item, each with its own DOM selector
|
|
78188
|
+
* and optional priority weight.
|
|
78189
|
+
*
|
|
78190
|
+
* Usage:
|
|
78191
|
+
* ```js
|
|
78192
|
+
* const searchPerson = createSearch({
|
|
78193
|
+
* name: {
|
|
78194
|
+
* getter: (item) => item.name,
|
|
78195
|
+
* domSelector: ".name",
|
|
78196
|
+
* },
|
|
78197
|
+
* address: {
|
|
78198
|
+
* getter: (item) => item.address,
|
|
78199
|
+
* domSelector: ".address",
|
|
78200
|
+
* priority: 1.5,
|
|
78201
|
+
* },
|
|
78202
|
+
* });
|
|
78203
|
+
*
|
|
78204
|
+
* const [orderedItems, getItemMatchInfo] = useSearch(search, items, searchPerson);
|
|
78205
|
+
* // getItemMatchInfo(item).matchRanges is { ".name": [[start,end],…], ".address": [[start,end],…] }
|
|
78206
|
+
* // Pass the whole thing: <ListItem matchInfo={getItemMatchInfo(item)} />
|
|
78207
|
+
* // — ListItem handles the per-selector object format for matchRanges.
|
|
78208
|
+
* ```
|
|
78209
|
+
*
|
|
78210
|
+
* Each field config:
|
|
78211
|
+
* - getter(item): string — extracts the text to search
|
|
78212
|
+
* - domSelector: string — CSS selector used by ListItem to find the target element
|
|
78213
|
+
* - priority?: number — multiplier applied to the field's score (default 1)
|
|
78214
|
+
* - matchFn?: function — custom match function (searchText, fieldValue) => { match, matchScore, matchRanges }
|
|
78215
|
+
* defaults to applySearch
|
|
78216
|
+
*/
|
|
78217
|
+
const createSearch = (fields) => {
|
|
78218
|
+
return (searchText, item) => {
|
|
78219
|
+
if (!searchText) {
|
|
78220
|
+
return { match: true, matchScore: 0, matchRanges: {} };
|
|
78221
|
+
}
|
|
78222
|
+
let totalScore = 0;
|
|
78223
|
+
const matchRanges = {};
|
|
78224
|
+
for (const [
|
|
78225
|
+
,
|
|
78226
|
+
{ getter, domSelector, priority = 1, matchFn = applySearch },
|
|
78227
|
+
] of Object.entries(fields)) {
|
|
78228
|
+
const fieldValue = getter(item);
|
|
78229
|
+
const result = matchFn(searchText, fieldValue);
|
|
78230
|
+
if (result.match && result.matchRanges.length > 0) {
|
|
78231
|
+
totalScore += result.matchScore * priority;
|
|
78232
|
+
matchRanges[domSelector] = result.matchRanges;
|
|
78233
|
+
}
|
|
78234
|
+
}
|
|
78235
|
+
if (totalScore === 0) {
|
|
78236
|
+
return { match: false, matchScore: 0, matchRanges: {} };
|
|
78237
|
+
}
|
|
78238
|
+
return { match: true, matchScore: totalScore, matchRanges };
|
|
78239
|
+
};
|
|
78240
|
+
};
|
|
78241
|
+
|
|
78242
|
+
/**
|
|
78243
|
+
* useSearch — reorders items so matched ones come first (sorted by score desc),
|
|
78244
|
+
* followed by non-matched items in their natural order. No item is hidden.
|
|
78245
|
+
* Returns [orderedItems, getItemMatchInfo].
|
|
78246
|
+
* - orderedItems: all items, reordered
|
|
78247
|
+
* - getItemMatchInfo(item): { match, matchScore, matchRanges } — pass the
|
|
78248
|
+
* whole thing straight to <ListItem matchInfo={getItemMatchInfo(item)} />,
|
|
78249
|
+
* there is no need to destructure the three fields by hand.
|
|
78250
|
+
*
|
|
78251
|
+
* When searchText is empty, natural order is preserved and all items match with score 0.
|
|
78252
|
+
*
|
|
78253
|
+
* To filter (hide non-matching items), pass filtered={!getItemMatchInfo(item).match}
|
|
78254
|
+
* to each ListItem. The list's matchFallback will be shown when all items are hidden.
|
|
78255
|
+
*/
|
|
78256
|
+
const useSearchText = (searchText, items, matchFn = applySearch) => {
|
|
78257
|
+
if (typeof searchText !== "string" && searchText !== undefined) {
|
|
78258
|
+
throw new TypeError(
|
|
78259
|
+
"useSearchText: searchText must be a string or undefined",
|
|
78260
|
+
);
|
|
78261
|
+
}
|
|
78262
|
+
if (items === undefined) {
|
|
78263
|
+
throw new TypeError("useSearch: items is undefined");
|
|
78264
|
+
}
|
|
78265
|
+
const { orderedItems, matchInfoMap } = useMemo(() => {
|
|
78266
|
+
const { scoreEntries, nonMatched, matchInfoMap } = buildMatchInfo(
|
|
78267
|
+
searchText,
|
|
78268
|
+
items,
|
|
78269
|
+
matchFn,
|
|
78270
|
+
);
|
|
78271
|
+
const orderedItems = [];
|
|
78272
|
+
for (const [, bucket] of scoreEntries) {
|
|
78273
|
+
for (const { item } of bucket) {
|
|
78274
|
+
orderedItems.push(item);
|
|
78275
|
+
}
|
|
78276
|
+
}
|
|
78277
|
+
for (const { item } of nonMatched) {
|
|
78278
|
+
orderedItems.push(item);
|
|
78279
|
+
}
|
|
78280
|
+
return { orderedItems, matchInfoMap };
|
|
78281
|
+
}, [items, searchText, matchFn]);
|
|
78282
|
+
|
|
78283
|
+
// The same function for as long as the map is the same: a `renderItem`
|
|
78284
|
+
// reading it is stable only if this is, and a run keeps the rows it drew
|
|
78285
|
+
// only for a stable `renderItem` (see List.Items).
|
|
78286
|
+
const getItemMatchInfo = useCallback(
|
|
78287
|
+
(item) => matchInfoMap.get(item),
|
|
78288
|
+
[matchInfoMap],
|
|
78289
|
+
);
|
|
78290
|
+
|
|
78291
|
+
return [orderedItems, getItemMatchInfo];
|
|
78292
|
+
};
|
|
78293
|
+
|
|
78294
|
+
const buildMatchInfo = (searchText, items, matchFn) => {
|
|
78295
|
+
// scoreEntries: [score, bucket][] kept sorted desc by score.
|
|
78296
|
+
// New distinct score values are inserted via bisect — O(1) in practice
|
|
78297
|
+
// since there are very few distinct scores (today just 0 and 1).
|
|
78298
|
+
const scoreEntries = []; // [score, bucket][]
|
|
78299
|
+
const nonMatched = [];
|
|
78300
|
+
|
|
78301
|
+
for (const item of items) {
|
|
78302
|
+
const result = matchFn(searchText, item);
|
|
78303
|
+
if (!result.match) {
|
|
78304
|
+
nonMatched.push({
|
|
78305
|
+
item,
|
|
78306
|
+
matchScore: result.matchScore,
|
|
78307
|
+
matchRanges: result.matchRanges,
|
|
78308
|
+
});
|
|
78309
|
+
continue;
|
|
78310
|
+
}
|
|
78311
|
+
const score = result.matchScore;
|
|
78312
|
+
// Find existing bucket or insert a new entry in desc order.
|
|
78313
|
+
let lo = 0;
|
|
78314
|
+
let hi = scoreEntries.length;
|
|
78315
|
+
while (lo < hi) {
|
|
78316
|
+
const mid = (lo + hi) >> 1;
|
|
78317
|
+
if (scoreEntries[mid][0] > score) {
|
|
78318
|
+
lo = mid + 1;
|
|
78319
|
+
} else if (scoreEntries[mid][0] < score) {
|
|
78320
|
+
hi = mid;
|
|
78321
|
+
} else {
|
|
78322
|
+
lo = mid;
|
|
78323
|
+
hi = mid; // exact match — found the bucket
|
|
78324
|
+
}
|
|
78325
|
+
}
|
|
78326
|
+
if (lo < scoreEntries.length && scoreEntries[lo][0] === score) {
|
|
78327
|
+
scoreEntries[lo][1].push({ item, matchRanges: result.matchRanges });
|
|
78159
78328
|
} else {
|
|
78160
|
-
|
|
78329
|
+
scoreEntries.splice(lo, 0, [
|
|
78330
|
+
score,
|
|
78331
|
+
[{ item, matchRanges: result.matchRanges }],
|
|
78332
|
+
]);
|
|
78161
78333
|
}
|
|
78162
78334
|
}
|
|
78163
|
-
|
|
78335
|
+
|
|
78336
|
+
const matchInfoMap = new Map();
|
|
78337
|
+
for (const [score, bucket] of scoreEntries) {
|
|
78338
|
+
for (const { item, matchRanges } of bucket) {
|
|
78339
|
+
matchInfoMap.set(item, { match: true, matchScore: score, matchRanges });
|
|
78340
|
+
}
|
|
78341
|
+
}
|
|
78342
|
+
for (const { item, matchScore, matchRanges } of nonMatched) {
|
|
78343
|
+
matchInfoMap.set(item, { match: false, matchScore, matchRanges });
|
|
78344
|
+
}
|
|
78345
|
+
|
|
78346
|
+
return { scoreEntries, nonMatched, matchInfoMap };
|
|
78164
78347
|
};
|
|
78165
78348
|
|
|
78166
|
-
|
|
78167
|
-
*
|
|
78349
|
+
/*
|
|
78350
|
+
* useItemTracker() — hook that creates a stable item tracker for the lifetime
|
|
78351
|
+
* of the host component.
|
|
78168
78352
|
*
|
|
78169
|
-
*
|
|
78170
|
-
*
|
|
78171
|
-
*
|
|
78172
|
-
*
|
|
78353
|
+
* USAGE:
|
|
78354
|
+
* ```jsx
|
|
78355
|
+
* function ListControlled({ items }) {
|
|
78356
|
+
* const tracker = useItemTracker({
|
|
78357
|
+
* onChange: () => console.log("items changed"),
|
|
78358
|
+
* });
|
|
78173
78359
|
*
|
|
78174
|
-
*
|
|
78360
|
+
* return (
|
|
78361
|
+
* <ul>
|
|
78362
|
+
* {items.map((item, i) => (
|
|
78363
|
+
* <Row key={item.id} id={item.id} index={i} hidden={item.hidden} value={item.value} tracker={tracker} />
|
|
78364
|
+
* ))}
|
|
78365
|
+
* <Count tracker={tracker} />
|
|
78366
|
+
* </ul>
|
|
78367
|
+
* );
|
|
78368
|
+
* }
|
|
78175
78369
|
*
|
|
78176
|
-
*
|
|
78177
|
-
*
|
|
78178
|
-
*
|
|
78179
|
-
*
|
|
78180
|
-
*
|
|
78181
|
-
* phrase / words mid-word 0.5
|
|
78182
|
-
* + case-exact bonus +0.125
|
|
78183
|
-
* multi-word partial: score × (matched/total)
|
|
78370
|
+
* function Row({ id, index, hidden, value, tracker }) {
|
|
78371
|
+
* const visibleIndex = tracker.useTrackItem({ id, index, hidden, value });
|
|
78372
|
+
* if (visibleIndex === -1) return null;
|
|
78373
|
+
* return <li>{value}</li>;
|
|
78374
|
+
* }
|
|
78184
78375
|
*
|
|
78185
|
-
*
|
|
78186
|
-
*
|
|
78376
|
+
* function Count({ tracker }) {
|
|
78377
|
+
* const count = tracker.visibleCountSignal.value; // re-renders only when count changes
|
|
78378
|
+
* return <span>{count} items</span>;
|
|
78379
|
+
* }
|
|
78380
|
+
* ```
|
|
78381
|
+
*
|
|
78382
|
+
* INTERNALS:
|
|
78383
|
+
* - registrations: Map key → data, contains only visible items
|
|
78384
|
+
* - idToKey: Map id → key, stable across renders
|
|
78385
|
+
* - orderedKeys: number[] of visible item keys sorted by explicit order
|
|
78386
|
+
* - keyToOrderedIndex: Map key → orderedKeys index, gives O(1) indexOf equivalent
|
|
78387
|
+
* - keyToExplicitOrder: Map key → explicitly passed index, used to maintain sort order
|
|
78388
|
+
* - allItemsSignal: signal(array), all items including hidden, ordered by explicit index
|
|
78389
|
+
* - visibleItemsSignal: signal(array), non-hidden items only
|
|
78390
|
+
* - countSignal: signal(number), count of all items including hidden
|
|
78391
|
+
* - visibleCountSignal: signal(number), updated in microtask batch, only when count changes
|
|
78392
|
+
* - propSignals: Map propName → signal(array), updated in microtask batch with element equality
|
|
78393
|
+
* - onChangeRef: holds the latest onChange callback, called once per microtask batch
|
|
78394
|
+
*
|
|
78395
|
+
* useTrackItem(id, data, index): registers the item with an explicitly provided index
|
|
78396
|
+
* that determines its position among siblings. The caller (e.g. items.map) knows the
|
|
78397
|
+
* correct order and passes it directly — no render-sequence deduction needed.
|
|
78398
|
+
* Returns the visible rank (position among non-hidden items), or -1 when hidden.
|
|
78399
|
+
* Signals and onChange are deferred to a microtask so multiple items updating
|
|
78400
|
+
* in one commit cause only one notification.
|
|
78401
|
+
*
|
|
78402
|
+
* getTrackedItemByIndex(index): synchronous O(1) lookup of a visible item by
|
|
78403
|
+
* its visible rank. Returns undefined when index is out of range.
|
|
78404
|
+
*
|
|
78405
|
+
* peekItems(): the items as they stand right now, without waiting for the
|
|
78406
|
+
* deferred notification — what a sibling rendering after the items must read
|
|
78407
|
+
* to paint them in the same commit.
|
|
78187
78408
|
*/
|
|
78188
|
-
const applySearch = (searchText, value) => {
|
|
78189
|
-
if (!searchText) {
|
|
78190
|
-
return { match: true, matchScore: 0, matchRanges: [] };
|
|
78191
|
-
}
|
|
78192
|
-
if (searchText.length > 100) {
|
|
78193
|
-
searchText = searchText.slice(0, 100);
|
|
78194
|
-
}
|
|
78195
|
-
const str = String(value);
|
|
78196
|
-
const foldedStr = foldAccents(str).toLowerCase();
|
|
78197
|
-
const { foldedSearch, words, originalWords } = getSearchInfo(searchText);
|
|
78198
78409
|
|
|
78199
|
-
|
|
78200
|
-
const
|
|
78201
|
-
|
|
78202
|
-
|
|
78203
|
-
|
|
78204
|
-
|
|
78205
|
-
|
|
78206
|
-
|
|
78207
|
-
|
|
78208
|
-
const atWordBoundary = phraseRanges.some(([start]) =>
|
|
78209
|
-
isWordBoundary(foldedStr, start),
|
|
78210
|
-
);
|
|
78211
|
-
const caseExact = str.includes(searchText);
|
|
78212
|
-
let baseScore;
|
|
78213
|
-
if (atStart) {
|
|
78214
|
-
baseScore = SCORE_PHRASE_AT_START;
|
|
78215
|
-
} else if (atWordBoundary) {
|
|
78216
|
-
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
78217
|
-
} else {
|
|
78218
|
-
baseScore = SCORE_MID_WORD;
|
|
78219
|
-
}
|
|
78220
|
-
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
78221
|
-
return { match: true, matchScore, matchRanges: mergeRanges(phraseRanges) };
|
|
78410
|
+
const useItemTracker = ({ onChange } = {}) => {
|
|
78411
|
+
const onChangeRef = useRef(onChange);
|
|
78412
|
+
onChangeRef.current = onChange;
|
|
78413
|
+
const trackerRef = useRef(null);
|
|
78414
|
+
let tracker = trackerRef.current;
|
|
78415
|
+
if (!tracker) {
|
|
78416
|
+
trackerRef.current = tracker = createItemTracker((items) => {
|
|
78417
|
+
onChangeRef.current?.(items);
|
|
78418
|
+
});
|
|
78222
78419
|
}
|
|
78420
|
+
// When code in useLayoutEffect of the caller wants to run the tracker must be in sync
|
|
78421
|
+
// without this layout effect the tracker might not have been synced yet and preact would call layout effect
|
|
78422
|
+
// before we had time to sync
|
|
78423
|
+
useLayoutEffect(() => {
|
|
78424
|
+
tracker._flushSync();
|
|
78425
|
+
});
|
|
78426
|
+
return tracker;
|
|
78427
|
+
};
|
|
78428
|
+
|
|
78429
|
+
const createItemTracker = (onChange) => {
|
|
78430
|
+
const registrations = new Map(); // key → data (visible items only)
|
|
78431
|
+
const idToKey = new Map(); // id → insertion key (stable, auto-incremented)
|
|
78432
|
+
let keyCounter = 0;
|
|
78433
|
+
// orderedKeys: visible item keys sorted by their explicitly provided index.
|
|
78434
|
+
const orderedKeys = []; // number[]
|
|
78435
|
+
// keyToOrderedIndex: O(1) equivalent of orderedKeys.indexOf(key).
|
|
78436
|
+
const keyToOrderedIndex = new Map(); // key → index in orderedKeys
|
|
78437
|
+
const allKeys = new Set(); // all registered keys including hidden
|
|
78438
|
+
const keyToExplicitOrder = new Map(); // key → explicitly passed index
|
|
78439
|
+
|
|
78440
|
+
const allRegistrations = new Map(); // key → data (all items including hidden)
|
|
78441
|
+
const allOrderedKeys = []; // all item keys sorted by explicit order
|
|
78442
|
+
const keyToAllOrderedIndex = new Map(); // key → index in allOrderedKeys
|
|
78443
|
+
|
|
78444
|
+
const itemsSignal = signal([]);
|
|
78445
|
+
const visibleItemsSignal = signal([]);
|
|
78446
|
+
const countSignal = signal(0);
|
|
78447
|
+
const visibleCountSignal = signal(0);
|
|
78448
|
+
const noMatchCountSignal = signal(0);
|
|
78449
|
+
|
|
78450
|
+
let notifyScheduled = false;
|
|
78451
|
+
const runNotify = () => {
|
|
78452
|
+
batch(() => {
|
|
78453
|
+
let someChange = false;
|
|
78454
|
+
|
|
78455
|
+
const newCount = allKeys.size;
|
|
78456
|
+
const countModified = countSignal.peek() !== newCount;
|
|
78457
|
+
if (countModified) {
|
|
78458
|
+
countSignal.value = newCount;
|
|
78459
|
+
someChange = true;
|
|
78460
|
+
}
|
|
78461
|
+
|
|
78462
|
+
// Build allItems and visibleItems in a single pass over allOrderedKeys.
|
|
78463
|
+
// Visible items are those without data.hidden or data.filtered — same
|
|
78464
|
+
// relative order as orderedKeys (syncItem already excludes both from
|
|
78465
|
+
// orderedKeys; this must match or consumers relying on visibleCountSignal
|
|
78466
|
+
// would count filtered-out items as if they still took up space).
|
|
78467
|
+
const prevAllItems = itemsSignal.peek();
|
|
78468
|
+
const prevVisibleItems = visibleItemsSignal.peek();
|
|
78469
|
+
let allItemsChanged = prevAllItems.length !== allOrderedKeys.length;
|
|
78470
|
+
let visibleItemsChanged = false;
|
|
78471
|
+
const allItems = [];
|
|
78472
|
+
const visibleItems = [];
|
|
78473
|
+
let newNoMatchCount = 0;
|
|
78474
|
+
for (let i = 0; i < allOrderedKeys.length; i++) {
|
|
78475
|
+
const key = allOrderedKeys[i];
|
|
78476
|
+
const item = allRegistrations.get(key);
|
|
78477
|
+
allItems.push(item);
|
|
78478
|
+
// Compare by reference: catches any prop change (id, selected, disabled, …)
|
|
78479
|
+
if (!allItemsChanged && item !== prevAllItems[i]) {
|
|
78480
|
+
allItemsChanged = true;
|
|
78481
|
+
}
|
|
78482
|
+
if (item.match === false) {
|
|
78483
|
+
newNoMatchCount++;
|
|
78484
|
+
}
|
|
78485
|
+
if (!item.hidden && !item.filtered) {
|
|
78486
|
+
const visibleIdx = visibleItems.length;
|
|
78487
|
+
visibleItems.push(item);
|
|
78488
|
+
if (!visibleItemsChanged && item !== prevVisibleItems[visibleIdx]) {
|
|
78489
|
+
visibleItemsChanged = true;
|
|
78490
|
+
}
|
|
78491
|
+
}
|
|
78492
|
+
}
|
|
78493
|
+
|
|
78494
|
+
const newVisibleCount = visibleItems.length;
|
|
78495
|
+
const visibleCountModified =
|
|
78496
|
+
visibleCountSignal.peek() !== newVisibleCount;
|
|
78497
|
+
if (visibleCountModified) {
|
|
78498
|
+
visibleCountSignal.value = newVisibleCount;
|
|
78499
|
+
someChange = true;
|
|
78500
|
+
}
|
|
78501
|
+
if (allItemsChanged) {
|
|
78502
|
+
itemsSignal.value = allItems;
|
|
78503
|
+
someChange = true;
|
|
78504
|
+
}
|
|
78505
|
+
if (visibleItemsChanged) {
|
|
78506
|
+
visibleItemsSignal.value = visibleItems;
|
|
78507
|
+
someChange = true;
|
|
78508
|
+
}
|
|
78509
|
+
const noMatchCountModified =
|
|
78510
|
+
noMatchCountSignal.peek() !== newNoMatchCount;
|
|
78511
|
+
if (noMatchCountModified) {
|
|
78512
|
+
noMatchCountSignal.value = newNoMatchCount;
|
|
78513
|
+
someChange = true;
|
|
78514
|
+
}
|
|
78515
|
+
if (someChange) {
|
|
78516
|
+
onChange?.();
|
|
78517
|
+
}
|
|
78518
|
+
});
|
|
78519
|
+
};
|
|
78223
78520
|
|
|
78224
|
-
|
|
78225
|
-
|
|
78226
|
-
|
|
78227
|
-
// foldedSearch.split filters empty strings). This path also handles the case
|
|
78228
|
-
// where searchText has trailing/leading spaces: the phrase match above tries
|
|
78229
|
-
// the literal (e.g. "tc " in "tc adapter"), and if that fails we fall through
|
|
78230
|
-
// here to try each word individually (e.g. "tc" matches "tca").
|
|
78231
|
-
const matchRanges = [];
|
|
78232
|
-
let matchedWordCount = 0;
|
|
78233
|
-
let anyWordAtStart = false;
|
|
78234
|
-
let anyWordAtWordBoundary = false;
|
|
78235
|
-
let allMatchedWordsExact = true;
|
|
78236
|
-
for (let w = 0; w < words.length; w++) {
|
|
78237
|
-
const word = words[w];
|
|
78238
|
-
const originalWord = originalWords[w];
|
|
78239
|
-
let idx = foldedStr.indexOf(word);
|
|
78240
|
-
if (idx === -1) {
|
|
78241
|
-
continue;
|
|
78521
|
+
const notify = () => {
|
|
78522
|
+
if (notifyScheduled) {
|
|
78523
|
+
return;
|
|
78242
78524
|
}
|
|
78243
|
-
|
|
78244
|
-
|
|
78245
|
-
|
|
78246
|
-
|
|
78247
|
-
if (idx === 0) {
|
|
78248
|
-
anyWordAtStart = true;
|
|
78249
|
-
anyWordAtWordBoundary = true;
|
|
78250
|
-
} else if (isWordBoundary(foldedStr, idx)) {
|
|
78251
|
-
anyWordAtWordBoundary = true;
|
|
78525
|
+
notifyScheduled = true;
|
|
78526
|
+
queueMicrotask(() => {
|
|
78527
|
+
if (!notifyScheduled) {
|
|
78528
|
+
return; // was already flushed synchronously
|
|
78252
78529
|
}
|
|
78253
|
-
|
|
78254
|
-
|
|
78530
|
+
notifyScheduled = false;
|
|
78531
|
+
runNotify();
|
|
78532
|
+
});
|
|
78533
|
+
};
|
|
78534
|
+
|
|
78535
|
+
const _flushSync = () => {
|
|
78536
|
+
if (!notifyScheduled) {
|
|
78537
|
+
return;
|
|
78538
|
+
}
|
|
78539
|
+
notifyScheduled = false;
|
|
78540
|
+
runNotify();
|
|
78541
|
+
};
|
|
78542
|
+
|
|
78543
|
+
// Insert key into orderedKeys at the correct position based on explicitOrder.
|
|
78544
|
+
// Uses binary search for O(log n) insertion.
|
|
78545
|
+
const insertKey = (key, explicitOrder) => {
|
|
78546
|
+
let lo = 0;
|
|
78547
|
+
let hi = orderedKeys.length;
|
|
78548
|
+
while (lo < hi) {
|
|
78549
|
+
const mid = (lo + hi) >> 1;
|
|
78550
|
+
if (keyToExplicitOrder.get(orderedKeys[mid]) <= explicitOrder) {
|
|
78551
|
+
lo = mid + 1;
|
|
78552
|
+
} else {
|
|
78553
|
+
hi = mid;
|
|
78255
78554
|
}
|
|
78256
|
-
idx = foldedStr.indexOf(word, idx + 1);
|
|
78257
78555
|
}
|
|
78258
|
-
|
|
78259
|
-
|
|
78556
|
+
orderedKeys.splice(lo, 0, key);
|
|
78557
|
+
for (let i = lo; i < orderedKeys.length; i++) {
|
|
78558
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
78260
78559
|
}
|
|
78261
|
-
}
|
|
78262
|
-
if (matchedWordCount === 0) {
|
|
78263
|
-
return tryAcronymMatch(foldedStr, str, searchText);
|
|
78264
|
-
}
|
|
78265
|
-
const wordRatio = matchedWordCount / words.length;
|
|
78266
|
-
let baseScore;
|
|
78267
|
-
if (anyWordAtStart) {
|
|
78268
|
-
baseScore = SCORE_MULTI_WORD_AT_START;
|
|
78269
|
-
} else if (anyWordAtWordBoundary) {
|
|
78270
|
-
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
78271
|
-
} else {
|
|
78272
|
-
baseScore = SCORE_MID_WORD;
|
|
78273
|
-
}
|
|
78274
|
-
const matchScore =
|
|
78275
|
-
(baseScore + (allMatchedWordsExact ? SCORE_BONUS_CASE_EXACT : 0)) *
|
|
78276
|
-
wordRatio;
|
|
78277
|
-
return { match: true, matchScore, matchRanges: mergeRanges(matchRanges) };
|
|
78278
|
-
};
|
|
78279
|
-
|
|
78280
|
-
// Returns true when position idx in str is at a word boundary,
|
|
78281
|
-
// meaning it is either the start of the string or the preceding character
|
|
78282
|
-
// is not a Unicode letter or digit.
|
|
78283
|
-
const isWordBoundary = (str, idx) => {
|
|
78284
|
-
if (idx === 0) {
|
|
78285
|
-
return true;
|
|
78286
|
-
}
|
|
78287
|
-
return !/[\p{L}\p{N}]/u.test(str[idx - 1]);
|
|
78288
|
-
};
|
|
78289
|
-
|
|
78290
|
-
// Strip diacritics for accent-insensitive matching.
|
|
78291
|
-
// NFC normalization first ensures precomposed characters (é → single code unit),
|
|
78292
|
-
// so the folded string has the same length as the NFC source — ranges computed
|
|
78293
|
-
// on the folded string map 1:1 to positions in the original string.
|
|
78294
|
-
const foldAccents = (str) => {
|
|
78295
|
-
return str
|
|
78296
|
-
.normalize("NFC")
|
|
78297
|
-
.normalize("NFD")
|
|
78298
|
-
.replace(/\p{Mn}/gu, "");
|
|
78299
|
-
};
|
|
78300
|
-
|
|
78301
|
-
const SCORE_PHRASE_AT_START = 1;
|
|
78302
|
-
const SCORE_MULTI_WORD_AT_START = 0.75;
|
|
78303
|
-
const SCORE_AT_WORD_BOUNDARY = 0.625;
|
|
78304
|
-
const SCORE_MID_WORD = 0.5;
|
|
78305
|
-
const SCORE_ACRONYM = 0.4;
|
|
78306
|
-
const SCORE_BONUS_CASE_EXACT = 0.125;
|
|
78560
|
+
};
|
|
78307
78561
|
|
|
78308
|
-
|
|
78309
|
-
|
|
78310
|
-
|
|
78311
|
-
|
|
78312
|
-
|
|
78313
|
-
|
|
78314
|
-
|
|
78315
|
-
|
|
78316
|
-
|
|
78317
|
-
const wordStarts = [];
|
|
78318
|
-
for (let i = 0; i < foldedStr.length; i++) {
|
|
78319
|
-
if (isWordBoundary(foldedStr, i)) {
|
|
78320
|
-
wordStarts.push(i);
|
|
78321
|
-
}
|
|
78322
|
-
}
|
|
78323
|
-
const matchedPositions = [];
|
|
78324
|
-
let wordIdx = 0;
|
|
78325
|
-
const originalAcronym = searchText.replace(/\s/g, "");
|
|
78326
|
-
for (let si = 0; si < acronymChars.length; si++) {
|
|
78327
|
-
const ch = acronymChars[si];
|
|
78328
|
-
let found = false;
|
|
78329
|
-
while (wordIdx < wordStarts.length) {
|
|
78330
|
-
const pos = wordStarts[wordIdx];
|
|
78331
|
-
wordIdx++;
|
|
78332
|
-
if (foldedStr[pos] === ch) {
|
|
78333
|
-
matchedPositions.push(pos);
|
|
78334
|
-
found = true;
|
|
78335
|
-
break;
|
|
78562
|
+
const insertAllKey = (key, explicitOrder) => {
|
|
78563
|
+
let lo = 0;
|
|
78564
|
+
let hi = allOrderedKeys.length;
|
|
78565
|
+
while (lo < hi) {
|
|
78566
|
+
const mid = (lo + hi) >> 1;
|
|
78567
|
+
if (keyToExplicitOrder.get(allOrderedKeys[mid]) <= explicitOrder) {
|
|
78568
|
+
lo = mid + 1;
|
|
78569
|
+
} else {
|
|
78570
|
+
hi = mid;
|
|
78336
78571
|
}
|
|
78337
78572
|
}
|
|
78338
|
-
|
|
78339
|
-
|
|
78573
|
+
allOrderedKeys.splice(lo, 0, key);
|
|
78574
|
+
for (let i = lo; i < allOrderedKeys.length; i++) {
|
|
78575
|
+
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
78340
78576
|
}
|
|
78341
|
-
}
|
|
78342
|
-
const atStart = matchedPositions[0] === 0;
|
|
78343
|
-
const caseExact = matchedPositions.every(
|
|
78344
|
-
(p, i) => str[p] === originalAcronym[i],
|
|
78345
|
-
);
|
|
78346
|
-
const baseScore = atStart ? SCORE_ACRONYM + 0.05 : SCORE_ACRONYM;
|
|
78347
|
-
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
78348
|
-
const matchRanges = matchedPositions.map((p) => [p, p + 1]);
|
|
78349
|
-
return { match: true, matchScore, matchRanges };
|
|
78350
|
-
};
|
|
78577
|
+
};
|
|
78351
78578
|
|
|
78352
|
-
|
|
78353
|
-
|
|
78354
|
-
|
|
78355
|
-
|
|
78356
|
-
|
|
78357
|
-
|
|
78358
|
-
|
|
78359
|
-
|
|
78360
|
-
|
|
78361
|
-
|
|
78362
|
-
}
|
|
78363
|
-
const foldedSearch = foldAccents(searchText).toLowerCase();
|
|
78364
|
-
const words = foldedSearch.split(/\s+/).filter(Boolean);
|
|
78365
|
-
const originalWords = searchText.split(/\s+/).filter(Boolean);
|
|
78366
|
-
const info = { foldedSearch, words, originalWords };
|
|
78367
|
-
searchCache.set(searchText, info);
|
|
78368
|
-
if (searchCache.size > SEARCH_CACHE_MAX_SIZE) {
|
|
78369
|
-
searchCache.delete(searchCache.keys().next().value);
|
|
78370
|
-
}
|
|
78371
|
-
return info;
|
|
78372
|
-
};
|
|
78579
|
+
const removeAllKey = (key) => {
|
|
78580
|
+
const idx = keyToAllOrderedIndex.get(key);
|
|
78581
|
+
if (idx !== undefined) {
|
|
78582
|
+
allOrderedKeys.splice(idx, 1);
|
|
78583
|
+
keyToAllOrderedIndex.delete(key);
|
|
78584
|
+
for (let i = idx; i < allOrderedKeys.length; i++) {
|
|
78585
|
+
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
78586
|
+
}
|
|
78587
|
+
}
|
|
78588
|
+
};
|
|
78373
78589
|
|
|
78374
|
-
//
|
|
78375
|
-
|
|
78376
|
-
|
|
78377
|
-
|
|
78378
|
-
|
|
78379
|
-
|
|
78380
|
-
|
|
78381
|
-
|
|
78382
|
-
|
|
78383
|
-
|
|
78384
|
-
|
|
78385
|
-
|
|
78386
|
-
|
|
78590
|
+
// Register or update an item. data.hidden controls visibility.
|
|
78591
|
+
// explicitOrder is the caller-provided index that determines sort position.
|
|
78592
|
+
const syncItem = (key, index, data) => {
|
|
78593
|
+
if (data.role === "presentation") {
|
|
78594
|
+
registrations.delete(key);
|
|
78595
|
+
const idx = keyToOrderedIndex.get(key);
|
|
78596
|
+
if (idx !== undefined) {
|
|
78597
|
+
orderedKeys.splice(idx, 1);
|
|
78598
|
+
keyToOrderedIndex.delete(key);
|
|
78599
|
+
for (let i = idx; i < orderedKeys.length; i++) {
|
|
78600
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
78601
|
+
}
|
|
78602
|
+
}
|
|
78603
|
+
keyToExplicitOrder.delete(key);
|
|
78604
|
+
allRegistrations.delete(key);
|
|
78605
|
+
removeAllKey(key);
|
|
78606
|
+
allKeys.delete(key);
|
|
78607
|
+
return;
|
|
78608
|
+
}
|
|
78609
|
+
|
|
78610
|
+
// Maintain allRegistrations and allOrderedKeys for all non-presentation items.
|
|
78611
|
+
allRegistrations.set(key, data);
|
|
78612
|
+
allKeys.add(key);
|
|
78613
|
+
const currentAllIdx = keyToAllOrderedIndex.get(key);
|
|
78614
|
+
const previousOrder = keyToExplicitOrder.get(key);
|
|
78615
|
+
keyToExplicitOrder.set(key, index);
|
|
78616
|
+
if (currentAllIdx === undefined) {
|
|
78617
|
+
insertAllKey(key, index);
|
|
78618
|
+
} else if (previousOrder !== index) {
|
|
78619
|
+
allOrderedKeys.splice(currentAllIdx, 1);
|
|
78620
|
+
keyToAllOrderedIndex.delete(key);
|
|
78621
|
+
for (let i = currentAllIdx; i < allOrderedKeys.length; i++) {
|
|
78622
|
+
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
78387
78623
|
}
|
|
78388
|
-
|
|
78389
|
-
merged.push(current);
|
|
78624
|
+
insertAllKey(key, index);
|
|
78390
78625
|
}
|
|
78391
|
-
}
|
|
78392
|
-
return merged;
|
|
78393
|
-
};
|
|
78394
78626
|
|
|
78395
|
-
|
|
78396
|
-
|
|
78397
|
-
|
|
78398
|
-
|
|
78399
|
-
|
|
78400
|
-
|
|
78401
|
-
|
|
78402
|
-
|
|
78403
|
-
|
|
78404
|
-
* getter: (item) => item.name,
|
|
78405
|
-
* domSelector: ".name",
|
|
78406
|
-
* },
|
|
78407
|
-
* address: {
|
|
78408
|
-
* getter: (item) => item.address,
|
|
78409
|
-
* domSelector: ".address",
|
|
78410
|
-
* priority: 1.5,
|
|
78411
|
-
* },
|
|
78412
|
-
* });
|
|
78413
|
-
*
|
|
78414
|
-
* const [orderedItems, getItemMatchInfo] = useSearch(search, items, searchPerson);
|
|
78415
|
-
* // getItemMatchInfo(item).matchRanges is { ".name": [[start,end],…], ".address": [[start,end],…] }
|
|
78416
|
-
* // Pass the whole thing: <ListItem matchInfo={getItemMatchInfo(item)} />
|
|
78417
|
-
* // — ListItem handles the per-selector object format for matchRanges.
|
|
78418
|
-
* ```
|
|
78419
|
-
*
|
|
78420
|
-
* Each field config:
|
|
78421
|
-
* - getter(item): string — extracts the text to search
|
|
78422
|
-
* - domSelector: string — CSS selector used by ListItem to find the target element
|
|
78423
|
-
* - priority?: number — multiplier applied to the field's score (default 1)
|
|
78424
|
-
* - matchFn?: function — custom match function (searchText, fieldValue) => { match, matchScore, matchRanges }
|
|
78425
|
-
* defaults to applySearch
|
|
78426
|
-
*/
|
|
78427
|
-
const createSearch = (fields) => {
|
|
78428
|
-
return (searchText, item) => {
|
|
78429
|
-
if (!searchText) {
|
|
78430
|
-
return { match: true, matchScore: 0, matchRanges: {} };
|
|
78431
|
-
}
|
|
78432
|
-
let totalScore = 0;
|
|
78433
|
-
const matchRanges = {};
|
|
78434
|
-
for (const [
|
|
78435
|
-
,
|
|
78436
|
-
{ getter, domSelector, priority = 1, matchFn = applySearch },
|
|
78437
|
-
] of Object.entries(fields)) {
|
|
78438
|
-
const fieldValue = getter(item);
|
|
78439
|
-
const result = matchFn(searchText, fieldValue);
|
|
78440
|
-
if (result.match && result.matchRanges.length > 0) {
|
|
78441
|
-
totalScore += result.matchScore * priority;
|
|
78442
|
-
matchRanges[domSelector] = result.matchRanges;
|
|
78627
|
+
if (data.filtered || data.hidden) {
|
|
78628
|
+
registrations.delete(key);
|
|
78629
|
+
const idx = keyToOrderedIndex.get(key);
|
|
78630
|
+
if (idx !== undefined) {
|
|
78631
|
+
orderedKeys.splice(idx, 1);
|
|
78632
|
+
keyToOrderedIndex.delete(key);
|
|
78633
|
+
for (let i = idx; i < orderedKeys.length; i++) {
|
|
78634
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
78635
|
+
}
|
|
78443
78636
|
}
|
|
78637
|
+
return;
|
|
78444
78638
|
}
|
|
78445
|
-
|
|
78446
|
-
|
|
78639
|
+
|
|
78640
|
+
registrations.set(key, data);
|
|
78641
|
+
const currentIdx = keyToOrderedIndex.get(key);
|
|
78642
|
+
if (currentIdx === undefined) {
|
|
78643
|
+
insertKey(key, index);
|
|
78644
|
+
return;
|
|
78447
78645
|
}
|
|
78448
|
-
|
|
78646
|
+
if (previousOrder === index) {
|
|
78647
|
+
return;
|
|
78648
|
+
}
|
|
78649
|
+
orderedKeys.splice(currentIdx, 1);
|
|
78650
|
+
keyToOrderedIndex.delete(key);
|
|
78651
|
+
for (let i = currentIdx; i < orderedKeys.length; i++) {
|
|
78652
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
78653
|
+
}
|
|
78654
|
+
insertKey(key, index);
|
|
78449
78655
|
};
|
|
78450
|
-
};
|
|
78451
78656
|
|
|
78452
|
-
|
|
78453
|
-
|
|
78454
|
-
|
|
78455
|
-
|
|
78456
|
-
|
|
78457
|
-
|
|
78458
|
-
|
|
78459
|
-
|
|
78460
|
-
*
|
|
78461
|
-
* When searchText is empty, natural order is preserved and all items match with score 0.
|
|
78462
|
-
*
|
|
78463
|
-
* To filter (hide non-matching items), pass filtered={!getItemMatchInfo(item).match}
|
|
78464
|
-
* to each ListItem. The list's matchFallback will be shown when all items are hidden.
|
|
78465
|
-
*/
|
|
78466
|
-
const useSearchText = (searchText, items, matchFn = applySearch) => {
|
|
78467
|
-
if (typeof searchText !== "string" && searchText !== undefined) {
|
|
78468
|
-
throw new TypeError(
|
|
78469
|
-
"useSearchText: searchText must be a string or undefined",
|
|
78470
|
-
);
|
|
78471
|
-
}
|
|
78472
|
-
if (items === undefined) {
|
|
78473
|
-
throw new TypeError("useSearch: items is undefined");
|
|
78474
|
-
}
|
|
78475
|
-
const { orderedItems, matchInfoMap } = useMemo(() => {
|
|
78476
|
-
const { scoreEntries, nonMatched, matchInfoMap } = buildMatchInfo(
|
|
78477
|
-
searchText,
|
|
78478
|
-
items,
|
|
78479
|
-
matchFn,
|
|
78480
|
-
);
|
|
78481
|
-
const orderedItems = [];
|
|
78482
|
-
for (const [, bucket] of scoreEntries) {
|
|
78483
|
-
for (const { item } of bucket) {
|
|
78484
|
-
orderedItems.push(item);
|
|
78657
|
+
const unregisterKey = (key) => {
|
|
78658
|
+
registrations.delete(key);
|
|
78659
|
+
const idx = keyToOrderedIndex.get(key);
|
|
78660
|
+
if (idx !== undefined) {
|
|
78661
|
+
orderedKeys.splice(idx, 1);
|
|
78662
|
+
keyToOrderedIndex.delete(key);
|
|
78663
|
+
for (let i = idx; i < orderedKeys.length; i++) {
|
|
78664
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
78485
78665
|
}
|
|
78486
78666
|
}
|
|
78487
|
-
|
|
78488
|
-
|
|
78667
|
+
keyToExplicitOrder.delete(key);
|
|
78668
|
+
allRegistrations.delete(key);
|
|
78669
|
+
removeAllKey(key);
|
|
78670
|
+
allKeys.delete(key);
|
|
78671
|
+
};
|
|
78672
|
+
|
|
78673
|
+
const keyForId = (id) => {
|
|
78674
|
+
if (!idToKey.has(id)) {
|
|
78675
|
+
idToKey.set(id, keyCounter++);
|
|
78489
78676
|
}
|
|
78490
|
-
return
|
|
78491
|
-
}
|
|
78677
|
+
return idToKey.get(id);
|
|
78678
|
+
};
|
|
78492
78679
|
|
|
78493
|
-
//
|
|
78494
|
-
//
|
|
78495
|
-
//
|
|
78496
|
-
|
|
78497
|
-
|
|
78498
|
-
|
|
78499
|
-
|
|
78680
|
+
// Register an item. data.hidden controls visibility.
|
|
78681
|
+
// explicitOrder is the caller-provided index (e.g. from items.map((item, i) => ...))
|
|
78682
|
+
// that determines this item's position among siblings.
|
|
78683
|
+
// Returns the item's visible rank among non-hidden items, or -1 when hidden.
|
|
78684
|
+
const useTrackItem = (data) => {
|
|
78685
|
+
const { id, index } = data;
|
|
78686
|
+
const key = keyForId(id);
|
|
78500
78687
|
|
|
78501
|
-
|
|
78502
|
-
|
|
78688
|
+
syncItem(key, index, data);
|
|
78689
|
+
notify();
|
|
78503
78690
|
|
|
78504
|
-
|
|
78505
|
-
|
|
78506
|
-
|
|
78507
|
-
|
|
78508
|
-
|
|
78509
|
-
|
|
78691
|
+
useLayoutEffect(() => {
|
|
78692
|
+
return () => {
|
|
78693
|
+
unregisterKey(key);
|
|
78694
|
+
notify();
|
|
78695
|
+
};
|
|
78696
|
+
}, []);
|
|
78510
78697
|
|
|
78511
|
-
|
|
78512
|
-
|
|
78513
|
-
if (!result.match) {
|
|
78514
|
-
nonMatched.push({
|
|
78515
|
-
item,
|
|
78516
|
-
matchScore: result.matchScore,
|
|
78517
|
-
matchRanges: result.matchRanges,
|
|
78518
|
-
});
|
|
78519
|
-
continue;
|
|
78520
|
-
}
|
|
78521
|
-
const score = result.matchScore;
|
|
78522
|
-
// Find existing bucket or insert a new entry in desc order.
|
|
78523
|
-
let lo = 0;
|
|
78524
|
-
let hi = scoreEntries.length;
|
|
78525
|
-
while (lo < hi) {
|
|
78526
|
-
const mid = (lo + hi) >> 1;
|
|
78527
|
-
if (scoreEntries[mid][0] > score) {
|
|
78528
|
-
lo = mid + 1;
|
|
78529
|
-
} else if (scoreEntries[mid][0] < score) {
|
|
78530
|
-
hi = mid;
|
|
78531
|
-
} else {
|
|
78532
|
-
lo = mid;
|
|
78533
|
-
hi = mid; // exact match — found the bucket
|
|
78534
|
-
}
|
|
78698
|
+
if (data.filtered || data.hidden || data.role === "presentation") {
|
|
78699
|
+
return -1;
|
|
78535
78700
|
}
|
|
78536
|
-
|
|
78537
|
-
|
|
78538
|
-
|
|
78539
|
-
|
|
78540
|
-
|
|
78541
|
-
|
|
78542
|
-
|
|
78701
|
+
return keyToOrderedIndex.get(key) ?? -1;
|
|
78702
|
+
};
|
|
78703
|
+
|
|
78704
|
+
const getTrackedItemByIndex = (index) => {
|
|
78705
|
+
const key = orderedKeys[index];
|
|
78706
|
+
if (key === undefined) {
|
|
78707
|
+
return undefined;
|
|
78543
78708
|
}
|
|
78544
|
-
|
|
78709
|
+
return registrations.get(key);
|
|
78710
|
+
};
|
|
78545
78711
|
|
|
78546
|
-
|
|
78547
|
-
|
|
78548
|
-
|
|
78549
|
-
|
|
78712
|
+
// The items as they stand right now, notification pending or not — same
|
|
78713
|
+
// content as itemsSignal, minus the wait.
|
|
78714
|
+
//
|
|
78715
|
+
// Items register during their own render, while the signal is only updated
|
|
78716
|
+
// on a deferred microtask (see notify): a sibling rendering after them would
|
|
78717
|
+
// otherwise paint from an empty list and correct itself a frame later. That
|
|
78718
|
+
// frame is visible whenever the painted size feeds a layout decision — a
|
|
78719
|
+
// dialog sizing itself on its content measures the empty version and shifts
|
|
78720
|
+
// once the real one lands. Reading this instead makes the first paint the
|
|
78721
|
+
// right one. Callers must still subscribe to itemsSignal to re-render on
|
|
78722
|
+
// LATER changes; this is the value to display, not the notification.
|
|
78723
|
+
const peekItems = () => {
|
|
78724
|
+
if (!notifyScheduled) {
|
|
78725
|
+
return itemsSignal.peek();
|
|
78550
78726
|
}
|
|
78551
|
-
|
|
78552
|
-
|
|
78553
|
-
|
|
78554
|
-
|
|
78727
|
+
const items = [];
|
|
78728
|
+
for (const key of allOrderedKeys) {
|
|
78729
|
+
items.push(allRegistrations.get(key));
|
|
78730
|
+
}
|
|
78731
|
+
return items;
|
|
78732
|
+
};
|
|
78555
78733
|
|
|
78556
|
-
return {
|
|
78734
|
+
return {
|
|
78735
|
+
useTrackItem,
|
|
78736
|
+
getTrackedItemByIndex,
|
|
78737
|
+
peekItems,
|
|
78738
|
+
itemsSignal,
|
|
78739
|
+
visibleItemsSignal,
|
|
78740
|
+
countSignal,
|
|
78741
|
+
visibleCountSignal,
|
|
78742
|
+
noMatchCountSignal,
|
|
78743
|
+
_flushSync,
|
|
78744
|
+
};
|
|
78557
78745
|
};
|
|
78558
78746
|
|
|
78559
78747
|
installImportMetaCssBuild(import.meta);
|