@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/jsenv_navi.js
CHANGED
|
@@ -64746,452 +64746,666 @@ const cssVars = vars => {
|
|
|
64746
64746
|
};
|
|
64747
64747
|
const lengthValue = value => typeof value === "number" ? `${value}px` : value;
|
|
64748
64748
|
|
|
64749
|
-
|
|
64750
|
-
|
|
64751
|
-
|
|
64752
|
-
|
|
64753
|
-
* USAGE:
|
|
64754
|
-
* ```jsx
|
|
64755
|
-
* function ListControlled({ items }) {
|
|
64756
|
-
* const tracker = useItemTracker({
|
|
64757
|
-
* onChange: () => console.log("items changed"),
|
|
64758
|
-
* });
|
|
64759
|
-
*
|
|
64760
|
-
* return (
|
|
64761
|
-
* <ul>
|
|
64762
|
-
* {items.map((item, i) => (
|
|
64763
|
-
* <Row key={item.id} id={item.id} index={i} hidden={item.hidden} value={item.value} tracker={tracker} />
|
|
64764
|
-
* ))}
|
|
64765
|
-
* <Count tracker={tracker} />
|
|
64766
|
-
* </ul>
|
|
64767
|
-
* );
|
|
64768
|
-
* }
|
|
64769
|
-
*
|
|
64770
|
-
* function Row({ id, index, hidden, value, tracker }) {
|
|
64771
|
-
* const visibleIndex = tracker.useTrackItem({ id, index, hidden, value });
|
|
64772
|
-
* if (visibleIndex === -1) return null;
|
|
64773
|
-
* return <li>{value}</li>;
|
|
64774
|
-
* }
|
|
64775
|
-
*
|
|
64776
|
-
* function Count({ tracker }) {
|
|
64777
|
-
* const count = tracker.visibleCountSignal.value; // re-renders only when count changes
|
|
64778
|
-
* return <span>{count} items</span>;
|
|
64779
|
-
* }
|
|
64780
|
-
* ```
|
|
64781
|
-
*
|
|
64782
|
-
* INTERNALS:
|
|
64783
|
-
* - registrations: Map key → data, contains only visible items
|
|
64784
|
-
* - idToKey: Map id → key, stable across renders
|
|
64785
|
-
* - orderedKeys: number[] of visible item keys sorted by explicit order
|
|
64786
|
-
* - keyToOrderedIndex: Map key → orderedKeys index, gives O(1) indexOf equivalent
|
|
64787
|
-
* - keyToExplicitOrder: Map key → explicitly passed index, used to maintain sort order
|
|
64788
|
-
* - allItemsSignal: signal(array), all items including hidden, ordered by explicit index
|
|
64789
|
-
* - visibleItemsSignal: signal(array), non-hidden items only
|
|
64790
|
-
* - countSignal: signal(number), count of all items including hidden
|
|
64791
|
-
* - visibleCountSignal: signal(number), updated in microtask batch, only when count changes
|
|
64792
|
-
* - propSignals: Map propName → signal(array), updated in microtask batch with element equality
|
|
64793
|
-
* - onChangeRef: holds the latest onChange callback, called once per microtask batch
|
|
64794
|
-
*
|
|
64795
|
-
* useTrackItem(id, data, index): registers the item with an explicitly provided index
|
|
64796
|
-
* that determines its position among siblings. The caller (e.g. items.map) knows the
|
|
64797
|
-
* correct order and passes it directly — no render-sequence deduction needed.
|
|
64798
|
-
* Returns the visible rank (position among non-hidden items), or -1 when hidden.
|
|
64799
|
-
* Signals and onChange are deferred to a microtask so multiple items updating
|
|
64800
|
-
* in one commit cause only one notification.
|
|
64801
|
-
*
|
|
64802
|
-
* getTrackedItemByIndex(index): synchronous O(1) lookup of a visible item by
|
|
64803
|
-
* its visible rank. Returns undefined when index is out of range.
|
|
64804
|
-
*
|
|
64805
|
-
* peekItems(): the items as they stand right now, without waiting for the
|
|
64806
|
-
* deferred notification — what a sibling rendering after the items must read
|
|
64807
|
-
* to paint them in the same commit.
|
|
64808
|
-
*/
|
|
64809
|
-
|
|
64810
|
-
const useItemTracker = ({ onChange } = {}) => {
|
|
64811
|
-
const onChangeRef = useRef(onChange);
|
|
64812
|
-
onChangeRef.current = onChange;
|
|
64813
|
-
const trackerRef = useRef(null);
|
|
64814
|
-
let tracker = trackerRef.current;
|
|
64815
|
-
if (!tracker) {
|
|
64816
|
-
trackerRef.current = tracker = createItemTracker((items) => {
|
|
64817
|
-
onChangeRef.current?.(items);
|
|
64818
|
-
});
|
|
64749
|
+
const ListItemHeaderOrFooterResolver = props => {
|
|
64750
|
+
const Next = useNextResolver();
|
|
64751
|
+
if (props.header) {
|
|
64752
|
+
return renderResolver(ListItemHeader, props);
|
|
64819
64753
|
}
|
|
64820
|
-
|
|
64821
|
-
|
|
64822
|
-
|
|
64823
|
-
|
|
64824
|
-
|
|
64754
|
+
if (props.footer) {
|
|
64755
|
+
return renderResolver(ListItemFooter, props);
|
|
64756
|
+
}
|
|
64757
|
+
return jsx(Next, {
|
|
64758
|
+
...props
|
|
64759
|
+
});
|
|
64760
|
+
};
|
|
64761
|
+
const ListItemHeader = props => {
|
|
64762
|
+
const Next = useNextResolver();
|
|
64763
|
+
const {
|
|
64764
|
+
ref
|
|
64765
|
+
} = props;
|
|
64766
|
+
useDisplayedLayoutEffect(ref, headerEl => {
|
|
64767
|
+
const listContainerEl = headerEl.closest(".navi_list_container");
|
|
64768
|
+
const rect = headerEl.getBoundingClientRect();
|
|
64769
|
+
listContainerEl.style.setProperty("--list-header-height", `${rect.height}px`);
|
|
64770
|
+
listContainerEl.style.setProperty("--list-header-width", `${rect.width}px`);
|
|
64771
|
+
}, []);
|
|
64772
|
+
return jsx(Next, {
|
|
64773
|
+
...props,
|
|
64774
|
+
header: undefined,
|
|
64775
|
+
role: "presentation",
|
|
64776
|
+
baseClassName: "navi_list_item_header"
|
|
64777
|
+
});
|
|
64778
|
+
};
|
|
64779
|
+
const ListItemFooter = props => {
|
|
64780
|
+
const Next = useNextResolver();
|
|
64781
|
+
const {
|
|
64782
|
+
ref
|
|
64783
|
+
} = props;
|
|
64784
|
+
useDisplayedLayoutEffect(ref, footerEl => {
|
|
64785
|
+
const listContainerEl = footerEl.closest(".navi_list_container");
|
|
64786
|
+
const rect = footerEl.getBoundingClientRect();
|
|
64787
|
+
listContainerEl.style.setProperty("--list-footer-height", `${rect.height}px`);
|
|
64788
|
+
listContainerEl.style.setProperty("--list-footer-width", `${rect.width}px`);
|
|
64789
|
+
}, []);
|
|
64790
|
+
return jsx(Next, {
|
|
64791
|
+
...props,
|
|
64792
|
+
footer: undefined,
|
|
64793
|
+
role: "presentation",
|
|
64794
|
+
baseClassName: "navi_list_item_footer"
|
|
64825
64795
|
});
|
|
64826
|
-
return tracker;
|
|
64827
64796
|
};
|
|
64828
64797
|
|
|
64829
|
-
|
|
64830
|
-
|
|
64831
|
-
|
|
64832
|
-
|
|
64833
|
-
|
|
64834
|
-
|
|
64835
|
-
|
|
64836
|
-
|
|
64837
|
-
|
|
64838
|
-
|
|
64839
|
-
|
|
64840
|
-
|
|
64841
|
-
|
|
64842
|
-
|
|
64843
|
-
|
|
64844
|
-
|
|
64845
|
-
|
|
64846
|
-
|
|
64847
|
-
|
|
64848
|
-
|
|
64849
|
-
|
|
64850
|
-
|
|
64851
|
-
|
|
64852
|
-
|
|
64853
|
-
|
|
64798
|
+
// Everything the list knows about its rows, in one place: how many the
|
|
64799
|
+
// collection has and where each child's rows start (the places), which rows
|
|
64800
|
+
// are drawn and which of those mount and show (the rows), and what each says
|
|
64801
|
+
// about itself (the items). Two clocks. Places and "is anything standing
|
|
64802
|
+
// above me" answer synchronously, in the middle of a render pass — a row asks
|
|
64803
|
+
// about the rows before it, and those have rendered already. The items and
|
|
64804
|
+
// the counts settle once per frame (a microtask): many rows change in one
|
|
64805
|
+
// commit, and what reads them wants one notification.
|
|
64806
|
+
//
|
|
64807
|
+
// Why places are read off the walk and not off the renders: a child knows how
|
|
64808
|
+
// many rows it stands for but not what was declared before it, and it cannot
|
|
64809
|
+
// deduce that from when it renders — a render is free to skip it. A child that
|
|
64810
|
+
// draws from signals and whose props are all referentially === the previous
|
|
64811
|
+
// ones does not render again (@preact/signals installs a shouldComponentUpdate
|
|
64812
|
+
// that says so), which is what any child nobody rebuilt this frame is — and
|
|
64813
|
+
// children numbered as they render would then slide up into the place of the
|
|
64814
|
+
// one that was skipped. So the list names a slot for each of its children and
|
|
64815
|
+
// declares them here, in order, before any of them renders (see
|
|
64816
|
+
// ListDeclaredChildren). A child then takes its place BY SLOT, and the place
|
|
64817
|
+
// is a signal: it moves when what stands before it changes — a row filtered
|
|
64818
|
+
// out, a run taking in rows, a slot added or moved — and the child follows,
|
|
64819
|
+
// rendered again for it whether or not anything else would have rendered it.
|
|
64820
|
+
//
|
|
64821
|
+
// Why "first" is a signal too: only the row itself knows, once it renders,
|
|
64822
|
+
// that it renders nothing (filtered out by a search), and the rows after it
|
|
64823
|
+
// may have been handed back unchanged. The first mounted row of a scope is
|
|
64824
|
+
// kept as a signal each of them reads; when it leaves, they are rendered again.
|
|
64854
64825
|
|
|
64855
|
-
|
|
64856
|
-
const countModified = countSignal.peek() !== newCount;
|
|
64857
|
-
if (countModified) {
|
|
64858
|
-
countSignal.value = newCount;
|
|
64859
|
-
someChange = true;
|
|
64860
|
-
}
|
|
64826
|
+
const UNGROUPED = Symbol("ungrouped");
|
|
64861
64827
|
|
|
64862
|
-
|
|
64863
|
-
|
|
64864
|
-
|
|
64865
|
-
|
|
64866
|
-
|
|
64867
|
-
|
|
64868
|
-
|
|
64869
|
-
|
|
64870
|
-
|
|
64871
|
-
|
|
64872
|
-
|
|
64873
|
-
|
|
64874
|
-
|
|
64875
|
-
|
|
64876
|
-
|
|
64877
|
-
|
|
64878
|
-
|
|
64879
|
-
|
|
64880
|
-
|
|
64881
|
-
|
|
64882
|
-
|
|
64883
|
-
|
|
64884
|
-
|
|
64885
|
-
|
|
64886
|
-
|
|
64887
|
-
|
|
64888
|
-
|
|
64889
|
-
|
|
64890
|
-
|
|
64891
|
-
|
|
64892
|
-
|
|
64893
|
-
|
|
64828
|
+
const createListRows = () => {
|
|
64829
|
+
const totalSignal = signal(0);
|
|
64830
|
+
// Bumped whenever a run takes in rows. The list itself has to hear about it:
|
|
64831
|
+
// rows arriving outside the render window change nothing it can see (nothing
|
|
64832
|
+
// registers, nothing is drawn), and yet they are what it may have been
|
|
64833
|
+
// waiting for — the row it was told to open on, for one.
|
|
64834
|
+
const pagesSignal = signal(0);
|
|
64835
|
+
// How many runs are re-reading rows they already show. The list wears it as
|
|
64836
|
+
// an attribute: what is drawn is from before, and the app may want to say so
|
|
64837
|
+
// without taking anything away.
|
|
64838
|
+
const refreshingSignal = signal(0);
|
|
64839
|
+
// The slots each walk declared, in order, by the slot the walk stands in
|
|
64840
|
+
// (null for the list's own children). Together they are a tree: a group's
|
|
64841
|
+
// rows live inside the group's slot.
|
|
64842
|
+
const slotIdsByParent = new Map();
|
|
64843
|
+
// Who took a place — a row, or a run of rows — and how many rows of the
|
|
64844
|
+
// collection it stands for. The place itself is a signal, see take.
|
|
64845
|
+
const ownerById = new Map();
|
|
64846
|
+
// The owners standing in each slot, in the order they took their place.
|
|
64847
|
+
// One, as a rule; a child that renders several rows keeps them in the order
|
|
64848
|
+
// they first rendered, which is all it can be told.
|
|
64849
|
+
const ownerIdsBySlot = new Map();
|
|
64850
|
+
const locatorByOwner = new Map();
|
|
64851
|
+
// The slots as the tree reads, first to last, and where each stands in it.
|
|
64852
|
+
// Rebuilt once a walk has changed the tree, read to place the owners.
|
|
64853
|
+
const slotWalk = [];
|
|
64854
|
+
const rankBySlot = new Map();
|
|
64855
|
+
let rowTotal = 0;
|
|
64856
|
+
// Owners have left and the others have not been moved up yet. Done on the
|
|
64857
|
+
// next ask rather than on the spot: rows leave many at a time (a search, a
|
|
64858
|
+
// list unmounting), and moving the others up once is enough.
|
|
64859
|
+
let placesStale = false;
|
|
64860
|
+
// Where the last slot holding an owner stands: an owner arriving at or after
|
|
64861
|
+
// it is placed at the end without going over the others — a whole first
|
|
64862
|
+
// render, rows arriving in order, costs each row nothing but itself.
|
|
64863
|
+
let rankOwnedLast = -1;
|
|
64894
64864
|
|
|
64895
|
-
|
|
64896
|
-
|
|
64897
|
-
|
|
64898
|
-
|
|
64899
|
-
|
|
64900
|
-
|
|
64901
|
-
|
|
64902
|
-
if (allItemsChanged) {
|
|
64903
|
-
itemsSignal.value = allItems;
|
|
64904
|
-
someChange = true;
|
|
64905
|
-
}
|
|
64906
|
-
if (visibleItemsChanged) {
|
|
64907
|
-
visibleItemsSignal.value = visibleItems;
|
|
64908
|
-
someChange = true;
|
|
64909
|
-
}
|
|
64910
|
-
const noMatchCountModified =
|
|
64911
|
-
noMatchCountSignal.peek() !== newNoMatchCount;
|
|
64912
|
-
if (noMatchCountModified) {
|
|
64913
|
-
noMatchCountSignal.value = newNoMatchCount;
|
|
64914
|
-
someChange = true;
|
|
64865
|
+
const rebuildWalk = () => {
|
|
64866
|
+
slotWalk.length = 0;
|
|
64867
|
+
rankBySlot.clear();
|
|
64868
|
+
const visit = (parentSlotId) => {
|
|
64869
|
+
const slotIds = slotIdsByParent.get(parentSlotId);
|
|
64870
|
+
if (!slotIds) {
|
|
64871
|
+
return;
|
|
64915
64872
|
}
|
|
64916
|
-
|
|
64917
|
-
|
|
64873
|
+
for (const slotId of slotIds) {
|
|
64874
|
+
rankBySlot.set(slotId, slotWalk.length);
|
|
64875
|
+
slotWalk.push(slotId);
|
|
64876
|
+
visit(slotId);
|
|
64918
64877
|
}
|
|
64919
|
-
}
|
|
64878
|
+
};
|
|
64879
|
+
visit(null);
|
|
64920
64880
|
};
|
|
64921
|
-
|
|
64922
|
-
|
|
64923
|
-
|
|
64924
|
-
|
|
64925
|
-
|
|
64926
|
-
|
|
64927
|
-
|
|
64928
|
-
|
|
64929
|
-
|
|
64881
|
+
// Every place, in one go: a place is the sum of what stands before it, so
|
|
64882
|
+
// there is nothing to hand out one at a time. Writing a place that did not
|
|
64883
|
+
// change wakes nobody — a signal ignores a value equal to its own.
|
|
64884
|
+
const refreshPlaces = () => {
|
|
64885
|
+
placesStale = false;
|
|
64886
|
+
let index = 0;
|
|
64887
|
+
let rank = 0;
|
|
64888
|
+
rankOwnedLast = -1;
|
|
64889
|
+
while (rank < slotWalk.length) {
|
|
64890
|
+
const ownerIds = ownerIdsBySlot.get(slotWalk[rank]);
|
|
64891
|
+
if (ownerIds) {
|
|
64892
|
+
for (const ownerId of ownerIds) {
|
|
64893
|
+
const owner = ownerById.get(ownerId);
|
|
64894
|
+
owner.placeSignal.value = index;
|
|
64895
|
+
index += owner.rowCount;
|
|
64896
|
+
}
|
|
64897
|
+
rankOwnedLast = rank;
|
|
64930
64898
|
}
|
|
64931
|
-
|
|
64932
|
-
|
|
64933
|
-
|
|
64899
|
+
rank++;
|
|
64900
|
+
}
|
|
64901
|
+
rowTotal = index;
|
|
64902
|
+
totalSignal.value = index;
|
|
64903
|
+
// A run's edges are places too (see refreshFirst).
|
|
64904
|
+
markStale(UNGROUPED);
|
|
64934
64905
|
};
|
|
64935
|
-
|
|
64936
|
-
|
|
64937
|
-
if (
|
|
64906
|
+
const addToSlot = (slotId, ownerId) => {
|
|
64907
|
+
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
64908
|
+
if (ownerIds) {
|
|
64909
|
+
ownerIds.push(ownerId);
|
|
64910
|
+
} else {
|
|
64911
|
+
ownerIdsBySlot.set(slotId, [ownerId]);
|
|
64912
|
+
}
|
|
64913
|
+
warnIfEveryRowInOneSlot(slotId);
|
|
64914
|
+
};
|
|
64915
|
+
// Rows that all stand in the same slot keep the order they first mounted in:
|
|
64916
|
+
// the walk is over the children the list is given, and a component holding
|
|
64917
|
+
// them is one child however many rows it renders. Everything about a place
|
|
64918
|
+
// then stops following what the caller writes — a search reordering the rows
|
|
64919
|
+
// moves nothing. Said once, and only for the shape that can be nothing else:
|
|
64920
|
+
// the list's whole content is one child, and several rows came out of it.
|
|
64921
|
+
let everyRowInOneSlotWarned = false;
|
|
64922
|
+
const warnIfEveryRowInOneSlot = (slotId) => {
|
|
64923
|
+
if (everyRowInOneSlotWarned) {
|
|
64938
64924
|
return;
|
|
64939
64925
|
}
|
|
64940
|
-
|
|
64941
|
-
|
|
64926
|
+
const rootSlotIds = slotIdsByParent.get(null);
|
|
64927
|
+
if (!rootSlotIds || rootSlotIds.length !== 1 || rootSlotIds[0] !== slotId) {
|
|
64928
|
+
return;
|
|
64929
|
+
}
|
|
64930
|
+
if (ownerIdsBySlot.get(slotId).length < 2) {
|
|
64931
|
+
return;
|
|
64932
|
+
}
|
|
64933
|
+
everyRowInOneSlotWarned = true;
|
|
64934
|
+
console.warn(
|
|
64935
|
+
`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.`,
|
|
64936
|
+
);
|
|
64942
64937
|
};
|
|
64943
|
-
|
|
64944
|
-
|
|
64945
|
-
|
|
64946
|
-
|
|
64947
|
-
let lo = 0;
|
|
64948
|
-
let hi = orderedKeys.length;
|
|
64949
|
-
while (lo < hi) {
|
|
64950
|
-
const mid = (lo + hi) >> 1;
|
|
64951
|
-
if (keyToExplicitOrder.get(orderedKeys[mid]) <= explicitOrder) {
|
|
64952
|
-
lo = mid + 1;
|
|
64953
|
-
} else {
|
|
64954
|
-
hi = mid;
|
|
64955
|
-
}
|
|
64938
|
+
const removeFromSlot = (slotId, ownerId) => {
|
|
64939
|
+
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
64940
|
+
if (!ownerIds) {
|
|
64941
|
+
return;
|
|
64956
64942
|
}
|
|
64957
|
-
|
|
64958
|
-
|
|
64959
|
-
|
|
64943
|
+
const index = ownerIds.indexOf(ownerId);
|
|
64944
|
+
if (index !== -1) {
|
|
64945
|
+
ownerIds.splice(index, 1);
|
|
64946
|
+
}
|
|
64947
|
+
if (ownerIds.length === 0) {
|
|
64948
|
+
ownerIdsBySlot.delete(slotId);
|
|
64960
64949
|
}
|
|
64961
64950
|
};
|
|
64962
|
-
|
|
64963
|
-
|
|
64964
|
-
|
|
64965
|
-
|
|
64966
|
-
|
|
64967
|
-
const
|
|
64968
|
-
|
|
64969
|
-
lo = mid + 1;
|
|
64970
|
-
} else {
|
|
64971
|
-
hi = mid;
|
|
64951
|
+
// A slot the walk no longer names: whatever stood in it is gone, and so is
|
|
64952
|
+
// whatever a walk inside it had declared.
|
|
64953
|
+
const dropSlot = (slotId) => {
|
|
64954
|
+
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
64955
|
+
if (ownerIds) {
|
|
64956
|
+
for (const ownerId of ownerIds) {
|
|
64957
|
+
ownerById.delete(ownerId);
|
|
64972
64958
|
}
|
|
64959
|
+
ownerIdsBySlot.delete(slotId);
|
|
64973
64960
|
}
|
|
64974
|
-
|
|
64975
|
-
|
|
64976
|
-
|
|
64961
|
+
const childSlotIds = slotIdsByParent.get(slotId);
|
|
64962
|
+
if (childSlotIds) {
|
|
64963
|
+
slotIdsByParent.delete(slotId);
|
|
64964
|
+
for (const childSlotId of childSlotIds) {
|
|
64965
|
+
dropSlot(childSlotId);
|
|
64966
|
+
}
|
|
64977
64967
|
}
|
|
64978
64968
|
};
|
|
64979
64969
|
|
|
64980
|
-
|
|
64981
|
-
|
|
64982
|
-
|
|
64983
|
-
|
|
64984
|
-
|
|
64985
|
-
|
|
64986
|
-
|
|
64987
|
-
|
|
64970
|
+
// ---- the rows drawn ----
|
|
64971
|
+
// rowId → { ownerId, place, groupId, data, mounted, visible, item }
|
|
64972
|
+
const rowById = new Map();
|
|
64973
|
+
// groupId → { firstSignal, countSignal, noMatchCountSignal }
|
|
64974
|
+
const groupById = new Map();
|
|
64975
|
+
// ownerId → { from, to }, for the runs (see declareWindow).
|
|
64976
|
+
const windowByOwner = new Map();
|
|
64977
|
+
// The first place something stands at, outside any group: the mounted rows
|
|
64978
|
+
// and the rows a run holds above its window. Per group, the group's first
|
|
64979
|
+
// mounted row.
|
|
64980
|
+
const firstStandingSignal = signal(-1);
|
|
64981
|
+
// The scopes whose first row left: recounted on the next ask, or at the end
|
|
64982
|
+
// of the frame, whichever comes first. A row mounting before the first one
|
|
64983
|
+
// moves it at once, no recount needed — the first can only ever move up.
|
|
64984
|
+
const staleScopes = new Set();
|
|
64985
|
+
const scopeOf = (groupId) => (groupId === undefined ? UNGROUPED : groupId);
|
|
64986
|
+
const groupOf = (groupId) => {
|
|
64987
|
+
let group = groupById.get(groupId);
|
|
64988
|
+
if (!group) {
|
|
64989
|
+
group = {
|
|
64990
|
+
firstSignal: signal(-1),
|
|
64991
|
+
countSignal: signal(0),
|
|
64992
|
+
noMatchCountSignal: signal(0),
|
|
64993
|
+
};
|
|
64994
|
+
groupById.set(groupId, group);
|
|
64988
64995
|
}
|
|
64996
|
+
return group;
|
|
64989
64997
|
};
|
|
64990
|
-
|
|
64991
|
-
|
|
64992
|
-
|
|
64993
|
-
|
|
64994
|
-
|
|
64995
|
-
|
|
64996
|
-
|
|
64997
|
-
|
|
64998
|
-
orderedKeys.splice(idx, 1);
|
|
64999
|
-
keyToOrderedIndex.delete(key);
|
|
65000
|
-
for (let i = idx; i < orderedKeys.length; i++) {
|
|
65001
|
-
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
65002
|
-
}
|
|
64998
|
+
const firstSignalOf = (scope) =>
|
|
64999
|
+
scope === UNGROUPED ? firstStandingSignal : groupOf(scope).firstSignal;
|
|
65000
|
+
const refreshFirst = (scope) => {
|
|
65001
|
+
staleScopes.delete(scope);
|
|
65002
|
+
let first = -1;
|
|
65003
|
+
const consider = (place) => {
|
|
65004
|
+
if (place !== undefined && (first === -1 || place < first)) {
|
|
65005
|
+
first = place;
|
|
65003
65006
|
}
|
|
65004
|
-
|
|
65005
|
-
|
|
65006
|
-
|
|
65007
|
-
|
|
65008
|
-
return;
|
|
65009
|
-
}
|
|
65010
|
-
|
|
65011
|
-
// Maintain allRegistrations and allOrderedKeys for all non-presentation items.
|
|
65012
|
-
allRegistrations.set(key, data);
|
|
65013
|
-
allKeys.add(key);
|
|
65014
|
-
const currentAllIdx = keyToAllOrderedIndex.get(key);
|
|
65015
|
-
const previousOrder = keyToExplicitOrder.get(key);
|
|
65016
|
-
keyToExplicitOrder.set(key, index);
|
|
65017
|
-
if (currentAllIdx === undefined) {
|
|
65018
|
-
insertAllKey(key, index);
|
|
65019
|
-
} else if (previousOrder !== index) {
|
|
65020
|
-
allOrderedKeys.splice(currentAllIdx, 1);
|
|
65021
|
-
keyToAllOrderedIndex.delete(key);
|
|
65022
|
-
for (let i = currentAllIdx; i < allOrderedKeys.length; i++) {
|
|
65023
|
-
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
65007
|
+
};
|
|
65008
|
+
for (const row of rowById.values()) {
|
|
65009
|
+
if (row.mounted && scopeOf(row.groupId) === scope) {
|
|
65010
|
+
consider(row.place);
|
|
65024
65011
|
}
|
|
65025
|
-
insertAllKey(key, index);
|
|
65026
65012
|
}
|
|
65027
|
-
|
|
65028
|
-
|
|
65029
|
-
|
|
65030
|
-
|
|
65031
|
-
|
|
65032
|
-
|
|
65033
|
-
|
|
65034
|
-
|
|
65035
|
-
|
|
65013
|
+
if (scope === UNGROUPED) {
|
|
65014
|
+
for (const [ownerId, window] of windowByOwner) {
|
|
65015
|
+
const owner = ownerById.get(ownerId);
|
|
65016
|
+
if (!owner) {
|
|
65017
|
+
continue;
|
|
65018
|
+
}
|
|
65019
|
+
const start = owner.placeSignal.peek();
|
|
65020
|
+
if (window.from > start) {
|
|
65021
|
+
consider(start);
|
|
65022
|
+
}
|
|
65023
|
+
if (window.to < start + owner.rowCount) {
|
|
65024
|
+
consider(window.to);
|
|
65036
65025
|
}
|
|
65037
65026
|
}
|
|
65038
|
-
return;
|
|
65039
|
-
}
|
|
65040
|
-
|
|
65041
|
-
registrations.set(key, data);
|
|
65042
|
-
const currentIdx = keyToOrderedIndex.get(key);
|
|
65043
|
-
if (currentIdx === undefined) {
|
|
65044
|
-
insertKey(key, index);
|
|
65045
|
-
return;
|
|
65046
65027
|
}
|
|
65047
|
-
|
|
65028
|
+
firstSignalOf(scope).value = first;
|
|
65029
|
+
};
|
|
65030
|
+
const markStale = (scope) => {
|
|
65031
|
+
if (staleScopes.has(scope)) {
|
|
65048
65032
|
return;
|
|
65049
65033
|
}
|
|
65050
|
-
|
|
65051
|
-
|
|
65052
|
-
|
|
65053
|
-
|
|
65034
|
+
staleScopes.add(scope);
|
|
65035
|
+
queueMicrotask(() => {
|
|
65036
|
+
if (staleScopes.has(scope)) {
|
|
65037
|
+
refreshFirst(scope);
|
|
65038
|
+
}
|
|
65039
|
+
});
|
|
65040
|
+
};
|
|
65041
|
+
const leaveFirst = (row) => {
|
|
65042
|
+
const scope = scopeOf(row.groupId);
|
|
65043
|
+
if (firstSignalOf(scope).peek() === row.place) {
|
|
65044
|
+
markStale(scope);
|
|
65054
65045
|
}
|
|
65055
|
-
insertKey(key, index);
|
|
65056
65046
|
};
|
|
65057
65047
|
|
|
65058
|
-
|
|
65059
|
-
|
|
65060
|
-
|
|
65061
|
-
|
|
65062
|
-
|
|
65063
|
-
|
|
65064
|
-
|
|
65065
|
-
|
|
65048
|
+
// ---- the items, settled once per frame ----
|
|
65049
|
+
const itemsSignal = signal([]);
|
|
65050
|
+
const visibleItemsSignal = signal([]);
|
|
65051
|
+
const countSignal = signal(0);
|
|
65052
|
+
const visibleCountSignal = signal(0);
|
|
65053
|
+
const noMatchCountSignal = signal(0);
|
|
65054
|
+
let notifyScheduled = false;
|
|
65055
|
+
const runNotify = () => {
|
|
65056
|
+
batch(() => {
|
|
65057
|
+
const itemRows = [];
|
|
65058
|
+
for (const row of rowById.values()) {
|
|
65059
|
+
if (row.item) {
|
|
65060
|
+
itemRows.push(row);
|
|
65061
|
+
}
|
|
65066
65062
|
}
|
|
65067
|
-
|
|
65068
|
-
|
|
65069
|
-
|
|
65070
|
-
|
|
65071
|
-
|
|
65063
|
+
itemRows.sort(compareRowPlaces);
|
|
65064
|
+
const items = [];
|
|
65065
|
+
const visibleItems = [];
|
|
65066
|
+
let noMatchCount = 0;
|
|
65067
|
+
const countByGroup = new Map();
|
|
65068
|
+
const noMatchCountByGroup = new Map();
|
|
65069
|
+
const prevItems = itemsSignal.peek();
|
|
65070
|
+
const prevVisibleItems = visibleItemsSignal.peek();
|
|
65071
|
+
let itemsChanged = prevItems.length !== itemRows.length;
|
|
65072
|
+
let visibleItemsChanged = false;
|
|
65073
|
+
for (const row of itemRows) {
|
|
65074
|
+
const item = row.data;
|
|
65075
|
+
// Compared by reference: any prop change (selected, disabled, …) is a
|
|
65076
|
+
// new props object.
|
|
65077
|
+
if (!itemsChanged && item !== prevItems[items.length]) {
|
|
65078
|
+
itemsChanged = true;
|
|
65079
|
+
}
|
|
65080
|
+
items.push(item);
|
|
65081
|
+
const noMatch = item.match === false;
|
|
65082
|
+
if (noMatch) {
|
|
65083
|
+
noMatchCount++;
|
|
65084
|
+
}
|
|
65085
|
+
if (row.groupId !== undefined) {
|
|
65086
|
+
countByGroup.set(
|
|
65087
|
+
row.groupId,
|
|
65088
|
+
(countByGroup.get(row.groupId) || 0) + 1,
|
|
65089
|
+
);
|
|
65090
|
+
if (noMatch) {
|
|
65091
|
+
noMatchCountByGroup.set(
|
|
65092
|
+
row.groupId,
|
|
65093
|
+
(noMatchCountByGroup.get(row.groupId) || 0) + 1,
|
|
65094
|
+
);
|
|
65095
|
+
}
|
|
65096
|
+
}
|
|
65097
|
+
if (row.visible) {
|
|
65098
|
+
if (
|
|
65099
|
+
!visibleItemsChanged &&
|
|
65100
|
+
item !== prevVisibleItems[visibleItems.length]
|
|
65101
|
+
) {
|
|
65102
|
+
visibleItemsChanged = true;
|
|
65103
|
+
}
|
|
65104
|
+
visibleItems.push(item);
|
|
65105
|
+
}
|
|
65106
|
+
}
|
|
65107
|
+
if (visibleItems.length !== prevVisibleItems.length) {
|
|
65108
|
+
visibleItemsChanged = true;
|
|
65109
|
+
}
|
|
65110
|
+
let someChange = false;
|
|
65111
|
+
if (countSignal.peek() !== items.length) {
|
|
65112
|
+
countSignal.value = items.length;
|
|
65113
|
+
someChange = true;
|
|
65114
|
+
}
|
|
65115
|
+
if (visibleCountSignal.peek() !== visibleItems.length) {
|
|
65116
|
+
visibleCountSignal.value = visibleItems.length;
|
|
65117
|
+
someChange = true;
|
|
65118
|
+
}
|
|
65119
|
+
if (itemsChanged) {
|
|
65120
|
+
itemsSignal.value = items;
|
|
65121
|
+
someChange = true;
|
|
65122
|
+
}
|
|
65123
|
+
if (visibleItemsChanged) {
|
|
65124
|
+
visibleItemsSignal.value = visibleItems;
|
|
65125
|
+
someChange = true;
|
|
65126
|
+
}
|
|
65127
|
+
if (noMatchCountSignal.peek() !== noMatchCount) {
|
|
65128
|
+
noMatchCountSignal.value = noMatchCount;
|
|
65129
|
+
someChange = true;
|
|
65130
|
+
}
|
|
65131
|
+
for (const [groupId, group] of groupById) {
|
|
65132
|
+
group.countSignal.value = countByGroup.get(groupId) || 0;
|
|
65133
|
+
group.noMatchCountSignal.value = noMatchCountByGroup.get(groupId) || 0;
|
|
65134
|
+
}
|
|
65135
|
+
if (someChange && listRows.onChange) {
|
|
65136
|
+
listRows.onChange();
|
|
65137
|
+
}
|
|
65138
|
+
});
|
|
65072
65139
|
};
|
|
65073
|
-
|
|
65074
|
-
|
|
65075
|
-
|
|
65076
|
-
idToKey.set(id, keyCounter++);
|
|
65140
|
+
const notify = () => {
|
|
65141
|
+
if (notifyScheduled) {
|
|
65142
|
+
return;
|
|
65077
65143
|
}
|
|
65078
|
-
|
|
65079
|
-
|
|
65080
|
-
|
|
65081
|
-
|
|
65082
|
-
|
|
65083
|
-
|
|
65084
|
-
|
|
65085
|
-
|
|
65086
|
-
const { id, index } = data;
|
|
65087
|
-
const key = keyForId(id);
|
|
65088
|
-
|
|
65089
|
-
syncItem(key, index, data);
|
|
65090
|
-
notify();
|
|
65091
|
-
|
|
65092
|
-
useLayoutEffect(() => {
|
|
65093
|
-
return () => {
|
|
65094
|
-
unregisterKey(key);
|
|
65095
|
-
notify();
|
|
65096
|
-
};
|
|
65097
|
-
}, []);
|
|
65098
|
-
|
|
65099
|
-
if (data.filtered || data.hidden || data.role === "presentation") {
|
|
65100
|
-
return -1;
|
|
65101
|
-
}
|
|
65102
|
-
return keyToOrderedIndex.get(key) ?? -1;
|
|
65103
|
-
};
|
|
65104
|
-
|
|
65105
|
-
const getTrackedItemByIndex = (index) => {
|
|
65106
|
-
const key = orderedKeys[index];
|
|
65107
|
-
if (key === undefined) {
|
|
65108
|
-
return undefined;
|
|
65109
|
-
}
|
|
65110
|
-
return registrations.get(key);
|
|
65111
|
-
};
|
|
65112
|
-
|
|
65113
|
-
// The items as they stand right now, notification pending or not — same
|
|
65114
|
-
// content as itemsSignal, minus the wait.
|
|
65115
|
-
//
|
|
65116
|
-
// Items register during their own render, while the signal is only updated
|
|
65117
|
-
// on a deferred microtask (see notify): a sibling rendering after them would
|
|
65118
|
-
// otherwise paint from an empty list and correct itself a frame later. That
|
|
65119
|
-
// frame is visible whenever the painted size feeds a layout decision — a
|
|
65120
|
-
// dialog sizing itself on its content measures the empty version and shifts
|
|
65121
|
-
// once the real one lands. Reading this instead makes the first paint the
|
|
65122
|
-
// right one. Callers must still subscribe to itemsSignal to re-render on
|
|
65123
|
-
// LATER changes; this is the value to display, not the notification.
|
|
65124
|
-
const peekItems = () => {
|
|
65125
|
-
if (!notifyScheduled) {
|
|
65126
|
-
return itemsSignal.peek();
|
|
65127
|
-
}
|
|
65128
|
-
const items = [];
|
|
65129
|
-
for (const key of allOrderedKeys) {
|
|
65130
|
-
items.push(allRegistrations.get(key));
|
|
65131
|
-
}
|
|
65132
|
-
return items;
|
|
65144
|
+
notifyScheduled = true;
|
|
65145
|
+
queueMicrotask(() => {
|
|
65146
|
+
if (!notifyScheduled) {
|
|
65147
|
+
return;
|
|
65148
|
+
}
|
|
65149
|
+
notifyScheduled = false;
|
|
65150
|
+
runNotify();
|
|
65151
|
+
});
|
|
65133
65152
|
};
|
|
65134
65153
|
|
|
65135
|
-
|
|
65136
|
-
|
|
65137
|
-
|
|
65138
|
-
|
|
65154
|
+
const listRows = {
|
|
65155
|
+
totalSignal,
|
|
65156
|
+
pagesSignal,
|
|
65157
|
+
refreshingSignal,
|
|
65158
|
+
// The rows that are items, in place order — every one drawn, and the ones
|
|
65159
|
+
// that show — and what the search made of them. Written once per frame.
|
|
65139
65160
|
itemsSignal,
|
|
65140
65161
|
visibleItemsSignal,
|
|
65141
65162
|
countSignal,
|
|
65142
65163
|
visibleCountSignal,
|
|
65143
65164
|
noMatchCountSignal,
|
|
65144
|
-
|
|
65165
|
+
// Called once per frame in which the items changed. Set by the list.
|
|
65166
|
+
onChange: null,
|
|
65167
|
+
// What a run needs to know about the list it lives in: how many rows the
|
|
65168
|
+
// list is willing to draw at once, which end it opens on, and how much
|
|
65169
|
+
// room one row is given — a row whose content has not arrived must take
|
|
65170
|
+
// exactly that, or the rows drawn would not reach where the list says they
|
|
65171
|
+
// are.
|
|
65172
|
+
renderBudget: 0,
|
|
65173
|
+
scrolled: "start",
|
|
65174
|
+
// The list is on its way somewhere: what the window frames is not what it
|
|
65175
|
+
// is about to frame, so a run must not fetch for it (see holdWindow).
|
|
65176
|
+
holdPending: false,
|
|
65177
|
+
// Called by a run just before rows land in it: what is on screen must not
|
|
65178
|
+
// move because something arrived above it. Set by the list itself.
|
|
65179
|
+
captureAnchor: () => {},
|
|
65180
|
+
horizontal: false,
|
|
65181
|
+
virtualItemSizeSignal: null,
|
|
65182
|
+
renderSkeleton: undefined,
|
|
65183
|
+
// The children a walk stands over, in order — said in one call, before any
|
|
65184
|
+
// of them renders, so that what a child asks next is answered against the
|
|
65185
|
+
// whole picture and not against the children that happened to render
|
|
65186
|
+
// first. Said again on every render of the walk, and heard only when
|
|
65187
|
+
// something moved.
|
|
65188
|
+
declareSlots: (parentSlotId, slotIds) => {
|
|
65189
|
+
const slotIdsPrevious = slotIdsByParent.get(parentSlotId);
|
|
65190
|
+
if (slotIdsPrevious && sameSlotIds(slotIdsPrevious, slotIds)) {
|
|
65191
|
+
return;
|
|
65192
|
+
}
|
|
65193
|
+
if (slotIdsPrevious) {
|
|
65194
|
+
const slotIdSet = new Set(slotIds);
|
|
65195
|
+
for (const slotId of slotIdsPrevious) {
|
|
65196
|
+
if (!slotIdSet.has(slotId)) {
|
|
65197
|
+
dropSlot(slotId);
|
|
65198
|
+
}
|
|
65199
|
+
}
|
|
65200
|
+
}
|
|
65201
|
+
slotIdsByParent.set(parentSlotId, slotIds);
|
|
65202
|
+
rebuildWalk();
|
|
65203
|
+
refreshPlaces();
|
|
65204
|
+
},
|
|
65205
|
+
// Whether something has taken this slot for its own: what it renders
|
|
65206
|
+
// inside is then its to place (a run draws its groups with their rows
|
|
65207
|
+
// already placed), and no walk inside it has anything to declare.
|
|
65208
|
+
slotHasOwner: (slotId) => ownerIdsBySlot.has(slotId),
|
|
65209
|
+
// Whether any run of rows lives in this list: what makes a render window
|
|
65210
|
+
// mean anything (see List's renderBudget).
|
|
65211
|
+
hasRuns: () => locatorByOwner.size > 0,
|
|
65212
|
+
setRowLocator: (ownerId, locate) => {
|
|
65213
|
+
locatorByOwner.set(ownerId, locate);
|
|
65214
|
+
},
|
|
65215
|
+
dropRowLocator: (ownerId) => {
|
|
65216
|
+
locatorByOwner.delete(ownerId);
|
|
65217
|
+
},
|
|
65218
|
+
// Where the row named by that id sits, asked of whoever holds it.
|
|
65219
|
+
locateRow: (id) => {
|
|
65220
|
+
for (const locate of locatorByOwner.values()) {
|
|
65221
|
+
const index = locate(id);
|
|
65222
|
+
if (index !== null) {
|
|
65223
|
+
return index;
|
|
65224
|
+
}
|
|
65225
|
+
}
|
|
65226
|
+
return null;
|
|
65227
|
+
},
|
|
65228
|
+
// The place the owner's rows start at — read from a signal, so that the
|
|
65229
|
+
// owner is rendered again when it moves (see the top of this file). Asked on
|
|
65230
|
+
// every render, and answered without a second look for as long as the
|
|
65231
|
+
// owner stands in the same slot for the same number of rows.
|
|
65232
|
+
take: (ownerId, rowCount, slotId) => {
|
|
65233
|
+
let owner = ownerById.get(ownerId);
|
|
65234
|
+
if (owner) {
|
|
65235
|
+
if (owner.slotId !== slotId || owner.rowCount !== rowCount) {
|
|
65236
|
+
removeFromSlot(owner.slotId, ownerId);
|
|
65237
|
+
addToSlot(slotId, ownerId);
|
|
65238
|
+
owner.slotId = slotId;
|
|
65239
|
+
owner.rowCount = rowCount;
|
|
65240
|
+
placesStale = true;
|
|
65241
|
+
}
|
|
65242
|
+
if (placesStale) {
|
|
65243
|
+
refreshPlaces();
|
|
65244
|
+
}
|
|
65245
|
+
return owner.placeSignal.value;
|
|
65246
|
+
}
|
|
65247
|
+
if (placesStale) {
|
|
65248
|
+
refreshPlaces();
|
|
65249
|
+
}
|
|
65250
|
+
const rank = rankBySlot.get(slotId);
|
|
65251
|
+
addToSlot(slotId, ownerId);
|
|
65252
|
+
if (rank !== undefined && rank >= rankOwnedLast) {
|
|
65253
|
+
owner = { slotId, rowCount, placeSignal: signal(rowTotal) };
|
|
65254
|
+
ownerById.set(ownerId, owner);
|
|
65255
|
+
rowTotal += rowCount;
|
|
65256
|
+
rankOwnedLast = rank;
|
|
65257
|
+
totalSignal.value = rowTotal;
|
|
65258
|
+
return owner.placeSignal.value;
|
|
65259
|
+
}
|
|
65260
|
+
owner = { slotId, rowCount, placeSignal: signal(0) };
|
|
65261
|
+
ownerById.set(ownerId, owner);
|
|
65262
|
+
refreshPlaces();
|
|
65263
|
+
return owner.placeSignal.value;
|
|
65264
|
+
},
|
|
65265
|
+
// The owner stands for no row of the collection: it was filtered out by a
|
|
65266
|
+
// search, or it is gone.
|
|
65267
|
+
drop: (ownerId) => {
|
|
65268
|
+
const owner = ownerById.get(ownerId);
|
|
65269
|
+
if (!owner) {
|
|
65270
|
+
return;
|
|
65271
|
+
}
|
|
65272
|
+
ownerById.delete(ownerId);
|
|
65273
|
+
removeFromSlot(owner.slotId, ownerId);
|
|
65274
|
+
windowByOwner.delete(ownerId);
|
|
65275
|
+
if (placesStale) {
|
|
65276
|
+
return;
|
|
65277
|
+
}
|
|
65278
|
+
placesStale = true;
|
|
65279
|
+
queueMicrotask(() => {
|
|
65280
|
+
if (placesStale) {
|
|
65281
|
+
refreshPlaces();
|
|
65282
|
+
}
|
|
65283
|
+
});
|
|
65284
|
+
},
|
|
65285
|
+
|
|
65286
|
+
// ---- the rows drawn ----
|
|
65287
|
+
|
|
65288
|
+
// A run says which of its rows it draws. The others stand: rows above the
|
|
65289
|
+
// window are above every row drawn, whether or not any of the drawn ones
|
|
65290
|
+
// mounts (see refreshFirst).
|
|
65291
|
+
declareWindow: (ownerId, from, to) => {
|
|
65292
|
+
const window = windowByOwner.get(ownerId);
|
|
65293
|
+
if (window && window.from === from && window.to === to) {
|
|
65294
|
+
return;
|
|
65295
|
+
}
|
|
65296
|
+
windowByOwner.set(ownerId, { from, to });
|
|
65297
|
+
markStale(UNGROUPED);
|
|
65298
|
+
},
|
|
65299
|
+
// A row says what it is, where it renders: its place, the group it is
|
|
65300
|
+
// in, and its data — from which follows whether it mounts at all
|
|
65301
|
+
// (filtered out), whether it shows (hidden keeps the room, not the
|
|
65302
|
+
// content), and whether it is an item (a group wrapper, a skeleton, are
|
|
65303
|
+
// rows of the list but items of nobody). Said in the name of the
|
|
65304
|
+
// component, not of the item id: two components may stand for one item for
|
|
65305
|
+
// a moment, one leaving as the other arrives.
|
|
65306
|
+
draw: (rowId, { ownerId, place, groupId, data }) => {
|
|
65307
|
+
const mounted = !data.filtered;
|
|
65308
|
+
const visible = mounted && !data.hidden;
|
|
65309
|
+
const item = !data.skeleton && data.role !== "presentation";
|
|
65310
|
+
let row = rowById.get(rowId);
|
|
65311
|
+
if (row) {
|
|
65312
|
+
if (
|
|
65313
|
+
row.mounted &&
|
|
65314
|
+
(row.place !== place || row.groupId !== groupId || !mounted)
|
|
65315
|
+
) {
|
|
65316
|
+
leaveFirst(row);
|
|
65317
|
+
}
|
|
65318
|
+
row.ownerId = ownerId;
|
|
65319
|
+
row.place = place;
|
|
65320
|
+
row.groupId = groupId;
|
|
65321
|
+
row.data = data;
|
|
65322
|
+
row.mounted = mounted;
|
|
65323
|
+
row.visible = visible;
|
|
65324
|
+
row.item = item;
|
|
65325
|
+
} else {
|
|
65326
|
+
row = { ownerId, place, groupId, data, mounted, visible, item };
|
|
65327
|
+
rowById.set(rowId, row);
|
|
65328
|
+
}
|
|
65329
|
+
if (mounted) {
|
|
65330
|
+
const firstSignal = firstSignalOf(scopeOf(groupId));
|
|
65331
|
+
const first = firstSignal.peek();
|
|
65332
|
+
if (first === -1 || place < first) {
|
|
65333
|
+
firstSignal.value = place;
|
|
65334
|
+
}
|
|
65335
|
+
}
|
|
65336
|
+
notify();
|
|
65337
|
+
},
|
|
65338
|
+
// The row is gone. A declared row is its own owner and gives its place
|
|
65339
|
+
// back with it; a run's row leaves the run's places alone.
|
|
65340
|
+
erase: (rowId) => {
|
|
65341
|
+
const row = rowById.get(rowId);
|
|
65342
|
+
if (!row) {
|
|
65343
|
+
return;
|
|
65344
|
+
}
|
|
65345
|
+
rowById.delete(rowId);
|
|
65346
|
+
if (row.mounted) {
|
|
65347
|
+
leaveFirst(row);
|
|
65348
|
+
}
|
|
65349
|
+
if (row.ownerId === rowId) {
|
|
65350
|
+
listRows.drop(rowId);
|
|
65351
|
+
}
|
|
65352
|
+
notify();
|
|
65353
|
+
},
|
|
65354
|
+
// Whether nothing of the list stands above this row: in its group, no
|
|
65355
|
+
// other row of the group mounts before it; outside groups, no row mounts
|
|
65356
|
+
// before it and no run has rows above its window before it. Answered from
|
|
65357
|
+
// a signal, so a row rendered from a kept vnode is rendered again when the
|
|
65358
|
+
// row before it leaves or comes back.
|
|
65359
|
+
isFirst: (rowId) => {
|
|
65360
|
+
const row = rowById.get(rowId);
|
|
65361
|
+
const scope = scopeOf(row.groupId);
|
|
65362
|
+
if (staleScopes.has(scope)) {
|
|
65363
|
+
refreshFirst(scope);
|
|
65364
|
+
}
|
|
65365
|
+
return firstSignalOf(scope).value === row.place;
|
|
65366
|
+
},
|
|
65367
|
+
// What a group knows about its rows: how many, and how many of them the
|
|
65368
|
+
// search left out (see ListItemGroup).
|
|
65369
|
+
group: (groupId) => groupOf(groupId),
|
|
65370
|
+
dropGroup: (groupId) => {
|
|
65371
|
+
groupById.delete(groupId);
|
|
65372
|
+
staleScopes.delete(groupId);
|
|
65373
|
+
},
|
|
65374
|
+
// Written when a frame's rows have settled (see notify); the value to act
|
|
65375
|
+
// on is peeked from wherever the change is heard.
|
|
65376
|
+
flushSync: () => {
|
|
65377
|
+
if (!notifyScheduled) {
|
|
65378
|
+
return;
|
|
65379
|
+
}
|
|
65380
|
+
notifyScheduled = false;
|
|
65381
|
+
runNotify();
|
|
65382
|
+
},
|
|
65145
65383
|
};
|
|
65384
|
+
return listRows;
|
|
65146
65385
|
};
|
|
65147
|
-
|
|
65148
|
-
|
|
65149
|
-
|
|
65150
|
-
if (props.header) {
|
|
65151
|
-
return renderResolver(ListItemHeader, props);
|
|
65386
|
+
const sameSlotIds = (left, right) => {
|
|
65387
|
+
if (left.length !== right.length) {
|
|
65388
|
+
return false;
|
|
65152
65389
|
}
|
|
65153
|
-
|
|
65154
|
-
|
|
65390
|
+
let index = 0;
|
|
65391
|
+
while (index < left.length) {
|
|
65392
|
+
if (left[index] !== right[index]) {
|
|
65393
|
+
return false;
|
|
65394
|
+
}
|
|
65395
|
+
index++;
|
|
65155
65396
|
}
|
|
65156
|
-
return
|
|
65157
|
-
...props
|
|
65158
|
-
});
|
|
65397
|
+
return true;
|
|
65159
65398
|
};
|
|
65160
|
-
|
|
65161
|
-
|
|
65162
|
-
|
|
65163
|
-
|
|
65164
|
-
|
|
65165
|
-
|
|
65166
|
-
|
|
65167
|
-
|
|
65168
|
-
|
|
65169
|
-
|
|
65170
|
-
}, []);
|
|
65171
|
-
return jsx(Next, {
|
|
65172
|
-
...props,
|
|
65173
|
-
header: undefined,
|
|
65174
|
-
role: "presentation",
|
|
65175
|
-
baseClassName: "navi_list_item_header"
|
|
65176
|
-
});
|
|
65177
|
-
};
|
|
65178
|
-
const ListItemFooter = props => {
|
|
65179
|
-
const Next = useNextResolver();
|
|
65180
|
-
const {
|
|
65181
|
-
ref
|
|
65182
|
-
} = props;
|
|
65183
|
-
useDisplayedLayoutEffect(ref, footerEl => {
|
|
65184
|
-
const listContainerEl = footerEl.closest(".navi_list_container");
|
|
65185
|
-
const rect = footerEl.getBoundingClientRect();
|
|
65186
|
-
listContainerEl.style.setProperty("--list-footer-height", `${rect.height}px`);
|
|
65187
|
-
listContainerEl.style.setProperty("--list-footer-width", `${rect.width}px`);
|
|
65188
|
-
}, []);
|
|
65189
|
-
return jsx(Next, {
|
|
65190
|
-
...props,
|
|
65191
|
-
footer: undefined,
|
|
65192
|
-
role: "presentation",
|
|
65193
|
-
baseClassName: "navi_list_item_footer"
|
|
65194
|
-
});
|
|
65399
|
+
|
|
65400
|
+
// Rows in place order; a row with no place (a declared row filtered out) last.
|
|
65401
|
+
const compareRowPlaces = (left, right) => {
|
|
65402
|
+
if (left.place === undefined) {
|
|
65403
|
+
return right.place === undefined ? 0 : 1;
|
|
65404
|
+
}
|
|
65405
|
+
if (right.place === undefined) {
|
|
65406
|
+
return -1;
|
|
65407
|
+
}
|
|
65408
|
+
return left.place - right.place;
|
|
65195
65409
|
};
|
|
65196
65410
|
|
|
65197
65411
|
// What a row may say it is waiting on, all of them about the row as a thing
|
|
@@ -65999,8 +66213,10 @@ const applySearchHighlight = (el, highlight) => {
|
|
|
65999
66213
|
};
|
|
66000
66214
|
|
|
66001
66215
|
installImportMetaCssBuild(import.meta);
|
|
66002
|
-
const
|
|
66003
|
-
|
|
66216
|
+
const ListRowsContext = createContext(null);
|
|
66217
|
+
// The group a row is declared in, by id (see ListItemGroup): what its count
|
|
66218
|
+
// and its separator are scoped to.
|
|
66219
|
+
const ListGroupContext = createContext(undefined);
|
|
66004
66220
|
const PendingScrollRefContext = createContext(null);
|
|
66005
66221
|
// Controls how List.Item behaves when match=false (set via List searchNoMatchMode prop):
|
|
66006
66222
|
// "remove" — remove from DOM (default)
|
|
@@ -66039,21 +66255,15 @@ const SeparatorContext = createContext(null);
|
|
|
66039
66255
|
// Set by <List itemTransition>: each row then gets a view-transition-name of
|
|
66040
66256
|
// its own, so a change wrapped in a view transition animates row by row.
|
|
66041
66257
|
const ItemTransitionContext = createContext(false);
|
|
66042
|
-
// What the list knows about the collection as a whole: how many rows it has,
|
|
66043
|
-
// which of them it actually holds, and where each child's rows start. Filled in
|
|
66044
|
-
// by the children as they render (see createListVirtual), read by everything
|
|
66045
|
-
// that must reserve room for what is not rendered.
|
|
66046
|
-
const ListVirtualContext = createContext(null);
|
|
66047
66258
|
// Set around each row a run of items renders (see ListItems): which row of the
|
|
66048
|
-
// collection it is, where it stands among the rows the list holds, and
|
|
66049
|
-
// run
|
|
66050
|
-
//
|
|
66051
|
-
//
|
|
66052
|
-
// own — instead of a bare <List.Item> — works the same way.
|
|
66259
|
+
// collection it is, where it stands among the rows the list holds, and which
|
|
66260
|
+
// run it belongs to. Carried by context rather than injected into whatever
|
|
66261
|
+
// vnode renderItem returned, so that returning a component of one's own —
|
|
66262
|
+
// instead of a bare <List.Item> — works the same way.
|
|
66053
66263
|
const ListRowContext = createContext(null);
|
|
66054
66264
|
// The slot a child of the list stands in, by id (see ListDeclaredChildren). A
|
|
66055
66265
|
// row takes its place in the collection by slot: the place is then the list's
|
|
66056
|
-
// to move, and the row's to follow — see
|
|
66266
|
+
// to move, and the row's to follow — see list_rows.js.
|
|
66057
66267
|
const ListSlotContext = createContext(null);
|
|
66058
66268
|
const css$x = /* css */`@layer navi {
|
|
66059
66269
|
.navi_list_container {
|
|
@@ -66544,7 +66754,7 @@ const ListUI = props => {
|
|
|
66544
66754
|
overflow,
|
|
66545
66755
|
overflowX,
|
|
66546
66756
|
overflowY,
|
|
66547
|
-
|
|
66757
|
+
listRows,
|
|
66548
66758
|
...rest
|
|
66549
66759
|
} = props;
|
|
66550
66760
|
const scrollBoxPaddingProps = {};
|
|
@@ -66613,16 +66823,19 @@ const ListUI = props => {
|
|
|
66613
66823
|
observer.disconnect();
|
|
66614
66824
|
};
|
|
66615
66825
|
}, [lockSize]);
|
|
66616
|
-
|
|
66617
|
-
|
|
66618
|
-
|
|
66619
|
-
|
|
66826
|
+
listRows.onChange = () => {
|
|
66827
|
+
onListVisibleItemsChange?.(listRows.visibleItemsSignal.peek());
|
|
66828
|
+
};
|
|
66829
|
+
// Code in a layout effect of the list reads the rows as they stand after
|
|
66830
|
+
// the commit; the rows settle on a microtask, which preact does not wait for.
|
|
66831
|
+
useLayoutEffect(() => {
|
|
66832
|
+
listRows.flushSync();
|
|
66620
66833
|
});
|
|
66621
66834
|
// What the runs ask for and stand for: the steady budget, whatever the
|
|
66622
66835
|
// window of the first paint draws — a run asking for the rows of the first
|
|
66623
66836
|
// picture and then for the rest is two round trips for one opening.
|
|
66624
|
-
|
|
66625
|
-
|
|
66837
|
+
listRows.renderBudget = renderBudgetAfterPaint;
|
|
66838
|
+
listRows.scrolled = scrolled ?? defaultScrolled;
|
|
66626
66839
|
const {
|
|
66627
66840
|
virtualItemSizeSignal,
|
|
66628
66841
|
renderWindow,
|
|
@@ -66631,11 +66844,10 @@ const ListUI = props => {
|
|
|
66631
66844
|
captureAnchor
|
|
66632
66845
|
} = useListScrollSync({
|
|
66633
66846
|
ref,
|
|
66634
|
-
|
|
66847
|
+
listRows,
|
|
66635
66848
|
renderBudget,
|
|
66636
66849
|
renderBudgetSteady: renderBudgetAfterPaint,
|
|
66637
66850
|
virtualItemSize,
|
|
66638
|
-
virtual,
|
|
66639
66851
|
scrolled,
|
|
66640
66852
|
defaultScrolled,
|
|
66641
66853
|
onScrolledChange,
|
|
@@ -66654,28 +66866,28 @@ const ListUI = props => {
|
|
|
66654
66866
|
if (props.renderBudget === undefined || renderBudgetWarnedRef.current) {
|
|
66655
66867
|
return;
|
|
66656
66868
|
}
|
|
66657
|
-
if (
|
|
66869
|
+
if (listRows.hasRuns() || listRows.itemsSignal.peek().length === 0) {
|
|
66658
66870
|
return;
|
|
66659
66871
|
}
|
|
66660
66872
|
renderBudgetWarnedRef.current = true;
|
|
66661
66873
|
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.`);
|
|
66662
66874
|
});
|
|
66663
|
-
|
|
66664
|
-
|
|
66665
|
-
|
|
66666
|
-
|
|
66875
|
+
listRows.captureAnchor = captureAnchor;
|
|
66876
|
+
listRows.virtualItemSizeSignal = virtualItemSizeSignal;
|
|
66877
|
+
listRows.horizontal = Boolean(horizontal);
|
|
66878
|
+
listRows.renderSkeleton = renderSkeleton;
|
|
66667
66879
|
|
|
66668
66880
|
// A row is addressed by id from outside (--navi-scroll, --navi-select): the
|
|
66669
|
-
// ones drawn have
|
|
66881
|
+
// ones drawn have said so (see list_rows.js), and the ones a run
|
|
66670
66882
|
// holds without drawing are known only to that run (see List.Items' row
|
|
66671
66883
|
// locator). Both answer here, so a row is reachable whether or not the
|
|
66672
66884
|
// window happens to frame it.
|
|
66673
66885
|
const getItemById = itemId => {
|
|
66674
|
-
const itemDrawn =
|
|
66886
|
+
const itemDrawn = listRows.itemsSignal.peek().find(item => item.id === itemId);
|
|
66675
66887
|
if (itemDrawn) {
|
|
66676
66888
|
return itemDrawn;
|
|
66677
66889
|
}
|
|
66678
|
-
const rowIndex =
|
|
66890
|
+
const rowIndex = listRows.locateRow(itemId);
|
|
66679
66891
|
if (rowIndex === null) {
|
|
66680
66892
|
return undefined;
|
|
66681
66893
|
}
|
|
@@ -66684,13 +66896,13 @@ const ListUI = props => {
|
|
|
66684
66896
|
index: rowIndex
|
|
66685
66897
|
};
|
|
66686
66898
|
};
|
|
66687
|
-
const noMatchCount =
|
|
66899
|
+
const noMatchCount = listRows.noMatchCountSignal.value;
|
|
66688
66900
|
// What the list stands for, which is not always what it holds: a run saying
|
|
66689
66901
|
// it covers 60 rows is not an empty list while it waits for the first of
|
|
66690
66902
|
// them (see List.Items).
|
|
66691
66903
|
// eslint-disable-next-line no-unused-expressions
|
|
66692
|
-
|
|
66693
|
-
const itemCount =
|
|
66904
|
+
listRows.pagesSignal.value;
|
|
66905
|
+
const itemCount = listRows.countSignal.value || listRows.totalSignal.value;
|
|
66694
66906
|
const allNoMatch = noMatchCount > 0 && noMatchCount === itemCount;
|
|
66695
66907
|
const searching = Boolean(searchText);
|
|
66696
66908
|
const fallbackDisabled = fallback !== undefined && !fallback;
|
|
@@ -66788,7 +67000,7 @@ const ListUI = props => {
|
|
|
66788
67000
|
expand: expand,
|
|
66789
67001
|
"navi-nothing-to-display": nothingToDisplay ? "" : undefined,
|
|
66790
67002
|
"navi-loading": loading ? "" : undefined,
|
|
66791
|
-
"navi-refreshing":
|
|
67003
|
+
"navi-refreshing": listRows.refreshingSignal.value ? "" : undefined,
|
|
66792
67004
|
"navi-error": error ? "" : undefined,
|
|
66793
67005
|
styleCSSVars: LIST_STYLE_CSS_VARS,
|
|
66794
67006
|
pseudoClasses: LIST_PSEUDO_CLASSES,
|
|
@@ -66824,9 +67036,8 @@ const ListUI = props => {
|
|
|
66824
67036
|
spacing: spacing,
|
|
66825
67037
|
columns: columns,
|
|
66826
67038
|
itemColumns: itemColumns,
|
|
66827
|
-
|
|
67039
|
+
listRows: listRows,
|
|
66828
67040
|
renderWindow: renderWindow,
|
|
66829
|
-
virtual: virtual,
|
|
66830
67041
|
pendingScrollRef: pendingScrollRef,
|
|
66831
67042
|
overflow: overflow,
|
|
66832
67043
|
overflowX: overflowX,
|
|
@@ -66847,11 +67058,11 @@ const ListFirstResolver = props => {
|
|
|
66847
67058
|
props.ref = props.ref || refDefault;
|
|
66848
67059
|
const idDefault = useId();
|
|
66849
67060
|
props.id = props.id || idDefault;
|
|
66850
|
-
const
|
|
66851
|
-
if (!
|
|
66852
|
-
|
|
67061
|
+
const listRowsRef = useRef(null);
|
|
67062
|
+
if (!listRowsRef.current) {
|
|
67063
|
+
listRowsRef.current = createListRows();
|
|
66853
67064
|
}
|
|
66854
|
-
props.
|
|
67065
|
+
props.listRows = listRowsRef.current;
|
|
66855
67066
|
const parallelGuard = useParallelGuard(props.parallelGuard ?? PARALLEL_GUARD_DEFAULT);
|
|
66856
67067
|
return jsx(ParallelGuardContext.Provider, {
|
|
66857
67068
|
value: parallelGuard,
|
|
@@ -66877,9 +67088,8 @@ const ListContent = ({
|
|
|
66877
67088
|
spacing,
|
|
66878
67089
|
columns,
|
|
66879
67090
|
itemColumns,
|
|
66880
|
-
|
|
67091
|
+
listRows,
|
|
66881
67092
|
renderWindow,
|
|
66882
|
-
virtual,
|
|
66883
67093
|
pendingScrollRef,
|
|
66884
67094
|
overflow,
|
|
66885
67095
|
overflowX,
|
|
@@ -66933,9 +67143,8 @@ const ListContent = ({
|
|
|
66933
67143
|
columns: columns,
|
|
66934
67144
|
itemColumns: itemColumns,
|
|
66935
67145
|
...listProps,
|
|
66936
|
-
|
|
67146
|
+
listRows: listRows,
|
|
66937
67147
|
renderWindow: renderWindow,
|
|
66938
|
-
virtual: virtual,
|
|
66939
67148
|
children: children
|
|
66940
67149
|
})
|
|
66941
67150
|
})
|
|
@@ -66959,11 +67168,10 @@ const LIST_STYLE_CSS_VARS = {
|
|
|
66959
67168
|
const LIST_PSEUDO_CLASSES = [":hover", ":focus", ":focus-visible", ":focus-within", ":read-only", ":disabled", ":-navi-void", ":-navi-expanded"];
|
|
66960
67169
|
const useListScrollSync = ({
|
|
66961
67170
|
ref,
|
|
66962
|
-
|
|
67171
|
+
listRows,
|
|
66963
67172
|
renderBudget,
|
|
66964
67173
|
renderBudgetSteady,
|
|
66965
67174
|
virtualItemSize,
|
|
66966
|
-
virtual,
|
|
66967
67175
|
scrolled,
|
|
66968
67176
|
defaultScrolled,
|
|
66969
67177
|
onScrolledChange,
|
|
@@ -66973,7 +67181,7 @@ const useListScrollSync = ({
|
|
|
66973
67181
|
}) => {
|
|
66974
67182
|
const debugScroll = useDebugScroll();
|
|
66975
67183
|
const virtualItemSizeSignal = useVirtualItemSizeSignal(ref, virtualItemSize, horizontal, {
|
|
66976
|
-
|
|
67184
|
+
listRows,
|
|
66977
67185
|
renderBudget,
|
|
66978
67186
|
scrolledWanted: scrolled ?? defaultScrolled
|
|
66979
67187
|
});
|
|
@@ -66998,7 +67206,7 @@ const useListScrollSync = ({
|
|
|
66998
67206
|
ref,
|
|
66999
67207
|
scrollerElResolved,
|
|
67000
67208
|
renderBudget,
|
|
67001
|
-
totalSignal:
|
|
67209
|
+
totalSignal: listRows.totalSignal,
|
|
67002
67210
|
virtualItemSizeSignal,
|
|
67003
67211
|
horizontal
|
|
67004
67212
|
});
|
|
@@ -67023,7 +67231,7 @@ const useListScrollSync = ({
|
|
|
67023
67231
|
anchorRef.current = captureScrollAnchor({
|
|
67024
67232
|
scrollerEl: getScroller(),
|
|
67025
67233
|
listEl: getListEl(),
|
|
67026
|
-
items:
|
|
67234
|
+
items: listRows.visibleItemsSignal.peek(),
|
|
67027
67235
|
horizontal
|
|
67028
67236
|
});
|
|
67029
67237
|
};
|
|
@@ -67055,7 +67263,7 @@ const useListScrollSync = ({
|
|
|
67055
67263
|
start,
|
|
67056
67264
|
end
|
|
67057
67265
|
} = renderWindowRef.current;
|
|
67058
|
-
const total =
|
|
67266
|
+
const total = listRows.totalSignal.peek();
|
|
67059
67267
|
let framedStart = start;
|
|
67060
67268
|
let framedEnd = start + renderBudget;
|
|
67061
67269
|
if (total > 0 && framedEnd > total) {
|
|
@@ -67098,19 +67306,19 @@ const useListScrollSync = ({
|
|
|
67098
67306
|
// jumped.
|
|
67099
67307
|
const holdWindow = () => {
|
|
67100
67308
|
if (startPlaceRef.current.userTookOver) {
|
|
67101
|
-
|
|
67309
|
+
listRows.holdPending = false;
|
|
67102
67310
|
return;
|
|
67103
67311
|
}
|
|
67104
67312
|
// Held somewhere it has not reached yet: what the window frames right now
|
|
67105
67313
|
// is not what it will frame, so nothing should be fetched for it.
|
|
67106
|
-
|
|
67107
|
-
const total =
|
|
67314
|
+
listRows.holdPending = scrolledWanted !== "start" && scrolledWanted !== undefined;
|
|
67315
|
+
const total = listRows.totalSignal.peek();
|
|
67108
67316
|
if (total <= renderBudget) {
|
|
67109
67317
|
// The whole collection is what the list draws: wherever in it the list is
|
|
67110
67318
|
// held, the window is already its place. Nowhere to move to means nothing
|
|
67111
67319
|
// to wait for — a hold left standing here is a list that never asks for
|
|
67112
67320
|
// anything again.
|
|
67113
|
-
|
|
67321
|
+
listRows.holdPending = false;
|
|
67114
67322
|
return;
|
|
67115
67323
|
}
|
|
67116
67324
|
const half = Math.floor(renderBudget / 2);
|
|
@@ -67120,7 +67328,7 @@ const useListScrollSync = ({
|
|
|
67120
67328
|
} else if (typeof scrolledWanted === "number") {
|
|
67121
67329
|
wantedStart = scrolledWanted - half;
|
|
67122
67330
|
} else if (scrolledWanted && scrolledWanted.id !== undefined) {
|
|
67123
|
-
const rowIndex =
|
|
67331
|
+
const rowIndex = listRows.locateRow(scrolledWanted.id);
|
|
67124
67332
|
if (rowIndex !== null) {
|
|
67125
67333
|
wantedStart = rowIndex - half;
|
|
67126
67334
|
} else if (typeof scrolledWanted.index === "number") {
|
|
@@ -67147,14 +67355,14 @@ const useListScrollSync = ({
|
|
|
67147
67355
|
end
|
|
67148
67356
|
} = renderWindowRef.current;
|
|
67149
67357
|
if (wantedStart === start && end - start === renderBudget) {
|
|
67150
|
-
|
|
67358
|
+
listRows.holdPending = false;
|
|
67151
67359
|
return;
|
|
67152
67360
|
}
|
|
67153
67361
|
renderWindowRef.current = {
|
|
67154
67362
|
start: wantedStart,
|
|
67155
67363
|
end: wantedStart + renderBudget
|
|
67156
67364
|
};
|
|
67157
|
-
|
|
67365
|
+
listRows.holdPending = false;
|
|
67158
67366
|
};
|
|
67159
67367
|
const pendingScrollRef = useRef();
|
|
67160
67368
|
const scrollToItem = (item, {
|
|
@@ -67165,7 +67373,7 @@ const useListScrollSync = ({
|
|
|
67165
67373
|
if (!item) {
|
|
67166
67374
|
return;
|
|
67167
67375
|
}
|
|
67168
|
-
const items =
|
|
67376
|
+
const items = listRows.itemsSignal.peek();
|
|
67169
67377
|
const itemCount = items.length;
|
|
67170
67378
|
if (itemCount === 0) {
|
|
67171
67379
|
return;
|
|
@@ -67293,7 +67501,7 @@ const useListScrollSync = ({
|
|
|
67293
67501
|
return;
|
|
67294
67502
|
}
|
|
67295
67503
|
hasBeenDisplayedRef.current = true;
|
|
67296
|
-
const items =
|
|
67504
|
+
const items = listRows.itemsSignal.peek();
|
|
67297
67505
|
const firstSelected = items.find(i => {
|
|
67298
67506
|
if (i.selected) {
|
|
67299
67507
|
return true;
|
|
@@ -67377,7 +67585,7 @@ const useListScrollSync = ({
|
|
|
67377
67585
|
scrollValues: savedScroll,
|
|
67378
67586
|
scrollerEl: listScrollContainerEl,
|
|
67379
67587
|
listEl: getListEl(),
|
|
67380
|
-
|
|
67588
|
+
listRows,
|
|
67381
67589
|
virtualItemSizeSignal,
|
|
67382
67590
|
renderWindowRef,
|
|
67383
67591
|
horizontal
|
|
@@ -67394,7 +67602,7 @@ const useListScrollSync = ({
|
|
|
67394
67602
|
});
|
|
67395
67603
|
return undefined;
|
|
67396
67604
|
}
|
|
67397
|
-
const visibleItems =
|
|
67605
|
+
const visibleItems = listRows.visibleItemsSignal.peek();
|
|
67398
67606
|
const topItems = visibleItems.slice(0, renderBudget);
|
|
67399
67607
|
const topMatchScoresKey = topItems.map(i => `${i.id}:${i.matchInfo?.matchScore ?? ""}`).join(",");
|
|
67400
67608
|
const currentTopMatchScore = topMatchScoresKeyRef.current;
|
|
@@ -67432,7 +67640,7 @@ const useListScrollSync = ({
|
|
|
67432
67640
|
if (scrolledWanted === "start" || scrolledWanted === undefined || startPlaceRef.current.userTookOver || !ref.current) {
|
|
67433
67641
|
return;
|
|
67434
67642
|
}
|
|
67435
|
-
if (
|
|
67643
|
+
if (listRows.totalSignal.peek() === 0 || virtualItemSizeSignal.peek() === 0) {
|
|
67436
67644
|
return;
|
|
67437
67645
|
}
|
|
67438
67646
|
// Coming back to a named row: it has to be on screen to be put back where
|
|
@@ -67444,13 +67652,13 @@ const useListScrollSync = ({
|
|
|
67444
67652
|
// Only whoever holds the rows can say where that one sits: the list
|
|
67445
67653
|
// itself knows the rows it has drawn, and this one is precisely the one
|
|
67446
67654
|
// it has not drawn yet.
|
|
67447
|
-
const rowIndex =
|
|
67655
|
+
const rowIndex = listRows.locateRow(scrolledWanted.id);
|
|
67448
67656
|
if (rowIndex === null) {
|
|
67449
67657
|
// Not there yet. Where it stood is enough to be roughly right in the
|
|
67450
67658
|
// meantime — the scrollbar lands near its final place instead of at the
|
|
67451
67659
|
// top, and the exact position is taken once the row itself can be
|
|
67452
67660
|
// measured.
|
|
67453
|
-
if (
|
|
67661
|
+
if (listRows.pagesSignal.peek() === 0) {
|
|
67454
67662
|
if (typeof scrolledWanted.index === "number") {
|
|
67455
67663
|
const rowPosition = scrolledWanted.index * virtualItemSizeSignal.peek();
|
|
67456
67664
|
anchorRef.current = null;
|
|
@@ -67567,7 +67775,7 @@ const useListScrollSync = ({
|
|
|
67567
67775
|
const position = captureScrollAnchor({
|
|
67568
67776
|
scrollerEl: getScroller(),
|
|
67569
67777
|
listEl: getListEl(),
|
|
67570
|
-
items:
|
|
67778
|
+
items: listRows.visibleItemsSignal.peek(),
|
|
67571
67779
|
horizontal
|
|
67572
67780
|
});
|
|
67573
67781
|
if (!position) {
|
|
@@ -67655,7 +67863,7 @@ const useListScrollSync = ({
|
|
|
67655
67863
|
anchorRef.current = null;
|
|
67656
67864
|
return;
|
|
67657
67865
|
}
|
|
67658
|
-
const items =
|
|
67866
|
+
const items = listRows.visibleItemsSignal.peek();
|
|
67659
67867
|
const itemNow = items.find(i => i.id === anchor.id);
|
|
67660
67868
|
if (!itemNow) {
|
|
67661
67869
|
anchorRef.current = null;
|
|
@@ -67677,7 +67885,7 @@ const useListScrollSync = ({
|
|
|
67677
67885
|
const windowSize = end - start;
|
|
67678
67886
|
const startShifted = start + indexShift;
|
|
67679
67887
|
let startWanted = startShifted < 0 ? 0 : startShifted;
|
|
67680
|
-
const total =
|
|
67888
|
+
const total = listRows.totalSignal.peek();
|
|
67681
67889
|
// Same normalization as the scroll listener: a window running past the
|
|
67682
67890
|
// last row slides back instead of framing fewer rows than its budget
|
|
67683
67891
|
// allows — every row that fits in it must stay rendered.
|
|
@@ -67735,7 +67943,7 @@ const useListScrollSync = ({
|
|
|
67735
67943
|
const windowSlidRef = useRef(false);
|
|
67736
67944
|
useRef(false);
|
|
67737
67945
|
const evaluateWindow = reason => {
|
|
67738
|
-
const total =
|
|
67946
|
+
const total = listRows.totalSignal.peek();
|
|
67739
67947
|
if (total <= renderBudget) {
|
|
67740
67948
|
return;
|
|
67741
67949
|
}
|
|
@@ -67757,7 +67965,7 @@ const useListScrollSync = ({
|
|
|
67757
67965
|
},
|
|
67758
67966
|
scrollerEl,
|
|
67759
67967
|
listEl,
|
|
67760
|
-
|
|
67968
|
+
listRows,
|
|
67761
67969
|
virtualItemSizeSignal,
|
|
67762
67970
|
renderWindowRef,
|
|
67763
67971
|
horizontal
|
|
@@ -68356,12 +68564,12 @@ const getScrollInfo = ({
|
|
|
68356
68564
|
scrollValues,
|
|
68357
68565
|
scrollerEl,
|
|
68358
68566
|
listEl,
|
|
68359
|
-
|
|
68567
|
+
listRows,
|
|
68360
68568
|
virtualItemSizeSignal,
|
|
68361
68569
|
renderWindowRef,
|
|
68362
68570
|
horizontal
|
|
68363
68571
|
}) => {
|
|
68364
|
-
const items =
|
|
68572
|
+
const items = listRows.itemsSignal.peek();
|
|
68365
68573
|
const viewportRect = getScrollerViewportRect(scrollerEl);
|
|
68366
68574
|
const listRect = listEl.getBoundingClientRect();
|
|
68367
68575
|
let hitEl = null;
|
|
@@ -68486,7 +68694,7 @@ const measureItemSize = (listEl, horizontal) => {
|
|
|
68486
68694
|
};
|
|
68487
68695
|
};
|
|
68488
68696
|
const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
68489
|
-
|
|
68697
|
+
listRows,
|
|
68490
68698
|
renderBudget,
|
|
68491
68699
|
scrolledWanted
|
|
68492
68700
|
}) => {
|
|
@@ -68546,7 +68754,7 @@ const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
|
68546
68754
|
// size is for, and a list drawing every row it has would pay a layout on
|
|
68547
68755
|
// each of its renders for a number nothing reads.
|
|
68548
68756
|
const sizeAlreadyKnown = virtualSizeSignal.peek() !== 0;
|
|
68549
|
-
const rowsHeldOffScreen =
|
|
68757
|
+
const rowsHeldOffScreen = listRows.totalSignal.peek() > renderBudget;
|
|
68550
68758
|
if (!virtualItemSizeProp && sizeAlreadyKnown && rowsHeldOffScreen && ref.current) {
|
|
68551
68759
|
const listEl = ref.current.querySelector(".navi_list");
|
|
68552
68760
|
const measure = listEl ? measureItemSize(listEl, horizontal) : null;
|
|
@@ -68562,7 +68770,7 @@ const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
|
68562
68770
|
// screen, and a list held somewhere (placeWhereHeld) before it knows where
|
|
68563
68771
|
// that is. A list drawing every row it has, opening at its start, would
|
|
68564
68772
|
// pay a layout in every commit for a number nobody reads.
|
|
68565
|
-
const sizeRead =
|
|
68773
|
+
const sizeRead = listRows.totalSignal.peek() > renderBudget || scrolledWanted !== undefined && scrolledWanted !== "start";
|
|
68566
68774
|
if (!sizeRead) {
|
|
68567
68775
|
return undefined;
|
|
68568
68776
|
}
|
|
@@ -68614,9 +68822,8 @@ const useVirtualItemSizeSignal = (ref, virtualItemSizeProp = 0, horizontal, {
|
|
|
68614
68822
|
// item after each commit and writes to the signal, causing only the fillers to
|
|
68615
68823
|
// re-render.
|
|
68616
68824
|
const UnorderedList = ({
|
|
68617
|
-
|
|
68825
|
+
listRows,
|
|
68618
68826
|
renderWindow,
|
|
68619
|
-
virtual,
|
|
68620
68827
|
fallback,
|
|
68621
68828
|
fallbackShown,
|
|
68622
68829
|
searchFallback,
|
|
@@ -68666,17 +68873,14 @@ const UnorderedList = ({
|
|
|
68666
68873
|
value: separator ?? null,
|
|
68667
68874
|
children: jsx(ItemTransitionContext.Provider, {
|
|
68668
68875
|
value: Boolean(itemTransition),
|
|
68669
|
-
children: jsx(
|
|
68670
|
-
value:
|
|
68671
|
-
children: jsx(
|
|
68672
|
-
value:
|
|
68673
|
-
children: jsx(
|
|
68674
|
-
value: null,
|
|
68675
|
-
children: jsx(
|
|
68676
|
-
|
|
68677
|
-
children: jsx(ListDeclaredChildren, {
|
|
68678
|
-
children: children
|
|
68679
|
-
})
|
|
68876
|
+
children: jsx(ListRowsContext.Provider, {
|
|
68877
|
+
value: listRows,
|
|
68878
|
+
children: jsx(ListRowContext.Provider, {
|
|
68879
|
+
value: null,
|
|
68880
|
+
children: jsx(ListItemColumnsContext.Provider, {
|
|
68881
|
+
value: columns ? null : itemColumns || null,
|
|
68882
|
+
children: jsx(ListDeclaredChildren, {
|
|
68883
|
+
children: children
|
|
68680
68884
|
})
|
|
68681
68885
|
})
|
|
68682
68886
|
})
|
|
@@ -68727,8 +68931,8 @@ const VirtualFiller = ({
|
|
|
68727
68931
|
edge,
|
|
68728
68932
|
itemCount
|
|
68729
68933
|
}) => {
|
|
68730
|
-
const
|
|
68731
|
-
const sizeToFill = itemCount *
|
|
68934
|
+
const listRows = useContext(ListRowsContext);
|
|
68935
|
+
const sizeToFill = itemCount * listRows.virtualItemSizeSignal.value;
|
|
68732
68936
|
if (!sizeToFill) {
|
|
68733
68937
|
return null;
|
|
68734
68938
|
}
|
|
@@ -68871,12 +69075,11 @@ const ListItemUI = props => {
|
|
|
68871
69075
|
}
|
|
68872
69076
|
const idDefault = useId();
|
|
68873
69077
|
props.id = props.id || idDefault;
|
|
68874
|
-
const
|
|
68875
|
-
const
|
|
69078
|
+
const listRows = useContext(ListRowsContext);
|
|
69079
|
+
const groupId = useContext(ListGroupContext);
|
|
68876
69080
|
const searchNoMatchMode = useContext(SearchNoMatchModeContext);
|
|
68877
69081
|
// The run this row belongs to, when it comes from one (see ListItems): it
|
|
68878
|
-
//
|
|
68879
|
-
// the row mounts is decided here, and told back to the run.
|
|
69082
|
+
// gave the row its place and decided it is inside the render window.
|
|
68880
69083
|
const row = useContext(ListRowContext);
|
|
68881
69084
|
const slotId = useContext(ListSlotContext);
|
|
68882
69085
|
// There is no standalone match/matchScore/highlight prop — participation
|
|
@@ -68884,7 +69087,7 @@ const ListItemUI = props => {
|
|
|
68884
69087
|
// (e.g. useSearchText's getItemMatchInfo(item): { match, matchScore,
|
|
68885
69088
|
// matchRanges }), so there is exactly one way to wire it up.
|
|
68886
69089
|
const matchInfo = props.matchInfo;
|
|
68887
|
-
// Expose match on the
|
|
69090
|
+
// Expose match on the row: the list counts non-matching rows via
|
|
68888
69091
|
// `item.match === false` (drives noMatchCount → allNoMatch → the searchFallback
|
|
68889
69092
|
// / hide-when-empty behavior). Without this a matchInfo-based search would
|
|
68890
69093
|
// filter items out but never register them as "no match".
|
|
@@ -68908,33 +69111,27 @@ const ListItemUI = props => {
|
|
|
68908
69111
|
// name of this very component (idDefault, not the row's id): two components
|
|
68909
69112
|
// may stand for the same row for a moment, one leaving as the other arrives,
|
|
68910
69113
|
// and the one leaving must give back its own place, not the newcomer's.
|
|
68911
|
-
if (row) {
|
|
69114
|
+
if (!row) {
|
|
68912
69115
|
if (props.filtered) {
|
|
68913
|
-
|
|
69116
|
+
listRows.drop(idDefault);
|
|
68914
69117
|
} else {
|
|
68915
|
-
|
|
69118
|
+
props.index = listRows.take(idDefault, 1, slotId);
|
|
68916
69119
|
}
|
|
68917
|
-
} else if (props.filtered) {
|
|
68918
|
-
virtual.drop(idDefault);
|
|
68919
|
-
} else {
|
|
68920
|
-
props.index = virtual.take(idDefault, 1, slotId);
|
|
68921
69120
|
}
|
|
69121
|
+
// Every row that renders says so, whether it was declared one by one or
|
|
69122
|
+
// drawn by a run: what it is (its value, whether it is selected) and whether
|
|
69123
|
+
// it mounts at all are written where it renders, in one place.
|
|
69124
|
+
listRows.draw(idDefault, {
|
|
69125
|
+
ownerId: row ? row.ownerId : idDefault,
|
|
69126
|
+
place: props.index,
|
|
69127
|
+
groupId,
|
|
69128
|
+
data: props
|
|
69129
|
+
});
|
|
68922
69130
|
useLayoutEffect(() => {
|
|
68923
69131
|
return () => {
|
|
68924
|
-
|
|
68925
|
-
row.run.unmount(idDefault);
|
|
68926
|
-
} else {
|
|
68927
|
-
virtual.drop(idDefault);
|
|
68928
|
-
}
|
|
69132
|
+
listRows.erase(idDefault);
|
|
68929
69133
|
};
|
|
68930
69134
|
}, []);
|
|
68931
|
-
// Every row that is drawn registers itself, whether it was declared one by
|
|
68932
|
-
// one or drawn by a run: what it says about itself (its value, whether it is
|
|
68933
|
-
// selected) is written where it is drawn, in one place.
|
|
68934
|
-
const item = props;
|
|
68935
|
-
tracker.useTrackItem(item);
|
|
68936
|
-
const groupTracker = useContext(GroupItemTrackerContext);
|
|
68937
|
-
const groupVisibleIndex = groupTracker ? groupTracker.useTrackItem(item) : null;
|
|
68938
69135
|
const separator = useContext(SeparatorContext);
|
|
68939
69136
|
if (props.filtered) {
|
|
68940
69137
|
return null;
|
|
@@ -68942,32 +69139,13 @@ const ListItemUI = props => {
|
|
|
68942
69139
|
const listItemVnode = jsx(ListItemReal, {
|
|
68943
69140
|
...props
|
|
68944
69141
|
});
|
|
68945
|
-
|
|
68946
|
-
|
|
68947
|
-
|
|
68948
|
-
// The separator a row wears is the one at the gap above it, so the first row
|
|
68949
|
-
// that mounts wears none. "Am I first?" is answered by whoever handed out
|
|
68950
|
-
// the place — the run for its rows, the list's virtual for a declared one
|
|
68951
|
-
// (virtual.take above) — not by the tracker's visibleIndex: during a reorder
|
|
68952
|
-
// render pass (items resorted by search score) the other items still carry
|
|
68953
|
-
// stale keyToExplicitOrder values, the binary search reads them, no item
|
|
68954
|
-
// comes out at 0 and a spurious separator appears at the top. Inside a
|
|
68955
|
-
// declared group, each group has its own tracker and its items do not
|
|
68956
|
-
// reorder, so groupVisibleIndex is reliable there.
|
|
68957
|
-
let isFirst;
|
|
68958
|
-
if (row) {
|
|
68959
|
-
isFirst = row.run.isFirst(props.index, row.groupKey);
|
|
68960
|
-
} else if (groupVisibleIndex === null || props.hidden) {
|
|
68961
|
-
isFirst = props.index === 0;
|
|
68962
|
-
} else {
|
|
68963
|
-
isFirst = groupVisibleIndex === 0;
|
|
68964
|
-
}
|
|
68965
|
-
if (isFirst) {
|
|
69142
|
+
// The separator a row wears is the one at the gap above it: none when
|
|
69143
|
+
// nothing of the list stands above it (see list_rows.js).
|
|
69144
|
+
if (!separator || listRows.isFirst(idDefault)) {
|
|
68966
69145
|
return listItemVnode;
|
|
68967
69146
|
}
|
|
68968
69147
|
// The gap index, only used as the function-form argument.
|
|
68969
|
-
|
|
68970
|
-
let separatorVnode = resolveSeparatorVnode(separator, gapIndex);
|
|
69148
|
+
let separatorVnode = resolveSeparatorVnode(separator, props.index - 1);
|
|
68971
69149
|
if (props.hidden) {
|
|
68972
69150
|
// A row kept in the DOM but hidden keeps its separator, hidden with it:
|
|
68973
69151
|
// the point of keeping a row that matches nothing is that nothing moves,
|
|
@@ -69296,441 +69474,45 @@ const ListItem = /*#__PURE__*/createComponentResolver([ListItemFirstResolver, Li
|
|
|
69296
69474
|
pure: true
|
|
69297
69475
|
});
|
|
69298
69476
|
|
|
69299
|
-
//
|
|
69300
|
-
//
|
|
69301
|
-
//
|
|
69302
|
-
//
|
|
69303
|
-
// A child knows how many rows it stands for but not what was declared before
|
|
69304
|
-
// it, and it cannot deduce that from when it renders: a render is free to skip
|
|
69305
|
-
// it. A child that draws from signals and whose props are all referentially
|
|
69306
|
-
// === the previous ones does not render again (@preact/signals installs a
|
|
69307
|
-
// shouldComponentUpdate that says so), which is what any child nobody rebuilt
|
|
69308
|
-
// this frame is — and children numbered as they render would then slide up
|
|
69309
|
-
// into the place of the one that was skipped.
|
|
69477
|
+
// The walk that gives the list's children their places: a slot for each of
|
|
69478
|
+
// them, declared to the list's rows all at once before any child renders,
|
|
69479
|
+
// and handed to the child through a provider of its own — which is what lets
|
|
69480
|
+
// the row reach it however deep the caller buried it in components of theirs.
|
|
69310
69481
|
//
|
|
69311
|
-
//
|
|
69312
|
-
//
|
|
69313
|
-
//
|
|
69314
|
-
//
|
|
69315
|
-
//
|
|
69316
|
-
|
|
69317
|
-
|
|
69318
|
-
|
|
69319
|
-
const
|
|
69320
|
-
|
|
69321
|
-
|
|
69322
|
-
|
|
69323
|
-
|
|
69324
|
-
const
|
|
69325
|
-
|
|
69326
|
-
|
|
69327
|
-
|
|
69328
|
-
|
|
69329
|
-
|
|
69330
|
-
|
|
69331
|
-
|
|
69332
|
-
|
|
69333
|
-
|
|
69334
|
-
|
|
69335
|
-
const
|
|
69336
|
-
|
|
69337
|
-
|
|
69338
|
-
|
|
69339
|
-
|
|
69340
|
-
|
|
69341
|
-
|
|
69342
|
-
|
|
69343
|
-
|
|
69344
|
-
|
|
69345
|
-
let rowTotal = 0;
|
|
69346
|
-
// Owners have left and the others have not been moved up yet. Done on the
|
|
69347
|
-
// next ask rather than on the spot: rows leave many at a time (a search, a
|
|
69348
|
-
// list unmounting), and moving the others up once is enough.
|
|
69349
|
-
let placesStale = false;
|
|
69350
|
-
// Where the last slot holding an owner stands: an owner arriving at or after
|
|
69351
|
-
// it is placed at the end without going over the others — a whole first
|
|
69352
|
-
// render, rows arriving in order, costs each row nothing but itself.
|
|
69353
|
-
let rankOwnedLast = -1;
|
|
69354
|
-
const rebuildWalk = () => {
|
|
69355
|
-
slotWalk.length = 0;
|
|
69356
|
-
rankBySlot.clear();
|
|
69357
|
-
const visit = parentSlotId => {
|
|
69358
|
-
const slotIds = slotIdsByParent.get(parentSlotId);
|
|
69359
|
-
if (!slotIds) {
|
|
69360
|
-
return;
|
|
69361
|
-
}
|
|
69362
|
-
for (const slotId of slotIds) {
|
|
69363
|
-
rankBySlot.set(slotId, slotWalk.length);
|
|
69364
|
-
slotWalk.push(slotId);
|
|
69365
|
-
visit(slotId);
|
|
69366
|
-
}
|
|
69367
|
-
};
|
|
69368
|
-
visit(null);
|
|
69369
|
-
};
|
|
69370
|
-
// Every place, in one go: a place is the sum of what stands before it, so
|
|
69371
|
-
// there is nothing to hand out one at a time. Writing a place that did not
|
|
69372
|
-
// change wakes nobody — a signal ignores a value equal to its own.
|
|
69373
|
-
const refreshPlaces = () => {
|
|
69374
|
-
placesStale = false;
|
|
69375
|
-
let index = 0;
|
|
69376
|
-
let rank = 0;
|
|
69377
|
-
rankOwnedLast = -1;
|
|
69378
|
-
while (rank < slotWalk.length) {
|
|
69379
|
-
const ownerIds = ownerIdsBySlot.get(slotWalk[rank]);
|
|
69380
|
-
if (ownerIds) {
|
|
69381
|
-
for (const ownerId of ownerIds) {
|
|
69382
|
-
const owner = ownerById.get(ownerId);
|
|
69383
|
-
owner.placeSignal.value = index;
|
|
69384
|
-
index += owner.rowCount;
|
|
69385
|
-
}
|
|
69386
|
-
rankOwnedLast = rank;
|
|
69387
|
-
}
|
|
69388
|
-
rank++;
|
|
69389
|
-
}
|
|
69390
|
-
rowTotal = index;
|
|
69391
|
-
totalSignal.value = index;
|
|
69392
|
-
};
|
|
69393
|
-
const addToSlot = (slotId, ownerId) => {
|
|
69394
|
-
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
69395
|
-
if (ownerIds) {
|
|
69396
|
-
ownerIds.push(ownerId);
|
|
69397
|
-
} else {
|
|
69398
|
-
ownerIdsBySlot.set(slotId, [ownerId]);
|
|
69399
|
-
}
|
|
69400
|
-
warnIfEveryRowInOneSlot(slotId);
|
|
69401
|
-
};
|
|
69402
|
-
// Rows that all stand in the same slot keep the order they first mounted in:
|
|
69403
|
-
// the walk is over the children the list is given, and a component holding
|
|
69404
|
-
// them is one child however many rows it renders. Everything about a place
|
|
69405
|
-
// then stops following what the caller writes — a search reordering the rows
|
|
69406
|
-
// moves nothing. Said once, and only for the shape that can be nothing else:
|
|
69407
|
-
// the list's whole content is one child, and several rows came out of it.
|
|
69408
|
-
let everyRowInOneSlotWarned = false;
|
|
69409
|
-
const warnIfEveryRowInOneSlot = slotId => {
|
|
69410
|
-
if (everyRowInOneSlotWarned) {
|
|
69411
|
-
return;
|
|
69412
|
-
}
|
|
69413
|
-
const rootSlotIds = slotIdsByParent.get(null);
|
|
69414
|
-
if (!rootSlotIds || rootSlotIds.length !== 1 || rootSlotIds[0] !== slotId) {
|
|
69415
|
-
return;
|
|
69416
|
-
}
|
|
69417
|
-
if (ownerIdsBySlot.get(slotId).length < 2) {
|
|
69418
|
-
return;
|
|
69419
|
-
}
|
|
69420
|
-
everyRowInOneSlotWarned = true;
|
|
69421
|
-
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.`);
|
|
69422
|
-
};
|
|
69423
|
-
const removeFromSlot = (slotId, ownerId) => {
|
|
69424
|
-
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
69425
|
-
if (!ownerIds) {
|
|
69426
|
-
return;
|
|
69427
|
-
}
|
|
69428
|
-
const index = ownerIds.indexOf(ownerId);
|
|
69429
|
-
if (index !== -1) {
|
|
69430
|
-
ownerIds.splice(index, 1);
|
|
69431
|
-
}
|
|
69432
|
-
if (ownerIds.length === 0) {
|
|
69433
|
-
ownerIdsBySlot.delete(slotId);
|
|
69434
|
-
}
|
|
69435
|
-
};
|
|
69436
|
-
// A slot the walk no longer names: whatever stood in it is gone, and so is
|
|
69437
|
-
// whatever a walk inside it had declared.
|
|
69438
|
-
const dropSlot = slotId => {
|
|
69439
|
-
const ownerIds = ownerIdsBySlot.get(slotId);
|
|
69440
|
-
if (ownerIds) {
|
|
69441
|
-
for (const ownerId of ownerIds) {
|
|
69442
|
-
ownerById.delete(ownerId);
|
|
69443
|
-
}
|
|
69444
|
-
ownerIdsBySlot.delete(slotId);
|
|
69445
|
-
}
|
|
69446
|
-
const childSlotIds = slotIdsByParent.get(slotId);
|
|
69447
|
-
if (childSlotIds) {
|
|
69448
|
-
slotIdsByParent.delete(slotId);
|
|
69449
|
-
for (const childSlotId of childSlotIds) {
|
|
69450
|
-
dropSlot(childSlotId);
|
|
69451
|
-
}
|
|
69452
|
-
}
|
|
69453
|
-
};
|
|
69454
|
-
const virtual = {
|
|
69455
|
-
totalSignal,
|
|
69456
|
-
pagesSignal,
|
|
69457
|
-
refreshingSignal,
|
|
69458
|
-
// What a run needs to know about the list it lives in: how many rows the
|
|
69459
|
-
// list is willing to draw at once, which end it opens on, and how much
|
|
69460
|
-
// room one row is given — a row whose content has not arrived must take
|
|
69461
|
-
// exactly that, or the rows drawn would not reach where the list says they
|
|
69462
|
-
// are.
|
|
69463
|
-
renderBudget: 0,
|
|
69464
|
-
scrolled: "start",
|
|
69465
|
-
// The list is on its way somewhere: what the window frames is not what it
|
|
69466
|
-
// is about to frame, so a run must not fetch for it (see holdWindow).
|
|
69467
|
-
holdPending: false,
|
|
69468
|
-
// Called by a run just before rows land in it: what is on screen must not
|
|
69469
|
-
// move because something arrived above it. Set by the list itself.
|
|
69470
|
-
captureAnchor: () => {},
|
|
69471
|
-
horizontal: false,
|
|
69472
|
-
virtualItemSizeSignal: null,
|
|
69473
|
-
renderSkeleton: undefined,
|
|
69474
|
-
// The children a walk stands over, in order — said in one call, before any
|
|
69475
|
-
// of them renders, so that what a child asks next is answered against the
|
|
69476
|
-
// whole picture and not against the children that happened to render
|
|
69477
|
-
// first. Said again on every render of the walk, and heard only when
|
|
69478
|
-
// something moved.
|
|
69479
|
-
declareSlots: (parentSlotId, slotIds) => {
|
|
69480
|
-
const slotIdsPrevious = slotIdsByParent.get(parentSlotId);
|
|
69481
|
-
if (slotIdsPrevious && sameSlotIds(slotIdsPrevious, slotIds)) {
|
|
69482
|
-
return;
|
|
69483
|
-
}
|
|
69484
|
-
if (slotIdsPrevious) {
|
|
69485
|
-
const slotIdSet = new Set(slotIds);
|
|
69486
|
-
for (const slotId of slotIdsPrevious) {
|
|
69487
|
-
if (!slotIdSet.has(slotId)) {
|
|
69488
|
-
dropSlot(slotId);
|
|
69489
|
-
}
|
|
69490
|
-
}
|
|
69491
|
-
}
|
|
69492
|
-
slotIdsByParent.set(parentSlotId, slotIds);
|
|
69493
|
-
rebuildWalk();
|
|
69494
|
-
refreshPlaces();
|
|
69495
|
-
},
|
|
69496
|
-
// Whether something has taken this slot for its own: what it renders
|
|
69497
|
-
// inside is then its to place (a run draws its groups with their rows
|
|
69498
|
-
// already placed), and no walk inside it has anything to declare.
|
|
69499
|
-
slotHasOwner: slotId => ownerIdsBySlot.has(slotId),
|
|
69500
|
-
// Whether any run of rows lives in this list: what makes a render window
|
|
69501
|
-
// mean anything (see List's renderBudget).
|
|
69502
|
-
hasRuns: () => locatorByOwner.size > 0,
|
|
69503
|
-
setRowLocator: (ownerId, locate) => {
|
|
69504
|
-
locatorByOwner.set(ownerId, locate);
|
|
69505
|
-
},
|
|
69506
|
-
dropRowLocator: ownerId => {
|
|
69507
|
-
locatorByOwner.delete(ownerId);
|
|
69508
|
-
},
|
|
69509
|
-
// Where the row named by that id sits, asked of whoever holds it.
|
|
69510
|
-
locateRow: id => {
|
|
69511
|
-
for (const locate of locatorByOwner.values()) {
|
|
69512
|
-
const index = locate(id);
|
|
69513
|
-
if (index !== null) {
|
|
69514
|
-
return index;
|
|
69515
|
-
}
|
|
69516
|
-
}
|
|
69517
|
-
return null;
|
|
69518
|
-
},
|
|
69519
|
-
// The place the owner's rows start at — read from a signal, so that the
|
|
69520
|
-
// owner is rendered again when it moves (see createListVirtual). Asked on
|
|
69521
|
-
// every render, and answered without a second look for as long as the
|
|
69522
|
-
// owner stands in the same slot for the same number of rows.
|
|
69523
|
-
take: (ownerId, rowCount, slotId) => {
|
|
69524
|
-
let owner = ownerById.get(ownerId);
|
|
69525
|
-
if (owner) {
|
|
69526
|
-
if (owner.slotId !== slotId || owner.rowCount !== rowCount) {
|
|
69527
|
-
removeFromSlot(owner.slotId, ownerId);
|
|
69528
|
-
addToSlot(slotId, ownerId);
|
|
69529
|
-
owner.slotId = slotId;
|
|
69530
|
-
owner.rowCount = rowCount;
|
|
69531
|
-
placesStale = true;
|
|
69532
|
-
}
|
|
69533
|
-
if (placesStale) {
|
|
69534
|
-
refreshPlaces();
|
|
69535
|
-
}
|
|
69536
|
-
return owner.placeSignal.value;
|
|
69537
|
-
}
|
|
69538
|
-
if (placesStale) {
|
|
69539
|
-
refreshPlaces();
|
|
69540
|
-
}
|
|
69541
|
-
const rank = rankBySlot.get(slotId);
|
|
69542
|
-
addToSlot(slotId, ownerId);
|
|
69543
|
-
if (rank !== undefined && rank >= rankOwnedLast) {
|
|
69544
|
-
owner = {
|
|
69545
|
-
slotId,
|
|
69546
|
-
rowCount,
|
|
69547
|
-
placeSignal: signal(rowTotal)
|
|
69548
|
-
};
|
|
69549
|
-
ownerById.set(ownerId, owner);
|
|
69550
|
-
rowTotal += rowCount;
|
|
69551
|
-
rankOwnedLast = rank;
|
|
69552
|
-
totalSignal.value = rowTotal;
|
|
69553
|
-
return owner.placeSignal.value;
|
|
69554
|
-
}
|
|
69555
|
-
owner = {
|
|
69556
|
-
slotId,
|
|
69557
|
-
rowCount,
|
|
69558
|
-
placeSignal: signal(0)
|
|
69559
|
-
};
|
|
69560
|
-
ownerById.set(ownerId, owner);
|
|
69561
|
-
refreshPlaces();
|
|
69562
|
-
return owner.placeSignal.value;
|
|
69563
|
-
},
|
|
69564
|
-
// The owner stands for no row of the collection: it was filtered out by a
|
|
69565
|
-
// search, or it is gone.
|
|
69566
|
-
drop: ownerId => {
|
|
69567
|
-
const owner = ownerById.get(ownerId);
|
|
69568
|
-
if (!owner) {
|
|
69569
|
-
return;
|
|
69570
|
-
}
|
|
69571
|
-
ownerById.delete(ownerId);
|
|
69572
|
-
removeFromSlot(owner.slotId, ownerId);
|
|
69573
|
-
if (placesStale) {
|
|
69574
|
-
return;
|
|
69575
|
-
}
|
|
69576
|
-
placesStale = true;
|
|
69577
|
-
queueMicrotask(() => {
|
|
69578
|
-
if (placesStale) {
|
|
69579
|
-
refreshPlaces();
|
|
69580
|
-
}
|
|
69581
|
-
});
|
|
69582
|
-
}
|
|
69583
|
-
};
|
|
69584
|
-
return virtual;
|
|
69585
|
-
};
|
|
69586
|
-
const sameSlotIds = (left, right) => {
|
|
69587
|
-
if (left.length !== right.length) {
|
|
69588
|
-
return false;
|
|
69589
|
-
}
|
|
69590
|
-
let index = 0;
|
|
69591
|
-
while (index < left.length) {
|
|
69592
|
-
if (left[index] !== right[index]) {
|
|
69593
|
-
return false;
|
|
69594
|
-
}
|
|
69595
|
-
index++;
|
|
69596
|
-
}
|
|
69597
|
-
return true;
|
|
69598
|
-
};
|
|
69599
|
-
|
|
69600
|
-
// Which of a run's rows mount, and which of them comes first. A run draws
|
|
69601
|
-
// every row of its window, and only the row itself knows, once it renders,
|
|
69602
|
-
// that it renders nothing (filtered out by a search, see ListItemUI). The
|
|
69603
|
-
// separator a row wears is the one at the gap above it, so the first row that
|
|
69604
|
-
// mounts wears none — and "first" is read off the rows that mount, not off
|
|
69605
|
-
// the collection. Rows say so as they render, in order, and the answer is a
|
|
69606
|
-
// signal: a row rendered from a kept vnode is rendered again when the row
|
|
69607
|
-
// before it leaves or comes back. Grouped rows are counted per group, the gap
|
|
69608
|
-
// above a group's first row being the group wrapper's own.
|
|
69609
|
-
const createRunRows = () => {
|
|
69610
|
-
// rowId → { index, groupKey }
|
|
69611
|
-
const rowById = new Map();
|
|
69612
|
-
// groupKey (undefined outside groups) → the index of the group's first
|
|
69613
|
-
// mounted row, -1 when none.
|
|
69614
|
-
const firstSignalByGroup = new Map();
|
|
69615
|
-
// Where the window starts: a run cut by the window has rows above its first
|
|
69616
|
-
// drawn one, and so does a run standing after declared rows.
|
|
69617
|
-
const windowFromSignal = signal(0);
|
|
69618
|
-
// Groups whose first row left: recounted on the next ask, or at the end of
|
|
69619
|
-
// the frame, whichever comes first.
|
|
69620
|
-
const staleGroupKeys = new Set();
|
|
69621
|
-
const firstSignalOf = groupKey => {
|
|
69622
|
-
let firstSignal = firstSignalByGroup.get(groupKey);
|
|
69623
|
-
if (!firstSignal) {
|
|
69624
|
-
firstSignal = signal(-1);
|
|
69625
|
-
firstSignalByGroup.set(groupKey, firstSignal);
|
|
69626
|
-
}
|
|
69627
|
-
return firstSignal;
|
|
69628
|
-
};
|
|
69629
|
-
const refresh = groupKey => {
|
|
69630
|
-
staleGroupKeys.delete(groupKey);
|
|
69631
|
-
let first = -1;
|
|
69632
|
-
for (const row of rowById.values()) {
|
|
69633
|
-
if (row.groupKey === groupKey && (first === -1 || row.index < first)) {
|
|
69634
|
-
first = row.index;
|
|
69635
|
-
}
|
|
69636
|
-
}
|
|
69637
|
-
firstSignalOf(groupKey).value = first;
|
|
69638
|
-
};
|
|
69639
|
-
const leave = row => {
|
|
69640
|
-
if (firstSignalOf(row.groupKey).peek() !== row.index) {
|
|
69641
|
-
return;
|
|
69642
|
-
}
|
|
69643
|
-
staleGroupKeys.add(row.groupKey);
|
|
69644
|
-
queueMicrotask(() => {
|
|
69645
|
-
if (staleGroupKeys.has(row.groupKey)) {
|
|
69646
|
-
refresh(row.groupKey);
|
|
69647
|
-
}
|
|
69648
|
-
});
|
|
69649
|
-
};
|
|
69650
|
-
return {
|
|
69651
|
-
setWindowFrom: windowFrom => {
|
|
69652
|
-
windowFromSignal.value = windowFrom;
|
|
69653
|
-
},
|
|
69654
|
-
mount: (rowId, index, groupKey) => {
|
|
69655
|
-
const row = rowById.get(rowId);
|
|
69656
|
-
if (row) {
|
|
69657
|
-
if (row.index === index && row.groupKey === groupKey) {
|
|
69658
|
-
return;
|
|
69659
|
-
}
|
|
69660
|
-
leave(row);
|
|
69661
|
-
row.index = index;
|
|
69662
|
-
row.groupKey = groupKey;
|
|
69663
|
-
} else {
|
|
69664
|
-
rowById.set(rowId, {
|
|
69665
|
-
index,
|
|
69666
|
-
groupKey
|
|
69667
|
-
});
|
|
69668
|
-
}
|
|
69669
|
-
const firstSignal = firstSignalOf(groupKey);
|
|
69670
|
-
const first = firstSignal.peek();
|
|
69671
|
-
if (first === -1 || index < first) {
|
|
69672
|
-
firstSignal.value = index;
|
|
69673
|
-
}
|
|
69674
|
-
},
|
|
69675
|
-
unmount: rowId => {
|
|
69676
|
-
const row = rowById.get(rowId);
|
|
69677
|
-
if (!row) {
|
|
69678
|
-
return;
|
|
69679
|
-
}
|
|
69680
|
-
rowById.delete(rowId);
|
|
69681
|
-
leave(row);
|
|
69682
|
-
},
|
|
69683
|
-
isFirst: (index, groupKey) => {
|
|
69684
|
-
if (staleGroupKeys.has(groupKey)) {
|
|
69685
|
-
refresh(groupKey);
|
|
69686
|
-
}
|
|
69687
|
-
if (firstSignalOf(groupKey).value !== index) {
|
|
69688
|
-
return false;
|
|
69689
|
-
}
|
|
69690
|
-
return groupKey !== undefined || windowFromSignal.value === 0;
|
|
69691
|
-
}
|
|
69692
|
-
};
|
|
69693
|
-
};
|
|
69694
|
-
|
|
69695
|
-
// The walk that gives the list's children their places: a slot for each of
|
|
69696
|
-
// them, declared to the list's virtual all at once before any child renders,
|
|
69697
|
-
// and handed to the child through a provider of its own — which is what lets
|
|
69698
|
-
// the row reach it however deep the caller buried it in components of theirs.
|
|
69699
|
-
//
|
|
69700
|
-
// A slot is named the way preact tells the child apart: by key when it has
|
|
69701
|
-
// one, by position otherwise, and inside the array it was given in — a nested
|
|
69702
|
-
// array is one child to preact, so what follows the array keeps its name
|
|
69703
|
-
// however many rows the array holds. A child preact would not render (null,
|
|
69704
|
-
// a boolean) has no slot: it is not there.
|
|
69705
|
-
const ListDeclaredChildren = ({
|
|
69706
|
-
children
|
|
69707
|
-
}) => {
|
|
69708
|
-
const virtual = useContext(ListVirtualContext);
|
|
69709
|
-
const parentSlotId = useContext(ListSlotContext);
|
|
69710
|
-
if (parentSlotId !== null && virtual.slotHasOwner(parentSlotId)) {
|
|
69711
|
-
return children;
|
|
69712
|
-
}
|
|
69713
|
-
const slotIds = [];
|
|
69714
|
-
const declared = [];
|
|
69715
|
-
declareChildren(children, parentSlotId === null ? "" : `${parentSlotId}/`, slotIds, declared);
|
|
69716
|
-
virtual.declareSlots(parentSlotId, slotIds);
|
|
69717
|
-
return jsx(Fragment, {
|
|
69718
|
-
children: declared
|
|
69719
|
-
});
|
|
69720
|
-
};
|
|
69721
|
-
const declareChildren = (children, prefix, slotIds, declared) => {
|
|
69722
|
-
const childArray = Array.isArray(children) ? children : [children];
|
|
69723
|
-
let index = 0;
|
|
69724
|
-
for (const child of childArray) {
|
|
69725
|
-
if (Array.isArray(child)) {
|
|
69726
|
-
declareChildren(child, `${prefix}${index}/`, slotIds, declared);
|
|
69727
|
-
} else if (child !== null && child !== undefined && child !== false && child !== true) {
|
|
69728
|
-
const slotId = child.key === undefined || child.key === null ? `${prefix}i${index}` : `${prefix}k${child.key}`;
|
|
69729
|
-
slotIds.push(slotId);
|
|
69730
|
-
declared.push(jsx(ListSlotContext.Provider, {
|
|
69731
|
-
value: slotId,
|
|
69732
|
-
children: child
|
|
69733
|
-
}, slotId));
|
|
69482
|
+
// A slot is named the way preact tells the child apart: by key when it has
|
|
69483
|
+
// one, by position otherwise, and inside the array it was given in — a nested
|
|
69484
|
+
// array is one child to preact, so what follows the array keeps its name
|
|
69485
|
+
// however many rows the array holds. A child preact would not render (null,
|
|
69486
|
+
// a boolean) has no slot: it is not there.
|
|
69487
|
+
const ListDeclaredChildren = ({
|
|
69488
|
+
children
|
|
69489
|
+
}) => {
|
|
69490
|
+
const listRows = useContext(ListRowsContext);
|
|
69491
|
+
const parentSlotId = useContext(ListSlotContext);
|
|
69492
|
+
if (parentSlotId !== null && listRows.slotHasOwner(parentSlotId)) {
|
|
69493
|
+
return children;
|
|
69494
|
+
}
|
|
69495
|
+
const slotIds = [];
|
|
69496
|
+
const declared = [];
|
|
69497
|
+
declareChildren(children, parentSlotId === null ? "" : `${parentSlotId}/`, slotIds, declared);
|
|
69498
|
+
listRows.declareSlots(parentSlotId, slotIds);
|
|
69499
|
+
return jsx(Fragment, {
|
|
69500
|
+
children: declared
|
|
69501
|
+
});
|
|
69502
|
+
};
|
|
69503
|
+
const declareChildren = (children, prefix, slotIds, declared) => {
|
|
69504
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
69505
|
+
let index = 0;
|
|
69506
|
+
for (const child of childArray) {
|
|
69507
|
+
if (Array.isArray(child)) {
|
|
69508
|
+
declareChildren(child, `${prefix}${index}/`, slotIds, declared);
|
|
69509
|
+
} else if (child !== null && child !== undefined && child !== false && child !== true) {
|
|
69510
|
+
const slotId = child.key === undefined || child.key === null ? `${prefix}i${index}` : `${prefix}k${child.key}`;
|
|
69511
|
+
slotIds.push(slotId);
|
|
69512
|
+
declared.push(jsx(ListSlotContext.Provider, {
|
|
69513
|
+
value: slotId,
|
|
69514
|
+
children: child
|
|
69515
|
+
}, slotId));
|
|
69734
69516
|
}
|
|
69735
69517
|
index++;
|
|
69736
69518
|
}
|
|
@@ -69872,15 +69654,10 @@ const ListItems = ({
|
|
|
69872
69654
|
onRequestStateChange
|
|
69873
69655
|
}) => {
|
|
69874
69656
|
const ownerId = useId();
|
|
69875
|
-
const
|
|
69657
|
+
const listRows = useContext(ListRowsContext);
|
|
69876
69658
|
const slotId = useContext(ListSlotContext);
|
|
69877
69659
|
const renderWindow = useContext(RenderWindowContext);
|
|
69878
69660
|
const separator = useContext(SeparatorContext);
|
|
69879
|
-
const runRowsRef = useRef(null);
|
|
69880
|
-
if (!runRowsRef.current) {
|
|
69881
|
-
runRowsRef.current = createRunRows();
|
|
69882
|
-
}
|
|
69883
|
-
const runRows = runRowsRef.current;
|
|
69884
69661
|
// The vnode drawn for a row, kept by item: a run rendering again (its window
|
|
69885
69662
|
// moving, its first paint's budget giving way to the full one) hands preact
|
|
69886
69663
|
// the same vnode for a row that has not changed, and preact leaves that
|
|
@@ -69903,7 +69680,7 @@ const ListItems = ({
|
|
|
69903
69680
|
memoryBudget,
|
|
69904
69681
|
onRequestStateChange
|
|
69905
69682
|
});
|
|
69906
|
-
const renderRowSkeleton = renderSkeleton === undefined ?
|
|
69683
|
+
const renderRowSkeleton = renderSkeleton === undefined ? listRows.renderSkeleton : renderSkeleton;
|
|
69907
69684
|
// A row on its way takes the room the list reserves for it: anything else
|
|
69908
69685
|
// and the rows drawn stop short of where the scroll says they are. Read
|
|
69909
69686
|
// where a row is actually missing, and not before: the size settles after
|
|
@@ -69915,9 +69692,9 @@ const ListItems = ({
|
|
|
69915
69692
|
return skeletonRow;
|
|
69916
69693
|
}
|
|
69917
69694
|
skeletonRow = {};
|
|
69918
|
-
const virtualItemSize =
|
|
69695
|
+
const virtualItemSize = listRows.virtualItemSizeSignal.value;
|
|
69919
69696
|
if (virtualItemSize) {
|
|
69920
|
-
if (
|
|
69697
|
+
if (listRows.horizontal) {
|
|
69921
69698
|
skeletonRow.rowMinWidth = `${virtualItemSize}px`;
|
|
69922
69699
|
} else {
|
|
69923
69700
|
skeletonRow.rowMinHeight = `${virtualItemSize}px`;
|
|
@@ -69925,7 +69702,7 @@ const ListItems = ({
|
|
|
69925
69702
|
}
|
|
69926
69703
|
return skeletonRow;
|
|
69927
69704
|
};
|
|
69928
|
-
const runStart =
|
|
69705
|
+
const runStart = listRows.take(ownerId, store.rowCount, slotId);
|
|
69929
69706
|
const runEnd = runStart + store.rowCount;
|
|
69930
69707
|
// The two ways to count the same row. The list numbers its rows from its own
|
|
69931
69708
|
// first one, whatever draws it; the store numbers the collection's, straight
|
|
@@ -69940,7 +69717,7 @@ const ListItems = ({
|
|
|
69940
69717
|
const windowFrom = renderWindow.start > runStart ? renderWindow.start : runStart;
|
|
69941
69718
|
const windowTo = renderWindow.end < runEnd ? renderWindow.end : runEnd;
|
|
69942
69719
|
store.forget(rankOf(windowFrom), rankOf(windowTo));
|
|
69943
|
-
|
|
69720
|
+
listRows.declareWindow(ownerId, windowFrom, windowTo);
|
|
69944
69721
|
|
|
69945
69722
|
// The row answers to its own id when the item carries one — that is what
|
|
69946
69723
|
// addresses it from outside (--navi-select, --navi-scroll, startAt) — and
|
|
@@ -69950,7 +69727,7 @@ const ListItems = ({
|
|
|
69950
69727
|
// Where a row named from outside actually sits. Only the run can answer:
|
|
69951
69728
|
// rows it holds but does not draw are nowhere else — a list only knows the
|
|
69952
69729
|
// rows it has drawn (they register themselves, see ListItemUI).
|
|
69953
|
-
|
|
69730
|
+
listRows.setRowLocator(ownerId, id => {
|
|
69954
69731
|
let found = null;
|
|
69955
69732
|
store.eachHeld((item, rank) => {
|
|
69956
69733
|
const rowIndex = rowOf(rank);
|
|
@@ -69962,8 +69739,8 @@ const ListItems = ({
|
|
|
69962
69739
|
});
|
|
69963
69740
|
useLayoutEffect(() => {
|
|
69964
69741
|
return () => {
|
|
69965
|
-
|
|
69966
|
-
|
|
69742
|
+
listRows.dropRowLocator(ownerId);
|
|
69743
|
+
listRows.drop(ownerId);
|
|
69967
69744
|
};
|
|
69968
69745
|
}, []);
|
|
69969
69746
|
|
|
@@ -69989,7 +69766,7 @@ const ListItems = ({
|
|
|
69989
69766
|
let askStart = missingStart;
|
|
69990
69767
|
let askEnd = missingEnd;
|
|
69991
69768
|
if (missingStart !== -1) {
|
|
69992
|
-
const rowsPerPage = pageSize ||
|
|
69769
|
+
const rowsPerPage = pageSize || listRows.renderBudget;
|
|
69993
69770
|
const holeSize = missingEnd - missingStart + 1;
|
|
69994
69771
|
if (holeSize < rowsPerPage) {
|
|
69995
69772
|
// Which way the page grows: away from the rows already held, which is
|
|
@@ -70104,7 +69881,7 @@ const ListItems = ({
|
|
|
70104
69881
|
rows.push(jsx("li", {
|
|
70105
69882
|
className: "navi_list_failed_rows",
|
|
70106
69883
|
style: {
|
|
70107
|
-
"--size-to-fill": `${failedRowCount *
|
|
69884
|
+
"--size-to-fill": `${failedRowCount * listRows.virtualItemSizeSignal.value}px`
|
|
70108
69885
|
},
|
|
70109
69886
|
children: renderError ? renderError({
|
|
70110
69887
|
error: store.failure.error,
|
|
@@ -70142,13 +69919,12 @@ const ListItems = ({
|
|
|
70142
69919
|
}
|
|
70143
69920
|
if (rowVnode) {
|
|
70144
69921
|
pushRow(jsx(ListRunSkeletonRow, {
|
|
70145
|
-
run: runRows,
|
|
70146
69922
|
row: {
|
|
70147
69923
|
id: key,
|
|
70148
69924
|
index: rowIndex,
|
|
69925
|
+
ownerId,
|
|
70149
69926
|
...getSkeletonRow()
|
|
70150
69927
|
},
|
|
70151
|
-
groupKey: groupKey,
|
|
70152
69928
|
separator: separator,
|
|
70153
69929
|
children: rowVnode
|
|
70154
69930
|
}, key), item, rowIndex, groupKey);
|
|
@@ -70159,7 +69935,7 @@ const ListItems = ({
|
|
|
70159
69935
|
let rowVnode;
|
|
70160
69936
|
let rowContextValue;
|
|
70161
69937
|
const rowVnodeKept = rowVnodesByItem.get(item);
|
|
70162
|
-
if (rowVnodeKept && rowVnodeKept.rowIndex === rowIndex && rowVnodeKept.refreshing === renderItemState.refreshing
|
|
69938
|
+
if (rowVnodeKept && rowVnodeKept.rowIndex === rowIndex && rowVnodeKept.refreshing === renderItemState.refreshing) {
|
|
70163
69939
|
rowVnode = rowVnodeKept.vnode;
|
|
70164
69940
|
rowContextValue = rowVnodeKept.rowContextValue;
|
|
70165
69941
|
} else {
|
|
@@ -70172,8 +69948,7 @@ const ListItems = ({
|
|
|
70172
69948
|
id: key,
|
|
70173
69949
|
index: rowIndex,
|
|
70174
69950
|
item,
|
|
70175
|
-
|
|
70176
|
-
groupKey
|
|
69951
|
+
ownerId
|
|
70177
69952
|
};
|
|
70178
69953
|
rowVnodesByItem.set(item, {
|
|
70179
69954
|
vnode: rowVnode,
|
|
@@ -70200,28 +69975,37 @@ const ListItems = ({
|
|
|
70200
69975
|
return rows;
|
|
70201
69976
|
};
|
|
70202
69977
|
|
|
70203
|
-
// A run's row that has not arrived, standing where the real one will
|
|
70204
|
-
//
|
|
70205
|
-
// above it
|
|
69978
|
+
// A run's row that has not arrived, standing where the real one will. It never
|
|
69979
|
+
// reaches ListItemUI (see ListItemSkeletonResolver), so it is drawn among the
|
|
69980
|
+
// rows here, and wears the separator of the gap above it the way a real row
|
|
69981
|
+
// does there.
|
|
69982
|
+
const SKELETON_ROW_DATA = {
|
|
69983
|
+
skeleton: true
|
|
69984
|
+
};
|
|
70206
69985
|
const ListRunSkeletonRow = ({
|
|
70207
|
-
run,
|
|
70208
69986
|
row,
|
|
70209
|
-
groupKey,
|
|
70210
69987
|
separator,
|
|
70211
69988
|
children
|
|
70212
69989
|
}) => {
|
|
69990
|
+
const listRows = useContext(ListRowsContext);
|
|
69991
|
+
const groupId = useContext(ListGroupContext);
|
|
70213
69992
|
const rowId = useId();
|
|
70214
|
-
|
|
69993
|
+
listRows.draw(rowId, {
|
|
69994
|
+
ownerId: row.ownerId,
|
|
69995
|
+
place: row.index,
|
|
69996
|
+
groupId,
|
|
69997
|
+
data: SKELETON_ROW_DATA
|
|
69998
|
+
});
|
|
70215
69999
|
useLayoutEffect(() => {
|
|
70216
70000
|
return () => {
|
|
70217
|
-
|
|
70001
|
+
listRows.erase(rowId);
|
|
70218
70002
|
};
|
|
70219
70003
|
}, []);
|
|
70220
70004
|
const rowVnode = jsx(ListRowContext.Provider, {
|
|
70221
70005
|
value: row,
|
|
70222
70006
|
children: children
|
|
70223
70007
|
});
|
|
70224
|
-
if (!separator ||
|
|
70008
|
+
if (!separator || listRows.isFirst(rowId)) {
|
|
70225
70009
|
return rowVnode;
|
|
70226
70010
|
}
|
|
70227
70011
|
return jsxs(Fragment, {
|
|
@@ -70374,7 +70158,7 @@ const useItemStore = ({
|
|
|
70374
70158
|
// where the hole is, and cleared by a retry — which is what makes the same
|
|
70375
70159
|
// range askable again (see the request memory just above).
|
|
70376
70160
|
const [failure, setFailure] = useState(null);
|
|
70377
|
-
const
|
|
70161
|
+
const listRows = useContext(ListRowsContext);
|
|
70378
70162
|
// The rows are there, which is what the list waits for to place itself on the
|
|
70379
70163
|
// row it is held at (see placeWhereHeld). Said from an effect: a signal read
|
|
70380
70164
|
// during this very render must not be written during it.
|
|
@@ -70383,12 +70167,12 @@ const useItemStore = ({
|
|
|
70383
70167
|
return;
|
|
70384
70168
|
}
|
|
70385
70169
|
itemsHeldRef.current = true;
|
|
70386
|
-
|
|
70170
|
+
listRows.pagesSignal.value = listRows.pagesSignal.peek() + 1;
|
|
70387
70171
|
});
|
|
70388
70172
|
// Before the first answer a run does not know how many rows it stands for.
|
|
70389
70173
|
// It stands for a windowful of them: a list that is about to be filled looks
|
|
70390
70174
|
// like rows on their way, not like an empty list.
|
|
70391
|
-
const rowCount = pages.count ?? count ??
|
|
70175
|
+
const rowCount = pages.count ?? count ?? listRows.renderBudget;
|
|
70392
70176
|
// A run that never received anything has nothing to keep on screen: asking
|
|
70393
70177
|
// again is its first ask, not a refresh.
|
|
70394
70178
|
if (staleRef.current && pages.count === undefined) {
|
|
@@ -70398,9 +70182,9 @@ const useItemStore = ({
|
|
|
70398
70182
|
if (!refreshing) {
|
|
70399
70183
|
return null;
|
|
70400
70184
|
}
|
|
70401
|
-
|
|
70185
|
+
listRows.refreshingSignal.value = listRows.refreshingSignal.peek() + 1;
|
|
70402
70186
|
return () => {
|
|
70403
|
-
|
|
70187
|
+
listRows.refreshingSignal.value = listRows.refreshingSignal.peek() - 1;
|
|
70404
70188
|
};
|
|
70405
70189
|
}, [refreshing]);
|
|
70406
70190
|
|
|
@@ -70499,7 +70283,7 @@ const useItemStore = ({
|
|
|
70499
70283
|
// how many rows there are, so it asks for the rows the list would open
|
|
70500
70284
|
// on — counting back from the end when that is where it opens, the way
|
|
70501
70285
|
// an HTTP range does.
|
|
70502
|
-
const budget =
|
|
70286
|
+
const budget = listRows.renderBudget;
|
|
70503
70287
|
let start = missingStart;
|
|
70504
70288
|
let end = missingEnd;
|
|
70505
70289
|
let around;
|
|
@@ -70510,11 +70294,11 @@ const useItemStore = ({
|
|
|
70510
70294
|
// The list is held on a row nothing on screen leads to: the rows it holds
|
|
70511
70295
|
// do not contain it, so no window it could draw will ever bring it. Only
|
|
70512
70296
|
// asking for it by name does.
|
|
70513
|
-
const wanted =
|
|
70297
|
+
const wanted = listRows.scrolled;
|
|
70514
70298
|
const askingAroundWantedRow = revalidating &&
|
|
70515
70299
|
// Only while the hold stands: once the user has taken the list over,
|
|
70516
70300
|
// the reading position is where they are, not where it opened.
|
|
70517
|
-
|
|
70301
|
+
listRows.holdPending && wanted && typeof wanted === "object" && wanted.id !== undefined && listRows.locateRow(wanted.id) === null;
|
|
70518
70302
|
if (askingAroundWantedRow) {
|
|
70519
70303
|
around = wanted.id;
|
|
70520
70304
|
// Where it stood when it was written down is enough to frame the ask;
|
|
@@ -70537,7 +70321,7 @@ const useItemStore = ({
|
|
|
70537
70321
|
around = firstHeld.id;
|
|
70538
70322
|
}
|
|
70539
70323
|
} else if (pages.count === undefined) {
|
|
70540
|
-
const scrolled =
|
|
70324
|
+
const scrolled = listRows.scrolled;
|
|
70541
70325
|
if (scrolled === "end") {
|
|
70542
70326
|
// Counting back from the end, the way an HTTP range does: a list
|
|
70543
70327
|
// opening on its last rows asks for them before it knows how many
|
|
@@ -70568,7 +70352,7 @@ const useItemStore = ({
|
|
|
70568
70352
|
// way somewhere the window does not frame yet, `count` that it knows
|
|
70569
70353
|
// how many rows it stands for.
|
|
70570
70354
|
const debugAsk = outcome => {
|
|
70571
|
-
debugScroll(`ask ${start}-${end}: ${outcome}`, `(revalidating=${revalidating} holdPending=${
|
|
70355
|
+
debugScroll(`ask ${start}-${end}: ${outcome}`, `(revalidating=${revalidating} holdPending=${listRows.holdPending} count=${pages.count})`);
|
|
70572
70356
|
};
|
|
70573
70357
|
if (start === -1) {
|
|
70574
70358
|
// Nothing missing and nothing to revalidate: the run has what it
|
|
@@ -70576,7 +70360,7 @@ const useItemStore = ({
|
|
|
70576
70360
|
debugAsk("nothing missing");
|
|
70577
70361
|
return;
|
|
70578
70362
|
}
|
|
70579
|
-
if (
|
|
70363
|
+
if (listRows.holdPending && pages.count !== undefined && !askingAroundWantedRow) {
|
|
70580
70364
|
// The one ask a hold lets through: the row the list is held on is
|
|
70581
70365
|
// what would lift the hold, and nothing else is going to bring it.
|
|
70582
70366
|
debugAsk("held on a row not reached yet");
|
|
@@ -70667,7 +70451,7 @@ const useItemStore = ({
|
|
|
70667
70451
|
const pageCount = Array.isArray(page) ? pageItems.length : page.count ?? pageStart + pageItems.length;
|
|
70668
70452
|
// Before the rows land: what is on screen has to stay where it is,
|
|
70669
70453
|
// and the DOM still shows the state to hold onto.
|
|
70670
|
-
|
|
70454
|
+
listRows.captureAnchor();
|
|
70671
70455
|
if (revalidating) {
|
|
70672
70456
|
// The rows held stood for a composition that has moved on; the
|
|
70673
70457
|
// ones outside the window are forgotten and asked for again if the
|
|
@@ -70689,7 +70473,7 @@ const useItemStore = ({
|
|
|
70689
70473
|
replace: revalidating
|
|
70690
70474
|
});
|
|
70691
70475
|
}
|
|
70692
|
-
|
|
70476
|
+
listRows.pagesSignal.value = listRows.pagesSignal.peek() + 1;
|
|
70693
70477
|
setPageVersion(version => version + 1);
|
|
70694
70478
|
};
|
|
70695
70479
|
const failed = error => {
|
|
@@ -70757,10 +70541,16 @@ const ListItemGroup = ({
|
|
|
70757
70541
|
...rest
|
|
70758
70542
|
}) => {
|
|
70759
70543
|
const groupId = useId();
|
|
70760
|
-
const
|
|
70544
|
+
const listRows = useContext(ListRowsContext);
|
|
70545
|
+
const group = listRows.group(groupId);
|
|
70546
|
+
useLayoutEffect(() => {
|
|
70547
|
+
return () => {
|
|
70548
|
+
listRows.dropGroup(groupId);
|
|
70549
|
+
};
|
|
70550
|
+
}, []);
|
|
70761
70551
|
const searchNoMatchMode = useContext(SearchNoMatchModeContext);
|
|
70762
|
-
const groupItemCount =
|
|
70763
|
-
const groupNoMatchCount =
|
|
70552
|
+
const groupItemCount = group.countSignal.value;
|
|
70553
|
+
const groupNoMatchCount = group.noMatchCountSignal.value;
|
|
70764
70554
|
// Every row of this group failed the search: the label has nothing left to
|
|
70765
70555
|
// title. "remove" empties the group on its own (and hiddenWhileEmpty takes it
|
|
70766
70556
|
// out of the flow), "muted" keeps the rows readable so the label stays useful
|
|
@@ -70804,8 +70594,8 @@ const ListItemGroup = ({
|
|
|
70804
70594
|
className: "navi_list_item_group_list",
|
|
70805
70595
|
role: "group",
|
|
70806
70596
|
"aria-labelledby": groupId,
|
|
70807
|
-
children: jsx(
|
|
70808
|
-
value:
|
|
70597
|
+
children: jsx(ListGroupContext.Provider, {
|
|
70598
|
+
value: groupId,
|
|
70809
70599
|
children: jsx(ListDeclaredChildren, {
|
|
70810
70600
|
children: children
|
|
70811
70601
|
})
|
|
@@ -76194,414 +75984,812 @@ const SplitButton = props => {
|
|
|
76194
75984
|
});
|
|
76195
75985
|
};
|
|
76196
75986
|
|
|
76197
|
-
// What the Picker's popup answers to — Picker's own popup props, named here so
|
|
76198
|
-
// a caller reaches all of them through the split button (see picker.jsx's JSDoc
|
|
76199
|
-
// for what each one says).
|
|
76200
|
-
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"]);
|
|
76201
|
-
const splitPopupProps = props => {
|
|
76202
|
-
const popupProps = {};
|
|
76203
|
-
const boxProps = {};
|
|
76204
|
-
for (const key of Object.keys(props)) {
|
|
76205
|
-
if (POPUP_PROP_SET.has(key)) {
|
|
76206
|
-
popupProps[key] = props[key];
|
|
75987
|
+
// What the Picker's popup answers to — Picker's own popup props, named here so
|
|
75988
|
+
// a caller reaches all of them through the split button (see picker.jsx's JSDoc
|
|
75989
|
+
// for what each one says).
|
|
75990
|
+
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"]);
|
|
75991
|
+
const splitPopupProps = props => {
|
|
75992
|
+
const popupProps = {};
|
|
75993
|
+
const boxProps = {};
|
|
75994
|
+
for (const key of Object.keys(props)) {
|
|
75995
|
+
if (POPUP_PROP_SET.has(key)) {
|
|
75996
|
+
popupProps[key] = props[key];
|
|
75997
|
+
} else {
|
|
75998
|
+
boxProps[key] = props[key];
|
|
75999
|
+
}
|
|
76000
|
+
}
|
|
76001
|
+
return [popupProps, boxProps];
|
|
76002
|
+
};
|
|
76003
|
+
|
|
76004
|
+
/**
|
|
76005
|
+
* applySearch — matches value against searchText.
|
|
76006
|
+
*
|
|
76007
|
+
* Accent-insensitive: "gue" matches "Guérin", "e" matches "é".
|
|
76008
|
+
* Case-insensitive: "bob" matches "Bob", with a score bonus for case-exact matches.
|
|
76009
|
+
* Multi-word: if searchText contains spaces, each word must appear somewhere in
|
|
76010
|
+
* the value for it to match. Ranges for all words are returned.
|
|
76011
|
+
*
|
|
76012
|
+
* Score table:
|
|
76013
|
+
*
|
|
76014
|
+
* Situation Score
|
|
76015
|
+
* ─────────────────────────────────────── ───────────────────────────
|
|
76016
|
+
* phrase at start of value 1
|
|
76017
|
+
* multi-word, one word at start (all match) 0.75
|
|
76018
|
+
* phrase / word at word boundary 0.625
|
|
76019
|
+
* phrase / words mid-word 0.5
|
|
76020
|
+
* + case-exact bonus +0.125
|
|
76021
|
+
* multi-word partial: score × (matched/total)
|
|
76022
|
+
*
|
|
76023
|
+
* matchRanges: [start, end] pairs (exclusive end) for CSS Highlight API.
|
|
76024
|
+
* Intended to be passed to useSearch as the matchFn parameter.
|
|
76025
|
+
*/
|
|
76026
|
+
const applySearch = (searchText, value) => {
|
|
76027
|
+
if (!searchText) {
|
|
76028
|
+
return { match: true, matchScore: 0, matchRanges: [] };
|
|
76029
|
+
}
|
|
76030
|
+
if (searchText.length > 100) {
|
|
76031
|
+
searchText = searchText.slice(0, 100);
|
|
76032
|
+
}
|
|
76033
|
+
const str = String(value);
|
|
76034
|
+
const foldedStr = foldAccents(str).toLowerCase();
|
|
76035
|
+
const { foldedSearch, words, originalWords } = getSearchInfo(searchText);
|
|
76036
|
+
|
|
76037
|
+
// Try exact phrase match first (gives best score).
|
|
76038
|
+
const phraseRanges = [];
|
|
76039
|
+
let phraseIdx = foldedStr.indexOf(foldedSearch);
|
|
76040
|
+
while (phraseIdx !== -1) {
|
|
76041
|
+
phraseRanges.push([phraseIdx, phraseIdx + foldedSearch.length]);
|
|
76042
|
+
phraseIdx = foldedStr.indexOf(foldedSearch, phraseIdx + 1);
|
|
76043
|
+
}
|
|
76044
|
+
if (phraseRanges.length > 0) {
|
|
76045
|
+
const atStart = foldedStr.startsWith(foldedSearch);
|
|
76046
|
+
const atWordBoundary = phraseRanges.some(([start]) =>
|
|
76047
|
+
isWordBoundary(foldedStr, start),
|
|
76048
|
+
);
|
|
76049
|
+
const caseExact = str.includes(searchText);
|
|
76050
|
+
let baseScore;
|
|
76051
|
+
if (atStart) {
|
|
76052
|
+
baseScore = SCORE_PHRASE_AT_START;
|
|
76053
|
+
} else if (atWordBoundary) {
|
|
76054
|
+
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
76055
|
+
} else {
|
|
76056
|
+
baseScore = SCORE_MID_WORD;
|
|
76057
|
+
}
|
|
76058
|
+
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
76059
|
+
return { match: true, matchScore, matchRanges: mergeRanges(phraseRanges) };
|
|
76060
|
+
}
|
|
76061
|
+
|
|
76062
|
+
// Multi-word OR: split on whitespace, any word matching contributes to the score.
|
|
76063
|
+
// Items where all words match rank higher than partial matches.
|
|
76064
|
+
// Note: words always has at least 1 element here (searchText is non-empty and
|
|
76065
|
+
// foldedSearch.split filters empty strings). This path also handles the case
|
|
76066
|
+
// where searchText has trailing/leading spaces: the phrase match above tries
|
|
76067
|
+
// the literal (e.g. "tc " in "tc adapter"), and if that fails we fall through
|
|
76068
|
+
// here to try each word individually (e.g. "tc" matches "tca").
|
|
76069
|
+
const matchRanges = [];
|
|
76070
|
+
let matchedWordCount = 0;
|
|
76071
|
+
let anyWordAtStart = false;
|
|
76072
|
+
let anyWordAtWordBoundary = false;
|
|
76073
|
+
let allMatchedWordsExact = true;
|
|
76074
|
+
for (let w = 0; w < words.length; w++) {
|
|
76075
|
+
const word = words[w];
|
|
76076
|
+
const originalWord = originalWords[w];
|
|
76077
|
+
let idx = foldedStr.indexOf(word);
|
|
76078
|
+
if (idx === -1) {
|
|
76079
|
+
continue;
|
|
76080
|
+
}
|
|
76081
|
+
matchedWordCount++;
|
|
76082
|
+
let wordHasExactMatch = false;
|
|
76083
|
+
while (idx !== -1) {
|
|
76084
|
+
matchRanges.push([idx, idx + word.length]);
|
|
76085
|
+
if (idx === 0) {
|
|
76086
|
+
anyWordAtStart = true;
|
|
76087
|
+
anyWordAtWordBoundary = true;
|
|
76088
|
+
} else if (isWordBoundary(foldedStr, idx)) {
|
|
76089
|
+
anyWordAtWordBoundary = true;
|
|
76090
|
+
}
|
|
76091
|
+
if (str.slice(idx, idx + word.length) === originalWord) {
|
|
76092
|
+
wordHasExactMatch = true;
|
|
76093
|
+
}
|
|
76094
|
+
idx = foldedStr.indexOf(word, idx + 1);
|
|
76095
|
+
}
|
|
76096
|
+
if (!wordHasExactMatch) {
|
|
76097
|
+
allMatchedWordsExact = false;
|
|
76098
|
+
}
|
|
76099
|
+
}
|
|
76100
|
+
if (matchedWordCount === 0) {
|
|
76101
|
+
return tryAcronymMatch(foldedStr, str, searchText);
|
|
76102
|
+
}
|
|
76103
|
+
const wordRatio = matchedWordCount / words.length;
|
|
76104
|
+
let baseScore;
|
|
76105
|
+
if (anyWordAtStart) {
|
|
76106
|
+
baseScore = SCORE_MULTI_WORD_AT_START;
|
|
76107
|
+
} else if (anyWordAtWordBoundary) {
|
|
76108
|
+
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
76109
|
+
} else {
|
|
76110
|
+
baseScore = SCORE_MID_WORD;
|
|
76111
|
+
}
|
|
76112
|
+
const matchScore =
|
|
76113
|
+
(baseScore + (allMatchedWordsExact ? SCORE_BONUS_CASE_EXACT : 0)) *
|
|
76114
|
+
wordRatio;
|
|
76115
|
+
return { match: true, matchScore, matchRanges: mergeRanges(matchRanges) };
|
|
76116
|
+
};
|
|
76117
|
+
|
|
76118
|
+
// Returns true when position idx in str is at a word boundary,
|
|
76119
|
+
// meaning it is either the start of the string or the preceding character
|
|
76120
|
+
// is not a Unicode letter or digit.
|
|
76121
|
+
const isWordBoundary = (str, idx) => {
|
|
76122
|
+
if (idx === 0) {
|
|
76123
|
+
return true;
|
|
76124
|
+
}
|
|
76125
|
+
return !/[\p{L}\p{N}]/u.test(str[idx - 1]);
|
|
76126
|
+
};
|
|
76127
|
+
|
|
76128
|
+
// Strip diacritics for accent-insensitive matching.
|
|
76129
|
+
// NFC normalization first ensures precomposed characters (é → single code unit),
|
|
76130
|
+
// so the folded string has the same length as the NFC source — ranges computed
|
|
76131
|
+
// on the folded string map 1:1 to positions in the original string.
|
|
76132
|
+
const foldAccents = (str) => {
|
|
76133
|
+
return str
|
|
76134
|
+
.normalize("NFC")
|
|
76135
|
+
.normalize("NFD")
|
|
76136
|
+
.replace(/\p{Mn}/gu, "");
|
|
76137
|
+
};
|
|
76138
|
+
|
|
76139
|
+
const SCORE_PHRASE_AT_START = 1;
|
|
76140
|
+
const SCORE_MULTI_WORD_AT_START = 0.75;
|
|
76141
|
+
const SCORE_AT_WORD_BOUNDARY = 0.625;
|
|
76142
|
+
const SCORE_MID_WORD = 0.5;
|
|
76143
|
+
const SCORE_ACRONYM = 0.4;
|
|
76144
|
+
const SCORE_BONUS_CASE_EXACT = 0.125;
|
|
76145
|
+
|
|
76146
|
+
// Acronym match: each char of searchText (spaces stripped) must be the first
|
|
76147
|
+
// letter of a word in value, in order (greedy subsequence on word-starts).
|
|
76148
|
+
// e.g. "TC" matches "Total Count" highlighting the T and C.
|
|
76149
|
+
const tryAcronymMatch = (foldedStr, str, searchText) => {
|
|
76150
|
+
const acronymChars = foldAccents(searchText).toLowerCase().replace(/\s/g, "");
|
|
76151
|
+
if (acronymChars.length < 2) {
|
|
76152
|
+
// Single-char acronym is too ambiguous — skip.
|
|
76153
|
+
return { match: false, matchScore: 0, matchRanges: [] };
|
|
76154
|
+
}
|
|
76155
|
+
const wordStarts = [];
|
|
76156
|
+
for (let i = 0; i < foldedStr.length; i++) {
|
|
76157
|
+
if (isWordBoundary(foldedStr, i)) {
|
|
76158
|
+
wordStarts.push(i);
|
|
76159
|
+
}
|
|
76160
|
+
}
|
|
76161
|
+
const matchedPositions = [];
|
|
76162
|
+
let wordIdx = 0;
|
|
76163
|
+
const originalAcronym = searchText.replace(/\s/g, "");
|
|
76164
|
+
for (let si = 0; si < acronymChars.length; si++) {
|
|
76165
|
+
const ch = acronymChars[si];
|
|
76166
|
+
let found = false;
|
|
76167
|
+
while (wordIdx < wordStarts.length) {
|
|
76168
|
+
const pos = wordStarts[wordIdx];
|
|
76169
|
+
wordIdx++;
|
|
76170
|
+
if (foldedStr[pos] === ch) {
|
|
76171
|
+
matchedPositions.push(pos);
|
|
76172
|
+
found = true;
|
|
76173
|
+
break;
|
|
76174
|
+
}
|
|
76175
|
+
}
|
|
76176
|
+
if (!found) {
|
|
76177
|
+
return { match: false, matchScore: 0, matchRanges: [] };
|
|
76178
|
+
}
|
|
76179
|
+
}
|
|
76180
|
+
const atStart = matchedPositions[0] === 0;
|
|
76181
|
+
const caseExact = matchedPositions.every(
|
|
76182
|
+
(p, i) => str[p] === originalAcronym[i],
|
|
76183
|
+
);
|
|
76184
|
+
const baseScore = atStart ? SCORE_ACRONYM + 0.05 : SCORE_ACRONYM;
|
|
76185
|
+
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
76186
|
+
const matchRanges = matchedPositions.map((p) => [p, p + 1]);
|
|
76187
|
+
return { match: true, matchScore, matchRanges };
|
|
76188
|
+
};
|
|
76189
|
+
|
|
76190
|
+
// LRU cache for pre-computed search info, avoids recomputing foldAccents/toLowerCase
|
|
76191
|
+
// for the same searchText across all items in a list render.
|
|
76192
|
+
const searchCache = new Map();
|
|
76193
|
+
const SEARCH_CACHE_MAX_SIZE = 20;
|
|
76194
|
+
const getSearchInfo = (searchText) => {
|
|
76195
|
+
if (searchCache.has(searchText)) {
|
|
76196
|
+
const cached = searchCache.get(searchText);
|
|
76197
|
+
searchCache.delete(searchText);
|
|
76198
|
+
searchCache.set(searchText, cached);
|
|
76199
|
+
return cached;
|
|
76200
|
+
}
|
|
76201
|
+
const foldedSearch = foldAccents(searchText).toLowerCase();
|
|
76202
|
+
const words = foldedSearch.split(/\s+/).filter(Boolean);
|
|
76203
|
+
const originalWords = searchText.split(/\s+/).filter(Boolean);
|
|
76204
|
+
const info = { foldedSearch, words, originalWords };
|
|
76205
|
+
searchCache.set(searchText, info);
|
|
76206
|
+
if (searchCache.size > SEARCH_CACHE_MAX_SIZE) {
|
|
76207
|
+
searchCache.delete(searchCache.keys().next().value);
|
|
76208
|
+
}
|
|
76209
|
+
return info;
|
|
76210
|
+
};
|
|
76211
|
+
|
|
76212
|
+
// Merge overlapping or adjacent [start, end] ranges (sorted by start).
|
|
76213
|
+
const mergeRanges = (ranges) => {
|
|
76214
|
+
if (ranges.length < 2) {
|
|
76215
|
+
return ranges;
|
|
76216
|
+
}
|
|
76217
|
+
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
76218
|
+
const merged = [sorted[0]];
|
|
76219
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
76220
|
+
const last = merged[merged.length - 1];
|
|
76221
|
+
const current = sorted[i];
|
|
76222
|
+
if (current[0] <= last[1]) {
|
|
76223
|
+
if (current[1] > last[1]) {
|
|
76224
|
+
last[1] = current[1];
|
|
76225
|
+
}
|
|
76226
|
+
} else {
|
|
76227
|
+
merged.push(current);
|
|
76228
|
+
}
|
|
76229
|
+
}
|
|
76230
|
+
return merged;
|
|
76231
|
+
};
|
|
76232
|
+
|
|
76233
|
+
/**
|
|
76234
|
+
* createSearch — builds a matchFn compatible with useSearch that searches
|
|
76235
|
+
* across multiple named fields of an item, each with its own DOM selector
|
|
76236
|
+
* and optional priority weight.
|
|
76237
|
+
*
|
|
76238
|
+
* Usage:
|
|
76239
|
+
* ```js
|
|
76240
|
+
* const searchPerson = createSearch({
|
|
76241
|
+
* name: {
|
|
76242
|
+
* getter: (item) => item.name,
|
|
76243
|
+
* domSelector: ".name",
|
|
76244
|
+
* },
|
|
76245
|
+
* address: {
|
|
76246
|
+
* getter: (item) => item.address,
|
|
76247
|
+
* domSelector: ".address",
|
|
76248
|
+
* priority: 1.5,
|
|
76249
|
+
* },
|
|
76250
|
+
* });
|
|
76251
|
+
*
|
|
76252
|
+
* const [orderedItems, getItemMatchInfo] = useSearch(search, items, searchPerson);
|
|
76253
|
+
* // getItemMatchInfo(item).matchRanges is { ".name": [[start,end],…], ".address": [[start,end],…] }
|
|
76254
|
+
* // Pass the whole thing: <ListItem matchInfo={getItemMatchInfo(item)} />
|
|
76255
|
+
* // — ListItem handles the per-selector object format for matchRanges.
|
|
76256
|
+
* ```
|
|
76257
|
+
*
|
|
76258
|
+
* Each field config:
|
|
76259
|
+
* - getter(item): string — extracts the text to search
|
|
76260
|
+
* - domSelector: string — CSS selector used by ListItem to find the target element
|
|
76261
|
+
* - priority?: number — multiplier applied to the field's score (default 1)
|
|
76262
|
+
* - matchFn?: function — custom match function (searchText, fieldValue) => { match, matchScore, matchRanges }
|
|
76263
|
+
* defaults to applySearch
|
|
76264
|
+
*/
|
|
76265
|
+
const createSearch = (fields) => {
|
|
76266
|
+
return (searchText, item) => {
|
|
76267
|
+
if (!searchText) {
|
|
76268
|
+
return { match: true, matchScore: 0, matchRanges: {} };
|
|
76269
|
+
}
|
|
76270
|
+
let totalScore = 0;
|
|
76271
|
+
const matchRanges = {};
|
|
76272
|
+
for (const [
|
|
76273
|
+
,
|
|
76274
|
+
{ getter, domSelector, priority = 1, matchFn = applySearch },
|
|
76275
|
+
] of Object.entries(fields)) {
|
|
76276
|
+
const fieldValue = getter(item);
|
|
76277
|
+
const result = matchFn(searchText, fieldValue);
|
|
76278
|
+
if (result.match && result.matchRanges.length > 0) {
|
|
76279
|
+
totalScore += result.matchScore * priority;
|
|
76280
|
+
matchRanges[domSelector] = result.matchRanges;
|
|
76281
|
+
}
|
|
76282
|
+
}
|
|
76283
|
+
if (totalScore === 0) {
|
|
76284
|
+
return { match: false, matchScore: 0, matchRanges: {} };
|
|
76285
|
+
}
|
|
76286
|
+
return { match: true, matchScore: totalScore, matchRanges };
|
|
76287
|
+
};
|
|
76288
|
+
};
|
|
76289
|
+
|
|
76290
|
+
/**
|
|
76291
|
+
* useSearch — reorders items so matched ones come first (sorted by score desc),
|
|
76292
|
+
* followed by non-matched items in their natural order. No item is hidden.
|
|
76293
|
+
* Returns [orderedItems, getItemMatchInfo].
|
|
76294
|
+
* - orderedItems: all items, reordered
|
|
76295
|
+
* - getItemMatchInfo(item): { match, matchScore, matchRanges } — pass the
|
|
76296
|
+
* whole thing straight to <ListItem matchInfo={getItemMatchInfo(item)} />,
|
|
76297
|
+
* there is no need to destructure the three fields by hand.
|
|
76298
|
+
*
|
|
76299
|
+
* When searchText is empty, natural order is preserved and all items match with score 0.
|
|
76300
|
+
*
|
|
76301
|
+
* To filter (hide non-matching items), pass filtered={!getItemMatchInfo(item).match}
|
|
76302
|
+
* to each ListItem. The list's matchFallback will be shown when all items are hidden.
|
|
76303
|
+
*/
|
|
76304
|
+
const useSearchText = (searchText, items, matchFn = applySearch) => {
|
|
76305
|
+
if (typeof searchText !== "string" && searchText !== undefined) {
|
|
76306
|
+
throw new TypeError(
|
|
76307
|
+
"useSearchText: searchText must be a string or undefined",
|
|
76308
|
+
);
|
|
76309
|
+
}
|
|
76310
|
+
if (items === undefined) {
|
|
76311
|
+
throw new TypeError("useSearch: items is undefined");
|
|
76312
|
+
}
|
|
76313
|
+
const { orderedItems, matchInfoMap } = useMemo(() => {
|
|
76314
|
+
const { scoreEntries, nonMatched, matchInfoMap } = buildMatchInfo(
|
|
76315
|
+
searchText,
|
|
76316
|
+
items,
|
|
76317
|
+
matchFn,
|
|
76318
|
+
);
|
|
76319
|
+
const orderedItems = [];
|
|
76320
|
+
for (const [, bucket] of scoreEntries) {
|
|
76321
|
+
for (const { item } of bucket) {
|
|
76322
|
+
orderedItems.push(item);
|
|
76323
|
+
}
|
|
76324
|
+
}
|
|
76325
|
+
for (const { item } of nonMatched) {
|
|
76326
|
+
orderedItems.push(item);
|
|
76327
|
+
}
|
|
76328
|
+
return { orderedItems, matchInfoMap };
|
|
76329
|
+
}, [items, searchText, matchFn]);
|
|
76330
|
+
|
|
76331
|
+
// The same function for as long as the map is the same: a `renderItem`
|
|
76332
|
+
// reading it is stable only if this is, and a run keeps the rows it drew
|
|
76333
|
+
// only for a stable `renderItem` (see List.Items).
|
|
76334
|
+
const getItemMatchInfo = useCallback(
|
|
76335
|
+
(item) => matchInfoMap.get(item),
|
|
76336
|
+
[matchInfoMap],
|
|
76337
|
+
);
|
|
76338
|
+
|
|
76339
|
+
return [orderedItems, getItemMatchInfo];
|
|
76340
|
+
};
|
|
76341
|
+
|
|
76342
|
+
const buildMatchInfo = (searchText, items, matchFn) => {
|
|
76343
|
+
// scoreEntries: [score, bucket][] kept sorted desc by score.
|
|
76344
|
+
// New distinct score values are inserted via bisect — O(1) in practice
|
|
76345
|
+
// since there are very few distinct scores (today just 0 and 1).
|
|
76346
|
+
const scoreEntries = []; // [score, bucket][]
|
|
76347
|
+
const nonMatched = [];
|
|
76348
|
+
|
|
76349
|
+
for (const item of items) {
|
|
76350
|
+
const result = matchFn(searchText, item);
|
|
76351
|
+
if (!result.match) {
|
|
76352
|
+
nonMatched.push({
|
|
76353
|
+
item,
|
|
76354
|
+
matchScore: result.matchScore,
|
|
76355
|
+
matchRanges: result.matchRanges,
|
|
76356
|
+
});
|
|
76357
|
+
continue;
|
|
76358
|
+
}
|
|
76359
|
+
const score = result.matchScore;
|
|
76360
|
+
// Find existing bucket or insert a new entry in desc order.
|
|
76361
|
+
let lo = 0;
|
|
76362
|
+
let hi = scoreEntries.length;
|
|
76363
|
+
while (lo < hi) {
|
|
76364
|
+
const mid = (lo + hi) >> 1;
|
|
76365
|
+
if (scoreEntries[mid][0] > score) {
|
|
76366
|
+
lo = mid + 1;
|
|
76367
|
+
} else if (scoreEntries[mid][0] < score) {
|
|
76368
|
+
hi = mid;
|
|
76369
|
+
} else {
|
|
76370
|
+
lo = mid;
|
|
76371
|
+
hi = mid; // exact match — found the bucket
|
|
76372
|
+
}
|
|
76373
|
+
}
|
|
76374
|
+
if (lo < scoreEntries.length && scoreEntries[lo][0] === score) {
|
|
76375
|
+
scoreEntries[lo][1].push({ item, matchRanges: result.matchRanges });
|
|
76207
76376
|
} else {
|
|
76208
|
-
|
|
76377
|
+
scoreEntries.splice(lo, 0, [
|
|
76378
|
+
score,
|
|
76379
|
+
[{ item, matchRanges: result.matchRanges }],
|
|
76380
|
+
]);
|
|
76209
76381
|
}
|
|
76210
76382
|
}
|
|
76211
|
-
|
|
76383
|
+
|
|
76384
|
+
const matchInfoMap = new Map();
|
|
76385
|
+
for (const [score, bucket] of scoreEntries) {
|
|
76386
|
+
for (const { item, matchRanges } of bucket) {
|
|
76387
|
+
matchInfoMap.set(item, { match: true, matchScore: score, matchRanges });
|
|
76388
|
+
}
|
|
76389
|
+
}
|
|
76390
|
+
for (const { item, matchScore, matchRanges } of nonMatched) {
|
|
76391
|
+
matchInfoMap.set(item, { match: false, matchScore, matchRanges });
|
|
76392
|
+
}
|
|
76393
|
+
|
|
76394
|
+
return { scoreEntries, nonMatched, matchInfoMap };
|
|
76212
76395
|
};
|
|
76213
76396
|
|
|
76214
|
-
|
|
76215
|
-
*
|
|
76397
|
+
/*
|
|
76398
|
+
* useItemTracker() — hook that creates a stable item tracker for the lifetime
|
|
76399
|
+
* of the host component.
|
|
76216
76400
|
*
|
|
76217
|
-
*
|
|
76218
|
-
*
|
|
76219
|
-
*
|
|
76220
|
-
*
|
|
76401
|
+
* USAGE:
|
|
76402
|
+
* ```jsx
|
|
76403
|
+
* function ListControlled({ items }) {
|
|
76404
|
+
* const tracker = useItemTracker({
|
|
76405
|
+
* onChange: () => console.log("items changed"),
|
|
76406
|
+
* });
|
|
76221
76407
|
*
|
|
76222
|
-
*
|
|
76408
|
+
* return (
|
|
76409
|
+
* <ul>
|
|
76410
|
+
* {items.map((item, i) => (
|
|
76411
|
+
* <Row key={item.id} id={item.id} index={i} hidden={item.hidden} value={item.value} tracker={tracker} />
|
|
76412
|
+
* ))}
|
|
76413
|
+
* <Count tracker={tracker} />
|
|
76414
|
+
* </ul>
|
|
76415
|
+
* );
|
|
76416
|
+
* }
|
|
76223
76417
|
*
|
|
76224
|
-
*
|
|
76225
|
-
*
|
|
76226
|
-
*
|
|
76227
|
-
*
|
|
76228
|
-
*
|
|
76229
|
-
* phrase / words mid-word 0.5
|
|
76230
|
-
* + case-exact bonus +0.125
|
|
76231
|
-
* multi-word partial: score × (matched/total)
|
|
76418
|
+
* function Row({ id, index, hidden, value, tracker }) {
|
|
76419
|
+
* const visibleIndex = tracker.useTrackItem({ id, index, hidden, value });
|
|
76420
|
+
* if (visibleIndex === -1) return null;
|
|
76421
|
+
* return <li>{value}</li>;
|
|
76422
|
+
* }
|
|
76232
76423
|
*
|
|
76233
|
-
*
|
|
76234
|
-
*
|
|
76424
|
+
* function Count({ tracker }) {
|
|
76425
|
+
* const count = tracker.visibleCountSignal.value; // re-renders only when count changes
|
|
76426
|
+
* return <span>{count} items</span>;
|
|
76427
|
+
* }
|
|
76428
|
+
* ```
|
|
76429
|
+
*
|
|
76430
|
+
* INTERNALS:
|
|
76431
|
+
* - registrations: Map key → data, contains only visible items
|
|
76432
|
+
* - idToKey: Map id → key, stable across renders
|
|
76433
|
+
* - orderedKeys: number[] of visible item keys sorted by explicit order
|
|
76434
|
+
* - keyToOrderedIndex: Map key → orderedKeys index, gives O(1) indexOf equivalent
|
|
76435
|
+
* - keyToExplicitOrder: Map key → explicitly passed index, used to maintain sort order
|
|
76436
|
+
* - allItemsSignal: signal(array), all items including hidden, ordered by explicit index
|
|
76437
|
+
* - visibleItemsSignal: signal(array), non-hidden items only
|
|
76438
|
+
* - countSignal: signal(number), count of all items including hidden
|
|
76439
|
+
* - visibleCountSignal: signal(number), updated in microtask batch, only when count changes
|
|
76440
|
+
* - propSignals: Map propName → signal(array), updated in microtask batch with element equality
|
|
76441
|
+
* - onChangeRef: holds the latest onChange callback, called once per microtask batch
|
|
76442
|
+
*
|
|
76443
|
+
* useTrackItem(id, data, index): registers the item with an explicitly provided index
|
|
76444
|
+
* that determines its position among siblings. The caller (e.g. items.map) knows the
|
|
76445
|
+
* correct order and passes it directly — no render-sequence deduction needed.
|
|
76446
|
+
* Returns the visible rank (position among non-hidden items), or -1 when hidden.
|
|
76447
|
+
* Signals and onChange are deferred to a microtask so multiple items updating
|
|
76448
|
+
* in one commit cause only one notification.
|
|
76449
|
+
*
|
|
76450
|
+
* getTrackedItemByIndex(index): synchronous O(1) lookup of a visible item by
|
|
76451
|
+
* its visible rank. Returns undefined when index is out of range.
|
|
76452
|
+
*
|
|
76453
|
+
* peekItems(): the items as they stand right now, without waiting for the
|
|
76454
|
+
* deferred notification — what a sibling rendering after the items must read
|
|
76455
|
+
* to paint them in the same commit.
|
|
76235
76456
|
*/
|
|
76236
|
-
const applySearch = (searchText, value) => {
|
|
76237
|
-
if (!searchText) {
|
|
76238
|
-
return { match: true, matchScore: 0, matchRanges: [] };
|
|
76239
|
-
}
|
|
76240
|
-
if (searchText.length > 100) {
|
|
76241
|
-
searchText = searchText.slice(0, 100);
|
|
76242
|
-
}
|
|
76243
|
-
const str = String(value);
|
|
76244
|
-
const foldedStr = foldAccents(str).toLowerCase();
|
|
76245
|
-
const { foldedSearch, words, originalWords } = getSearchInfo(searchText);
|
|
76246
76457
|
|
|
76247
|
-
|
|
76248
|
-
const
|
|
76249
|
-
|
|
76250
|
-
|
|
76251
|
-
|
|
76252
|
-
|
|
76253
|
-
|
|
76254
|
-
|
|
76255
|
-
|
|
76256
|
-
const atWordBoundary = phraseRanges.some(([start]) =>
|
|
76257
|
-
isWordBoundary(foldedStr, start),
|
|
76258
|
-
);
|
|
76259
|
-
const caseExact = str.includes(searchText);
|
|
76260
|
-
let baseScore;
|
|
76261
|
-
if (atStart) {
|
|
76262
|
-
baseScore = SCORE_PHRASE_AT_START;
|
|
76263
|
-
} else if (atWordBoundary) {
|
|
76264
|
-
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
76265
|
-
} else {
|
|
76266
|
-
baseScore = SCORE_MID_WORD;
|
|
76267
|
-
}
|
|
76268
|
-
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
76269
|
-
return { match: true, matchScore, matchRanges: mergeRanges(phraseRanges) };
|
|
76458
|
+
const useItemTracker = ({ onChange } = {}) => {
|
|
76459
|
+
const onChangeRef = useRef(onChange);
|
|
76460
|
+
onChangeRef.current = onChange;
|
|
76461
|
+
const trackerRef = useRef(null);
|
|
76462
|
+
let tracker = trackerRef.current;
|
|
76463
|
+
if (!tracker) {
|
|
76464
|
+
trackerRef.current = tracker = createItemTracker((items) => {
|
|
76465
|
+
onChangeRef.current?.(items);
|
|
76466
|
+
});
|
|
76270
76467
|
}
|
|
76468
|
+
// When code in useLayoutEffect of the caller wants to run the tracker must be in sync
|
|
76469
|
+
// without this layout effect the tracker might not have been synced yet and preact would call layout effect
|
|
76470
|
+
// before we had time to sync
|
|
76471
|
+
useLayoutEffect(() => {
|
|
76472
|
+
tracker._flushSync();
|
|
76473
|
+
});
|
|
76474
|
+
return tracker;
|
|
76475
|
+
};
|
|
76476
|
+
|
|
76477
|
+
const createItemTracker = (onChange) => {
|
|
76478
|
+
const registrations = new Map(); // key → data (visible items only)
|
|
76479
|
+
const idToKey = new Map(); // id → insertion key (stable, auto-incremented)
|
|
76480
|
+
let keyCounter = 0;
|
|
76481
|
+
// orderedKeys: visible item keys sorted by their explicitly provided index.
|
|
76482
|
+
const orderedKeys = []; // number[]
|
|
76483
|
+
// keyToOrderedIndex: O(1) equivalent of orderedKeys.indexOf(key).
|
|
76484
|
+
const keyToOrderedIndex = new Map(); // key → index in orderedKeys
|
|
76485
|
+
const allKeys = new Set(); // all registered keys including hidden
|
|
76486
|
+
const keyToExplicitOrder = new Map(); // key → explicitly passed index
|
|
76487
|
+
|
|
76488
|
+
const allRegistrations = new Map(); // key → data (all items including hidden)
|
|
76489
|
+
const allOrderedKeys = []; // all item keys sorted by explicit order
|
|
76490
|
+
const keyToAllOrderedIndex = new Map(); // key → index in allOrderedKeys
|
|
76491
|
+
|
|
76492
|
+
const itemsSignal = signal([]);
|
|
76493
|
+
const visibleItemsSignal = signal([]);
|
|
76494
|
+
const countSignal = signal(0);
|
|
76495
|
+
const visibleCountSignal = signal(0);
|
|
76496
|
+
const noMatchCountSignal = signal(0);
|
|
76497
|
+
|
|
76498
|
+
let notifyScheduled = false;
|
|
76499
|
+
const runNotify = () => {
|
|
76500
|
+
batch(() => {
|
|
76501
|
+
let someChange = false;
|
|
76502
|
+
|
|
76503
|
+
const newCount = allKeys.size;
|
|
76504
|
+
const countModified = countSignal.peek() !== newCount;
|
|
76505
|
+
if (countModified) {
|
|
76506
|
+
countSignal.value = newCount;
|
|
76507
|
+
someChange = true;
|
|
76508
|
+
}
|
|
76509
|
+
|
|
76510
|
+
// Build allItems and visibleItems in a single pass over allOrderedKeys.
|
|
76511
|
+
// Visible items are those without data.hidden or data.filtered — same
|
|
76512
|
+
// relative order as orderedKeys (syncItem already excludes both from
|
|
76513
|
+
// orderedKeys; this must match or consumers relying on visibleCountSignal
|
|
76514
|
+
// would count filtered-out items as if they still took up space).
|
|
76515
|
+
const prevAllItems = itemsSignal.peek();
|
|
76516
|
+
const prevVisibleItems = visibleItemsSignal.peek();
|
|
76517
|
+
let allItemsChanged = prevAllItems.length !== allOrderedKeys.length;
|
|
76518
|
+
let visibleItemsChanged = false;
|
|
76519
|
+
const allItems = [];
|
|
76520
|
+
const visibleItems = [];
|
|
76521
|
+
let newNoMatchCount = 0;
|
|
76522
|
+
for (let i = 0; i < allOrderedKeys.length; i++) {
|
|
76523
|
+
const key = allOrderedKeys[i];
|
|
76524
|
+
const item = allRegistrations.get(key);
|
|
76525
|
+
allItems.push(item);
|
|
76526
|
+
// Compare by reference: catches any prop change (id, selected, disabled, …)
|
|
76527
|
+
if (!allItemsChanged && item !== prevAllItems[i]) {
|
|
76528
|
+
allItemsChanged = true;
|
|
76529
|
+
}
|
|
76530
|
+
if (item.match === false) {
|
|
76531
|
+
newNoMatchCount++;
|
|
76532
|
+
}
|
|
76533
|
+
if (!item.hidden && !item.filtered) {
|
|
76534
|
+
const visibleIdx = visibleItems.length;
|
|
76535
|
+
visibleItems.push(item);
|
|
76536
|
+
if (!visibleItemsChanged && item !== prevVisibleItems[visibleIdx]) {
|
|
76537
|
+
visibleItemsChanged = true;
|
|
76538
|
+
}
|
|
76539
|
+
}
|
|
76540
|
+
}
|
|
76541
|
+
|
|
76542
|
+
const newVisibleCount = visibleItems.length;
|
|
76543
|
+
const visibleCountModified =
|
|
76544
|
+
visibleCountSignal.peek() !== newVisibleCount;
|
|
76545
|
+
if (visibleCountModified) {
|
|
76546
|
+
visibleCountSignal.value = newVisibleCount;
|
|
76547
|
+
someChange = true;
|
|
76548
|
+
}
|
|
76549
|
+
if (allItemsChanged) {
|
|
76550
|
+
itemsSignal.value = allItems;
|
|
76551
|
+
someChange = true;
|
|
76552
|
+
}
|
|
76553
|
+
if (visibleItemsChanged) {
|
|
76554
|
+
visibleItemsSignal.value = visibleItems;
|
|
76555
|
+
someChange = true;
|
|
76556
|
+
}
|
|
76557
|
+
const noMatchCountModified =
|
|
76558
|
+
noMatchCountSignal.peek() !== newNoMatchCount;
|
|
76559
|
+
if (noMatchCountModified) {
|
|
76560
|
+
noMatchCountSignal.value = newNoMatchCount;
|
|
76561
|
+
someChange = true;
|
|
76562
|
+
}
|
|
76563
|
+
if (someChange) {
|
|
76564
|
+
onChange?.();
|
|
76565
|
+
}
|
|
76566
|
+
});
|
|
76567
|
+
};
|
|
76271
76568
|
|
|
76272
|
-
|
|
76273
|
-
|
|
76274
|
-
|
|
76275
|
-
// foldedSearch.split filters empty strings). This path also handles the case
|
|
76276
|
-
// where searchText has trailing/leading spaces: the phrase match above tries
|
|
76277
|
-
// the literal (e.g. "tc " in "tc adapter"), and if that fails we fall through
|
|
76278
|
-
// here to try each word individually (e.g. "tc" matches "tca").
|
|
76279
|
-
const matchRanges = [];
|
|
76280
|
-
let matchedWordCount = 0;
|
|
76281
|
-
let anyWordAtStart = false;
|
|
76282
|
-
let anyWordAtWordBoundary = false;
|
|
76283
|
-
let allMatchedWordsExact = true;
|
|
76284
|
-
for (let w = 0; w < words.length; w++) {
|
|
76285
|
-
const word = words[w];
|
|
76286
|
-
const originalWord = originalWords[w];
|
|
76287
|
-
let idx = foldedStr.indexOf(word);
|
|
76288
|
-
if (idx === -1) {
|
|
76289
|
-
continue;
|
|
76569
|
+
const notify = () => {
|
|
76570
|
+
if (notifyScheduled) {
|
|
76571
|
+
return;
|
|
76290
76572
|
}
|
|
76291
|
-
|
|
76292
|
-
|
|
76293
|
-
|
|
76294
|
-
|
|
76295
|
-
if (idx === 0) {
|
|
76296
|
-
anyWordAtStart = true;
|
|
76297
|
-
anyWordAtWordBoundary = true;
|
|
76298
|
-
} else if (isWordBoundary(foldedStr, idx)) {
|
|
76299
|
-
anyWordAtWordBoundary = true;
|
|
76573
|
+
notifyScheduled = true;
|
|
76574
|
+
queueMicrotask(() => {
|
|
76575
|
+
if (!notifyScheduled) {
|
|
76576
|
+
return; // was already flushed synchronously
|
|
76300
76577
|
}
|
|
76301
|
-
|
|
76302
|
-
|
|
76578
|
+
notifyScheduled = false;
|
|
76579
|
+
runNotify();
|
|
76580
|
+
});
|
|
76581
|
+
};
|
|
76582
|
+
|
|
76583
|
+
const _flushSync = () => {
|
|
76584
|
+
if (!notifyScheduled) {
|
|
76585
|
+
return;
|
|
76586
|
+
}
|
|
76587
|
+
notifyScheduled = false;
|
|
76588
|
+
runNotify();
|
|
76589
|
+
};
|
|
76590
|
+
|
|
76591
|
+
// Insert key into orderedKeys at the correct position based on explicitOrder.
|
|
76592
|
+
// Uses binary search for O(log n) insertion.
|
|
76593
|
+
const insertKey = (key, explicitOrder) => {
|
|
76594
|
+
let lo = 0;
|
|
76595
|
+
let hi = orderedKeys.length;
|
|
76596
|
+
while (lo < hi) {
|
|
76597
|
+
const mid = (lo + hi) >> 1;
|
|
76598
|
+
if (keyToExplicitOrder.get(orderedKeys[mid]) <= explicitOrder) {
|
|
76599
|
+
lo = mid + 1;
|
|
76600
|
+
} else {
|
|
76601
|
+
hi = mid;
|
|
76303
76602
|
}
|
|
76304
|
-
idx = foldedStr.indexOf(word, idx + 1);
|
|
76305
76603
|
}
|
|
76306
|
-
|
|
76307
|
-
|
|
76604
|
+
orderedKeys.splice(lo, 0, key);
|
|
76605
|
+
for (let i = lo; i < orderedKeys.length; i++) {
|
|
76606
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
76308
76607
|
}
|
|
76309
|
-
}
|
|
76310
|
-
if (matchedWordCount === 0) {
|
|
76311
|
-
return tryAcronymMatch(foldedStr, str, searchText);
|
|
76312
|
-
}
|
|
76313
|
-
const wordRatio = matchedWordCount / words.length;
|
|
76314
|
-
let baseScore;
|
|
76315
|
-
if (anyWordAtStart) {
|
|
76316
|
-
baseScore = SCORE_MULTI_WORD_AT_START;
|
|
76317
|
-
} else if (anyWordAtWordBoundary) {
|
|
76318
|
-
baseScore = SCORE_AT_WORD_BOUNDARY;
|
|
76319
|
-
} else {
|
|
76320
|
-
baseScore = SCORE_MID_WORD;
|
|
76321
|
-
}
|
|
76322
|
-
const matchScore =
|
|
76323
|
-
(baseScore + (allMatchedWordsExact ? SCORE_BONUS_CASE_EXACT : 0)) *
|
|
76324
|
-
wordRatio;
|
|
76325
|
-
return { match: true, matchScore, matchRanges: mergeRanges(matchRanges) };
|
|
76326
|
-
};
|
|
76327
|
-
|
|
76328
|
-
// Returns true when position idx in str is at a word boundary,
|
|
76329
|
-
// meaning it is either the start of the string or the preceding character
|
|
76330
|
-
// is not a Unicode letter or digit.
|
|
76331
|
-
const isWordBoundary = (str, idx) => {
|
|
76332
|
-
if (idx === 0) {
|
|
76333
|
-
return true;
|
|
76334
|
-
}
|
|
76335
|
-
return !/[\p{L}\p{N}]/u.test(str[idx - 1]);
|
|
76336
|
-
};
|
|
76337
|
-
|
|
76338
|
-
// Strip diacritics for accent-insensitive matching.
|
|
76339
|
-
// NFC normalization first ensures precomposed characters (é → single code unit),
|
|
76340
|
-
// so the folded string has the same length as the NFC source — ranges computed
|
|
76341
|
-
// on the folded string map 1:1 to positions in the original string.
|
|
76342
|
-
const foldAccents = (str) => {
|
|
76343
|
-
return str
|
|
76344
|
-
.normalize("NFC")
|
|
76345
|
-
.normalize("NFD")
|
|
76346
|
-
.replace(/\p{Mn}/gu, "");
|
|
76347
|
-
};
|
|
76348
|
-
|
|
76349
|
-
const SCORE_PHRASE_AT_START = 1;
|
|
76350
|
-
const SCORE_MULTI_WORD_AT_START = 0.75;
|
|
76351
|
-
const SCORE_AT_WORD_BOUNDARY = 0.625;
|
|
76352
|
-
const SCORE_MID_WORD = 0.5;
|
|
76353
|
-
const SCORE_ACRONYM = 0.4;
|
|
76354
|
-
const SCORE_BONUS_CASE_EXACT = 0.125;
|
|
76608
|
+
};
|
|
76355
76609
|
|
|
76356
|
-
|
|
76357
|
-
|
|
76358
|
-
|
|
76359
|
-
|
|
76360
|
-
|
|
76361
|
-
|
|
76362
|
-
|
|
76363
|
-
|
|
76364
|
-
|
|
76365
|
-
const wordStarts = [];
|
|
76366
|
-
for (let i = 0; i < foldedStr.length; i++) {
|
|
76367
|
-
if (isWordBoundary(foldedStr, i)) {
|
|
76368
|
-
wordStarts.push(i);
|
|
76369
|
-
}
|
|
76370
|
-
}
|
|
76371
|
-
const matchedPositions = [];
|
|
76372
|
-
let wordIdx = 0;
|
|
76373
|
-
const originalAcronym = searchText.replace(/\s/g, "");
|
|
76374
|
-
for (let si = 0; si < acronymChars.length; si++) {
|
|
76375
|
-
const ch = acronymChars[si];
|
|
76376
|
-
let found = false;
|
|
76377
|
-
while (wordIdx < wordStarts.length) {
|
|
76378
|
-
const pos = wordStarts[wordIdx];
|
|
76379
|
-
wordIdx++;
|
|
76380
|
-
if (foldedStr[pos] === ch) {
|
|
76381
|
-
matchedPositions.push(pos);
|
|
76382
|
-
found = true;
|
|
76383
|
-
break;
|
|
76610
|
+
const insertAllKey = (key, explicitOrder) => {
|
|
76611
|
+
let lo = 0;
|
|
76612
|
+
let hi = allOrderedKeys.length;
|
|
76613
|
+
while (lo < hi) {
|
|
76614
|
+
const mid = (lo + hi) >> 1;
|
|
76615
|
+
if (keyToExplicitOrder.get(allOrderedKeys[mid]) <= explicitOrder) {
|
|
76616
|
+
lo = mid + 1;
|
|
76617
|
+
} else {
|
|
76618
|
+
hi = mid;
|
|
76384
76619
|
}
|
|
76385
76620
|
}
|
|
76386
|
-
|
|
76387
|
-
|
|
76621
|
+
allOrderedKeys.splice(lo, 0, key);
|
|
76622
|
+
for (let i = lo; i < allOrderedKeys.length; i++) {
|
|
76623
|
+
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
76388
76624
|
}
|
|
76389
|
-
}
|
|
76390
|
-
const atStart = matchedPositions[0] === 0;
|
|
76391
|
-
const caseExact = matchedPositions.every(
|
|
76392
|
-
(p, i) => str[p] === originalAcronym[i],
|
|
76393
|
-
);
|
|
76394
|
-
const baseScore = atStart ? SCORE_ACRONYM + 0.05 : SCORE_ACRONYM;
|
|
76395
|
-
const matchScore = baseScore + (caseExact ? SCORE_BONUS_CASE_EXACT : 0);
|
|
76396
|
-
const matchRanges = matchedPositions.map((p) => [p, p + 1]);
|
|
76397
|
-
return { match: true, matchScore, matchRanges };
|
|
76398
|
-
};
|
|
76625
|
+
};
|
|
76399
76626
|
|
|
76400
|
-
|
|
76401
|
-
|
|
76402
|
-
|
|
76403
|
-
|
|
76404
|
-
|
|
76405
|
-
|
|
76406
|
-
|
|
76407
|
-
|
|
76408
|
-
|
|
76409
|
-
|
|
76410
|
-
}
|
|
76411
|
-
const foldedSearch = foldAccents(searchText).toLowerCase();
|
|
76412
|
-
const words = foldedSearch.split(/\s+/).filter(Boolean);
|
|
76413
|
-
const originalWords = searchText.split(/\s+/).filter(Boolean);
|
|
76414
|
-
const info = { foldedSearch, words, originalWords };
|
|
76415
|
-
searchCache.set(searchText, info);
|
|
76416
|
-
if (searchCache.size > SEARCH_CACHE_MAX_SIZE) {
|
|
76417
|
-
searchCache.delete(searchCache.keys().next().value);
|
|
76418
|
-
}
|
|
76419
|
-
return info;
|
|
76420
|
-
};
|
|
76627
|
+
const removeAllKey = (key) => {
|
|
76628
|
+
const idx = keyToAllOrderedIndex.get(key);
|
|
76629
|
+
if (idx !== undefined) {
|
|
76630
|
+
allOrderedKeys.splice(idx, 1);
|
|
76631
|
+
keyToAllOrderedIndex.delete(key);
|
|
76632
|
+
for (let i = idx; i < allOrderedKeys.length; i++) {
|
|
76633
|
+
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
76634
|
+
}
|
|
76635
|
+
}
|
|
76636
|
+
};
|
|
76421
76637
|
|
|
76422
|
-
//
|
|
76423
|
-
|
|
76424
|
-
|
|
76425
|
-
|
|
76426
|
-
|
|
76427
|
-
|
|
76428
|
-
|
|
76429
|
-
|
|
76430
|
-
|
|
76431
|
-
|
|
76432
|
-
|
|
76433
|
-
|
|
76434
|
-
|
|
76638
|
+
// Register or update an item. data.hidden controls visibility.
|
|
76639
|
+
// explicitOrder is the caller-provided index that determines sort position.
|
|
76640
|
+
const syncItem = (key, index, data) => {
|
|
76641
|
+
if (data.role === "presentation") {
|
|
76642
|
+
registrations.delete(key);
|
|
76643
|
+
const idx = keyToOrderedIndex.get(key);
|
|
76644
|
+
if (idx !== undefined) {
|
|
76645
|
+
orderedKeys.splice(idx, 1);
|
|
76646
|
+
keyToOrderedIndex.delete(key);
|
|
76647
|
+
for (let i = idx; i < orderedKeys.length; i++) {
|
|
76648
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
76649
|
+
}
|
|
76650
|
+
}
|
|
76651
|
+
keyToExplicitOrder.delete(key);
|
|
76652
|
+
allRegistrations.delete(key);
|
|
76653
|
+
removeAllKey(key);
|
|
76654
|
+
allKeys.delete(key);
|
|
76655
|
+
return;
|
|
76656
|
+
}
|
|
76657
|
+
|
|
76658
|
+
// Maintain allRegistrations and allOrderedKeys for all non-presentation items.
|
|
76659
|
+
allRegistrations.set(key, data);
|
|
76660
|
+
allKeys.add(key);
|
|
76661
|
+
const currentAllIdx = keyToAllOrderedIndex.get(key);
|
|
76662
|
+
const previousOrder = keyToExplicitOrder.get(key);
|
|
76663
|
+
keyToExplicitOrder.set(key, index);
|
|
76664
|
+
if (currentAllIdx === undefined) {
|
|
76665
|
+
insertAllKey(key, index);
|
|
76666
|
+
} else if (previousOrder !== index) {
|
|
76667
|
+
allOrderedKeys.splice(currentAllIdx, 1);
|
|
76668
|
+
keyToAllOrderedIndex.delete(key);
|
|
76669
|
+
for (let i = currentAllIdx; i < allOrderedKeys.length; i++) {
|
|
76670
|
+
keyToAllOrderedIndex.set(allOrderedKeys[i], i);
|
|
76435
76671
|
}
|
|
76436
|
-
|
|
76437
|
-
merged.push(current);
|
|
76672
|
+
insertAllKey(key, index);
|
|
76438
76673
|
}
|
|
76439
|
-
}
|
|
76440
|
-
return merged;
|
|
76441
|
-
};
|
|
76442
76674
|
|
|
76443
|
-
|
|
76444
|
-
|
|
76445
|
-
|
|
76446
|
-
|
|
76447
|
-
|
|
76448
|
-
|
|
76449
|
-
|
|
76450
|
-
|
|
76451
|
-
|
|
76452
|
-
* getter: (item) => item.name,
|
|
76453
|
-
* domSelector: ".name",
|
|
76454
|
-
* },
|
|
76455
|
-
* address: {
|
|
76456
|
-
* getter: (item) => item.address,
|
|
76457
|
-
* domSelector: ".address",
|
|
76458
|
-
* priority: 1.5,
|
|
76459
|
-
* },
|
|
76460
|
-
* });
|
|
76461
|
-
*
|
|
76462
|
-
* const [orderedItems, getItemMatchInfo] = useSearch(search, items, searchPerson);
|
|
76463
|
-
* // getItemMatchInfo(item).matchRanges is { ".name": [[start,end],…], ".address": [[start,end],…] }
|
|
76464
|
-
* // Pass the whole thing: <ListItem matchInfo={getItemMatchInfo(item)} />
|
|
76465
|
-
* // — ListItem handles the per-selector object format for matchRanges.
|
|
76466
|
-
* ```
|
|
76467
|
-
*
|
|
76468
|
-
* Each field config:
|
|
76469
|
-
* - getter(item): string — extracts the text to search
|
|
76470
|
-
* - domSelector: string — CSS selector used by ListItem to find the target element
|
|
76471
|
-
* - priority?: number — multiplier applied to the field's score (default 1)
|
|
76472
|
-
* - matchFn?: function — custom match function (searchText, fieldValue) => { match, matchScore, matchRanges }
|
|
76473
|
-
* defaults to applySearch
|
|
76474
|
-
*/
|
|
76475
|
-
const createSearch = (fields) => {
|
|
76476
|
-
return (searchText, item) => {
|
|
76477
|
-
if (!searchText) {
|
|
76478
|
-
return { match: true, matchScore: 0, matchRanges: {} };
|
|
76479
|
-
}
|
|
76480
|
-
let totalScore = 0;
|
|
76481
|
-
const matchRanges = {};
|
|
76482
|
-
for (const [
|
|
76483
|
-
,
|
|
76484
|
-
{ getter, domSelector, priority = 1, matchFn = applySearch },
|
|
76485
|
-
] of Object.entries(fields)) {
|
|
76486
|
-
const fieldValue = getter(item);
|
|
76487
|
-
const result = matchFn(searchText, fieldValue);
|
|
76488
|
-
if (result.match && result.matchRanges.length > 0) {
|
|
76489
|
-
totalScore += result.matchScore * priority;
|
|
76490
|
-
matchRanges[domSelector] = result.matchRanges;
|
|
76675
|
+
if (data.filtered || data.hidden) {
|
|
76676
|
+
registrations.delete(key);
|
|
76677
|
+
const idx = keyToOrderedIndex.get(key);
|
|
76678
|
+
if (idx !== undefined) {
|
|
76679
|
+
orderedKeys.splice(idx, 1);
|
|
76680
|
+
keyToOrderedIndex.delete(key);
|
|
76681
|
+
for (let i = idx; i < orderedKeys.length; i++) {
|
|
76682
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
76683
|
+
}
|
|
76491
76684
|
}
|
|
76685
|
+
return;
|
|
76492
76686
|
}
|
|
76493
|
-
|
|
76494
|
-
|
|
76687
|
+
|
|
76688
|
+
registrations.set(key, data);
|
|
76689
|
+
const currentIdx = keyToOrderedIndex.get(key);
|
|
76690
|
+
if (currentIdx === undefined) {
|
|
76691
|
+
insertKey(key, index);
|
|
76692
|
+
return;
|
|
76495
76693
|
}
|
|
76496
|
-
|
|
76694
|
+
if (previousOrder === index) {
|
|
76695
|
+
return;
|
|
76696
|
+
}
|
|
76697
|
+
orderedKeys.splice(currentIdx, 1);
|
|
76698
|
+
keyToOrderedIndex.delete(key);
|
|
76699
|
+
for (let i = currentIdx; i < orderedKeys.length; i++) {
|
|
76700
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
76701
|
+
}
|
|
76702
|
+
insertKey(key, index);
|
|
76497
76703
|
};
|
|
76498
|
-
};
|
|
76499
76704
|
|
|
76500
|
-
|
|
76501
|
-
|
|
76502
|
-
|
|
76503
|
-
|
|
76504
|
-
|
|
76505
|
-
|
|
76506
|
-
|
|
76507
|
-
|
|
76508
|
-
*
|
|
76509
|
-
* When searchText is empty, natural order is preserved and all items match with score 0.
|
|
76510
|
-
*
|
|
76511
|
-
* To filter (hide non-matching items), pass filtered={!getItemMatchInfo(item).match}
|
|
76512
|
-
* to each ListItem. The list's matchFallback will be shown when all items are hidden.
|
|
76513
|
-
*/
|
|
76514
|
-
const useSearchText = (searchText, items, matchFn = applySearch) => {
|
|
76515
|
-
if (typeof searchText !== "string" && searchText !== undefined) {
|
|
76516
|
-
throw new TypeError(
|
|
76517
|
-
"useSearchText: searchText must be a string or undefined",
|
|
76518
|
-
);
|
|
76519
|
-
}
|
|
76520
|
-
if (items === undefined) {
|
|
76521
|
-
throw new TypeError("useSearch: items is undefined");
|
|
76522
|
-
}
|
|
76523
|
-
const { orderedItems, matchInfoMap } = useMemo(() => {
|
|
76524
|
-
const { scoreEntries, nonMatched, matchInfoMap } = buildMatchInfo(
|
|
76525
|
-
searchText,
|
|
76526
|
-
items,
|
|
76527
|
-
matchFn,
|
|
76528
|
-
);
|
|
76529
|
-
const orderedItems = [];
|
|
76530
|
-
for (const [, bucket] of scoreEntries) {
|
|
76531
|
-
for (const { item } of bucket) {
|
|
76532
|
-
orderedItems.push(item);
|
|
76705
|
+
const unregisterKey = (key) => {
|
|
76706
|
+
registrations.delete(key);
|
|
76707
|
+
const idx = keyToOrderedIndex.get(key);
|
|
76708
|
+
if (idx !== undefined) {
|
|
76709
|
+
orderedKeys.splice(idx, 1);
|
|
76710
|
+
keyToOrderedIndex.delete(key);
|
|
76711
|
+
for (let i = idx; i < orderedKeys.length; i++) {
|
|
76712
|
+
keyToOrderedIndex.set(orderedKeys[i], i);
|
|
76533
76713
|
}
|
|
76534
76714
|
}
|
|
76535
|
-
|
|
76536
|
-
|
|
76715
|
+
keyToExplicitOrder.delete(key);
|
|
76716
|
+
allRegistrations.delete(key);
|
|
76717
|
+
removeAllKey(key);
|
|
76718
|
+
allKeys.delete(key);
|
|
76719
|
+
};
|
|
76720
|
+
|
|
76721
|
+
const keyForId = (id) => {
|
|
76722
|
+
if (!idToKey.has(id)) {
|
|
76723
|
+
idToKey.set(id, keyCounter++);
|
|
76537
76724
|
}
|
|
76538
|
-
return
|
|
76539
|
-
}
|
|
76725
|
+
return idToKey.get(id);
|
|
76726
|
+
};
|
|
76540
76727
|
|
|
76541
|
-
//
|
|
76542
|
-
//
|
|
76543
|
-
//
|
|
76544
|
-
|
|
76545
|
-
|
|
76546
|
-
|
|
76547
|
-
|
|
76728
|
+
// Register an item. data.hidden controls visibility.
|
|
76729
|
+
// explicitOrder is the caller-provided index (e.g. from items.map((item, i) => ...))
|
|
76730
|
+
// that determines this item's position among siblings.
|
|
76731
|
+
// Returns the item's visible rank among non-hidden items, or -1 when hidden.
|
|
76732
|
+
const useTrackItem = (data) => {
|
|
76733
|
+
const { id, index } = data;
|
|
76734
|
+
const key = keyForId(id);
|
|
76548
76735
|
|
|
76549
|
-
|
|
76550
|
-
|
|
76736
|
+
syncItem(key, index, data);
|
|
76737
|
+
notify();
|
|
76551
76738
|
|
|
76552
|
-
|
|
76553
|
-
|
|
76554
|
-
|
|
76555
|
-
|
|
76556
|
-
|
|
76557
|
-
|
|
76739
|
+
useLayoutEffect(() => {
|
|
76740
|
+
return () => {
|
|
76741
|
+
unregisterKey(key);
|
|
76742
|
+
notify();
|
|
76743
|
+
};
|
|
76744
|
+
}, []);
|
|
76558
76745
|
|
|
76559
|
-
|
|
76560
|
-
|
|
76561
|
-
if (!result.match) {
|
|
76562
|
-
nonMatched.push({
|
|
76563
|
-
item,
|
|
76564
|
-
matchScore: result.matchScore,
|
|
76565
|
-
matchRanges: result.matchRanges,
|
|
76566
|
-
});
|
|
76567
|
-
continue;
|
|
76568
|
-
}
|
|
76569
|
-
const score = result.matchScore;
|
|
76570
|
-
// Find existing bucket or insert a new entry in desc order.
|
|
76571
|
-
let lo = 0;
|
|
76572
|
-
let hi = scoreEntries.length;
|
|
76573
|
-
while (lo < hi) {
|
|
76574
|
-
const mid = (lo + hi) >> 1;
|
|
76575
|
-
if (scoreEntries[mid][0] > score) {
|
|
76576
|
-
lo = mid + 1;
|
|
76577
|
-
} else if (scoreEntries[mid][0] < score) {
|
|
76578
|
-
hi = mid;
|
|
76579
|
-
} else {
|
|
76580
|
-
lo = mid;
|
|
76581
|
-
hi = mid; // exact match — found the bucket
|
|
76582
|
-
}
|
|
76746
|
+
if (data.filtered || data.hidden || data.role === "presentation") {
|
|
76747
|
+
return -1;
|
|
76583
76748
|
}
|
|
76584
|
-
|
|
76585
|
-
|
|
76586
|
-
|
|
76587
|
-
|
|
76588
|
-
|
|
76589
|
-
|
|
76590
|
-
|
|
76749
|
+
return keyToOrderedIndex.get(key) ?? -1;
|
|
76750
|
+
};
|
|
76751
|
+
|
|
76752
|
+
const getTrackedItemByIndex = (index) => {
|
|
76753
|
+
const key = orderedKeys[index];
|
|
76754
|
+
if (key === undefined) {
|
|
76755
|
+
return undefined;
|
|
76591
76756
|
}
|
|
76592
|
-
|
|
76757
|
+
return registrations.get(key);
|
|
76758
|
+
};
|
|
76593
76759
|
|
|
76594
|
-
|
|
76595
|
-
|
|
76596
|
-
|
|
76597
|
-
|
|
76760
|
+
// The items as they stand right now, notification pending or not — same
|
|
76761
|
+
// content as itemsSignal, minus the wait.
|
|
76762
|
+
//
|
|
76763
|
+
// Items register during their own render, while the signal is only updated
|
|
76764
|
+
// on a deferred microtask (see notify): a sibling rendering after them would
|
|
76765
|
+
// otherwise paint from an empty list and correct itself a frame later. That
|
|
76766
|
+
// frame is visible whenever the painted size feeds a layout decision — a
|
|
76767
|
+
// dialog sizing itself on its content measures the empty version and shifts
|
|
76768
|
+
// once the real one lands. Reading this instead makes the first paint the
|
|
76769
|
+
// right one. Callers must still subscribe to itemsSignal to re-render on
|
|
76770
|
+
// LATER changes; this is the value to display, not the notification.
|
|
76771
|
+
const peekItems = () => {
|
|
76772
|
+
if (!notifyScheduled) {
|
|
76773
|
+
return itemsSignal.peek();
|
|
76598
76774
|
}
|
|
76599
|
-
|
|
76600
|
-
|
|
76601
|
-
|
|
76602
|
-
|
|
76775
|
+
const items = [];
|
|
76776
|
+
for (const key of allOrderedKeys) {
|
|
76777
|
+
items.push(allRegistrations.get(key));
|
|
76778
|
+
}
|
|
76779
|
+
return items;
|
|
76780
|
+
};
|
|
76603
76781
|
|
|
76604
|
-
return {
|
|
76782
|
+
return {
|
|
76783
|
+
useTrackItem,
|
|
76784
|
+
getTrackedItemByIndex,
|
|
76785
|
+
peekItems,
|
|
76786
|
+
itemsSignal,
|
|
76787
|
+
visibleItemsSignal,
|
|
76788
|
+
countSignal,
|
|
76789
|
+
visibleCountSignal,
|
|
76790
|
+
noMatchCountSignal,
|
|
76791
|
+
_flushSync,
|
|
76792
|
+
};
|
|
76605
76793
|
};
|
|
76606
76794
|
|
|
76607
76795
|
installImportMetaCssBuild(import.meta);
|