trotl-table 1.0.10 → 1.0.11
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/README.md +1 -0
- package/dist/index.cjs.js +38 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -15
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -9693,26 +9693,49 @@ function Table({
|
|
|
9693
9693
|
// Option to read search param from URL
|
|
9694
9694
|
const [searchTerm, setSearchTerm] = React.useState(extraSearchTerm);
|
|
9695
9695
|
|
|
9696
|
-
//
|
|
9697
|
-
// Extract window.location.search to a variable for useEffect dependency
|
|
9698
|
-
const locationSearch = typeof window !== "undefined" ? window.location.search : "";
|
|
9696
|
+
// Listen to URL changes via popstate (back/forward) and custom events
|
|
9699
9697
|
React.useEffect(() => {
|
|
9700
9698
|
if (!enableSearchUrlParam) {
|
|
9701
9699
|
setSearchTerm(extraSearchTerm);
|
|
9702
9700
|
return;
|
|
9703
9701
|
}
|
|
9704
|
-
const
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
9702
|
+
const updateSearchFromUrl = () => {
|
|
9703
|
+
const params = new URLSearchParams(window.location.search);
|
|
9704
|
+
const entrySearch = params.get("entry");
|
|
9705
|
+
const urlSearch = params.get("search");
|
|
9706
|
+
if (entrySearch) {
|
|
9707
|
+
setSearchTerm(entrySearch);
|
|
9708
|
+
} else if (urlSearch) {
|
|
9709
|
+
setSearchTerm(urlSearch);
|
|
9710
|
+
} else {
|
|
9711
|
+
setSearchTerm(extraSearchTerm);
|
|
9712
|
+
}
|
|
9713
|
+
};
|
|
9714
|
+
|
|
9715
|
+
// Initial sync
|
|
9716
|
+
updateSearchFromUrl();
|
|
9717
|
+
|
|
9718
|
+
// Listen for URL changes (back/forward navigation)
|
|
9719
|
+
window.addEventListener('popstate', updateSearchFromUrl);
|
|
9720
|
+
|
|
9721
|
+
// Listen for programmatic URL changes if you use history.pushState/replaceState
|
|
9722
|
+
const originalPushState = window.history.pushState;
|
|
9723
|
+
const originalReplaceState = window.history.replaceState;
|
|
9724
|
+
window.history.pushState = function (...args) {
|
|
9725
|
+
originalPushState.apply(this, args);
|
|
9726
|
+
updateSearchFromUrl();
|
|
9727
|
+
};
|
|
9728
|
+
window.history.replaceState = function (...args) {
|
|
9729
|
+
originalReplaceState.apply(this, args);
|
|
9730
|
+
updateSearchFromUrl();
|
|
9731
|
+
};
|
|
9732
|
+
return () => {
|
|
9733
|
+
window.removeEventListener('popstate', updateSearchFromUrl);
|
|
9734
|
+
// Restore original methods
|
|
9735
|
+
window.history.pushState = originalPushState;
|
|
9736
|
+
window.history.replaceState = originalReplaceState;
|
|
9737
|
+
};
|
|
9738
|
+
}, [enableSearchUrlParam, extraSearchTerm]);
|
|
9716
9739
|
const toggleRowSelection = React.useCallback(rowId => {
|
|
9717
9740
|
setSelectedRows(prev => prev.includes(rowId) ? prev.filter(r => r !== rowId) : [...prev, rowId]);
|
|
9718
9741
|
}, []);
|