@charlesgomes/leafcode-shared-lib-react 1.0.47 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -863,7 +863,7 @@ function DataTableAdvancedFilterWrapper({
863
863
  globalFilterFields
864
864
  )
865
865
  });
866
- const updateUrlParams = (params) => {
866
+ const updateUrlParams = (params, options = { replace: true }) => {
867
867
  if (typeof window === "undefined" || !replaceUrl) return;
868
868
  const urlParams = new URLSearchParams(window.location.search);
869
869
  Object.entries(params).forEach(([key, value]) => {
@@ -876,12 +876,40 @@ function DataTableAdvancedFilterWrapper({
876
876
  );
877
877
  }
878
878
  });
879
- window.history.replaceState(
880
- null,
881
- "",
882
- `${window.location.pathname}?${urlParams.toString()}`
883
- );
879
+ const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
880
+ window.history.pushState(null, "", newUrl);
881
+ };
882
+ const hydrateFromUrl = () => {
883
+ const params = new URLSearchParams(window.location.search);
884
+ const pageParam = Number(params.get("page") ?? 1);
885
+ const rowsParam = Number(params.get("rows") ?? rows);
886
+ const sortFieldParam = params.get("sortField") ?? sortFieldInitial;
887
+ const sortOrderParam = Number(params.get("sortOrder") ?? sortOrderInitial);
888
+ const filterParam = params.get("filter") ?? "";
889
+ setPage(pageParam);
890
+ setRows(rowsParam);
891
+ setFirst((pageParam - 1) * rowsParam);
892
+ setSortField(sortFieldParam);
893
+ setSortOrder(sortOrderParam);
894
+ setSearchText(filterParam);
895
+ setFilters((prev) => ({
896
+ ...prev,
897
+ global: {
898
+ ...prev.global ?? { matchMode: "contains" },
899
+ value: filterParam
900
+ }
901
+ }));
884
902
  };
903
+ (0, import_react6.useEffect)(() => {
904
+ if (typeof window === "undefined") return;
905
+ const handlePopState = () => {
906
+ hydrateFromUrl();
907
+ };
908
+ window.addEventListener("popstate", handlePopState);
909
+ return () => {
910
+ window.removeEventListener("popstate", handlePopState);
911
+ };
912
+ }, []);
885
913
  const onPage = (event) => {
886
914
  setFirst(event.first);
887
915
  setRows(event.rows);
package/dist/index.mjs CHANGED
@@ -808,7 +808,7 @@ function DataTableAdvancedFilterWrapper({
808
808
  globalFilterFields
809
809
  )
810
810
  });
811
- const updateUrlParams = (params) => {
811
+ const updateUrlParams = (params, options = { replace: true }) => {
812
812
  if (typeof window === "undefined" || !replaceUrl) return;
813
813
  const urlParams = new URLSearchParams(window.location.search);
814
814
  Object.entries(params).forEach(([key, value]) => {
@@ -821,12 +821,40 @@ function DataTableAdvancedFilterWrapper({
821
821
  );
822
822
  }
823
823
  });
824
- window.history.replaceState(
825
- null,
826
- "",
827
- `${window.location.pathname}?${urlParams.toString()}`
828
- );
824
+ const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
825
+ window.history.pushState(null, "", newUrl);
826
+ };
827
+ const hydrateFromUrl = () => {
828
+ const params = new URLSearchParams(window.location.search);
829
+ const pageParam = Number(params.get("page") ?? 1);
830
+ const rowsParam = Number(params.get("rows") ?? rows);
831
+ const sortFieldParam = params.get("sortField") ?? sortFieldInitial;
832
+ const sortOrderParam = Number(params.get("sortOrder") ?? sortOrderInitial);
833
+ const filterParam = params.get("filter") ?? "";
834
+ setPage(pageParam);
835
+ setRows(rowsParam);
836
+ setFirst((pageParam - 1) * rowsParam);
837
+ setSortField(sortFieldParam);
838
+ setSortOrder(sortOrderParam);
839
+ setSearchText(filterParam);
840
+ setFilters((prev) => ({
841
+ ...prev,
842
+ global: {
843
+ ...prev.global ?? { matchMode: "contains" },
844
+ value: filterParam
845
+ }
846
+ }));
829
847
  };
848
+ useEffect3(() => {
849
+ if (typeof window === "undefined") return;
850
+ const handlePopState = () => {
851
+ hydrateFromUrl();
852
+ };
853
+ window.addEventListener("popstate", handlePopState);
854
+ return () => {
855
+ window.removeEventListener("popstate", handlePopState);
856
+ };
857
+ }, []);
830
858
  const onPage = (event) => {
831
859
  setFirst(event.first);
832
860
  setRows(event.rows);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charlesgomes/leafcode-shared-lib-react",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "Lib de componentes react",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",