@charlesgomes/leafcode-shared-lib-react 1.0.50 → 1.0.52

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
@@ -516,288 +516,6 @@ var useDebounce = (value, delay) => {
516
516
  return debouncedValue;
517
517
  };
518
518
 
519
- // src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
520
- var import_api2 = require("primereact/api");
521
- var mapMatchMode = (mode) => {
522
- switch (mode) {
523
- case "startsWith":
524
- return "StartsWith";
525
- case "contains":
526
- return "Contains";
527
- case "equals":
528
- return "Equals";
529
- case "notEquals":
530
- return "notEquals";
531
- case "endsWith":
532
- return "EndsWith";
533
- case "lt":
534
- case "dateBefore":
535
- return "LessThan";
536
- case "lte":
537
- return "LessThanOrEqualTo";
538
- case "gt":
539
- case "dateAfter":
540
- return "GreaterThan";
541
- case "gte":
542
- return "GreaterThanOrEqualTo";
543
- case "notContains":
544
- return "NotContains";
545
- case "empty":
546
- return "Empty";
547
- default:
548
- return "Equals";
549
- }
550
- };
551
- var buildFilterPayload = (fieldName, matchMode, rawValue) => {
552
- const normalized = normalizeFilterValue(rawValue);
553
- if (matchMode === "empty") {
554
- return {
555
- field: fieldName,
556
- operator: "Empty"
557
- };
558
- }
559
- if (matchMode === "notEmpty") {
560
- return {
561
- not: {
562
- field: fieldName,
563
- operator: "Empty"
564
- }
565
- };
566
- }
567
- if (normalized === null) return null;
568
- if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
569
- matchMode === "dateIsNot" || matchMode === "notContains") {
570
- let operator;
571
- switch (matchMode) {
572
- case "notStartsWith":
573
- operator = "StartsWith";
574
- break;
575
- case "notEndsWith":
576
- operator = "EndsWith";
577
- break;
578
- case "notContains":
579
- operator = "Contains";
580
- break;
581
- case "notEquals":
582
- case "dateIsNot":
583
- default:
584
- operator = "Equals";
585
- }
586
- return {
587
- not: {
588
- field: fieldName,
589
- operator,
590
- value: normalized
591
- }
592
- };
593
- }
594
- return {
595
- field: fieldName,
596
- operator: mapMatchMode(matchMode),
597
- value: normalized
598
- };
599
- };
600
- var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
601
- const finalAnd = [];
602
- const globalOr = [];
603
- const camposMap = {};
604
- Object.entries(filters).forEach(([field, config]) => {
605
- if (!config) return;
606
- const value = config?.value?.text ?? config?.value;
607
- if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
608
- const globalOrNodes = [];
609
- globalFilterFields.forEach((globalField) => {
610
- const fieldConfig = filters[globalField];
611
- if (!fieldConfig) return;
612
- const payload = buildFilterPayload(
613
- fieldConfig.filterFieldCollection ?? globalField,
614
- resolveMatchMode(config.matchMode, config.value),
615
- config.value
616
- );
617
- if (!payload) return;
618
- if (!fieldConfig.collection) {
619
- globalOrNodes.push(payload);
620
- return;
621
- }
622
- const rootCollections = [];
623
- pushIntoCollectionTree(
624
- rootCollections,
625
- fieldConfig.collection,
626
- payload.field ?? payload.not?.field,
627
- payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
628
- );
629
- globalOrNodes.push(...rootCollections);
630
- });
631
- if (globalOrNodes.length) {
632
- finalAnd.push({ or: globalOrNodes });
633
- }
634
- return;
635
- }
636
- const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
637
- if (!constraints.length) return;
638
- const colOperator = config.operator === "or" ? "or" : "and";
639
- if (config.collection === "campos" && config.fieldId) {
640
- if (!camposMap[config.fieldId]) {
641
- camposMap[config.fieldId] = { operator: colOperator, values: [] };
642
- }
643
- constraints.forEach((c) => {
644
- const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
645
- const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
646
- if (payload) camposMap[config.fieldId].values.push(payload);
647
- });
648
- return;
649
- }
650
- const columnPayloads = constraints.map(
651
- (c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
652
- ).filter(Boolean);
653
- if (!columnPayloads.length) return;
654
- if (config.collection) {
655
- const rootCollections = [];
656
- columnPayloads.forEach((payload) => {
657
- pushIntoCollectionTree(
658
- rootCollections,
659
- config.collection,
660
- payload.field ?? payload.not?.field,
661
- payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
662
- );
663
- });
664
- rootCollections.forEach((c) => finalAnd.push(c));
665
- return;
666
- }
667
- finalAnd.push({ [colOperator]: columnPayloads });
668
- });
669
- Object.entries(camposMap).forEach(([fieldId, config]) => {
670
- if (!config.values.length) return;
671
- finalAnd.push({
672
- collection: "campos",
673
- any: {
674
- and: [
675
- { field: "tipocampo.id", operator: "Equals", value: fieldId },
676
- { [config.operator]: config.values }
677
- ]
678
- }
679
- });
680
- });
681
- return finalAnd.length ? { and: finalAnd } : void 0;
682
- };
683
- function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
684
- const collections = collectionPath.split(".");
685
- let current = root;
686
- collections.forEach((collection) => {
687
- let node = current.find(
688
- (n) => n.collection === collection && n.any
689
- );
690
- if (!node) {
691
- node = {
692
- collection,
693
- any: { or: [] }
694
- };
695
- current.push(node);
696
- }
697
- current = node.any.or;
698
- });
699
- current.push({
700
- ...payloadBase,
701
- field: fieldName
702
- });
703
- }
704
- function getMatchModeByTipo(tipo) {
705
- switch (tipo) {
706
- case "NumeroInteiro":
707
- case "NumeroDecimal":
708
- return import_api2.FilterMatchMode.EQUALS;
709
- default:
710
- return import_api2.FilterMatchMode.CONTAINS;
711
- }
712
- }
713
- function buildDynamicCampoFilters(campos) {
714
- return campos?.reduce((acc, campo) => {
715
- acc[`${campo.id}`] = {
716
- operator: import_api2.FilterOperator.AND,
717
- constraints: [
718
- {
719
- value: null,
720
- matchMode: getMatchModeByTipo(campo.tipoDado)
721
- }
722
- ],
723
- collection: "campos",
724
- filterFieldCollection: "valor",
725
- fieldId: campo.id
726
- // opcional (útil pro backend)
727
- };
728
- return acc;
729
- }, {});
730
- }
731
- var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
732
- const params = new URLSearchParams(
733
- typeof window !== "undefined" ? window.location.search : ""
734
- );
735
- return {
736
- page: Number(params.get("page") ?? 1),
737
- rows: Number(params.get("rows") ?? 10),
738
- sortField: params.get("sortField") || sortFieldInitial || "",
739
- sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
740
- filter: params.get("filter") ?? ""
741
- };
742
- };
743
- function buildSortingWithFilters(filters, sortField, order) {
744
- const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
745
- let sorting = [
746
- {
747
- field: sortField,
748
- direction
749
- }
750
- ];
751
- if (!filters || !sortField) {
752
- return sorting;
753
- }
754
- const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
755
- if (sortFilter?.fieldId) {
756
- sorting = [
757
- {
758
- collection: "campos",
759
- filter: {
760
- field: "tipocampo.id",
761
- operator: "equals",
762
- value: sortFilter.fieldId
763
- },
764
- first: {
765
- field: "valor",
766
- direction
767
- }
768
- }
769
- ];
770
- }
771
- return sorting;
772
- }
773
- function normalizeFilterValue(raw) {
774
- if (raw === null || raw === void 0) return null;
775
- if (typeof raw === "boolean") {
776
- return String(raw);
777
- }
778
- if (typeof raw === "number") {
779
- return raw;
780
- }
781
- if (typeof raw === "string") {
782
- return raw.trim() !== "" ? raw : null;
783
- }
784
- if (typeof raw === "object") {
785
- if ("text" in raw && raw.text === null) {
786
- return "__NULL__";
787
- }
788
- if (typeof raw.text === "string") {
789
- return raw.text.trim() !== "" ? raw.text : null;
790
- }
791
- }
792
- return null;
793
- }
794
- function resolveMatchMode(constraintMatchMode, rawValue) {
795
- if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
796
- return rawValue.matchMode;
797
- }
798
- return constraintMatchMode;
799
- }
800
-
801
519
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilterWrapper.tsx
802
520
  var import_jsx_runtime9 = require("react/jsx-runtime");
803
521
  function DataTableAdvancedFilterWrapper({
@@ -815,28 +533,29 @@ function DataTableAdvancedFilterWrapper({
815
533
  sortOrderInitial = 1,
816
534
  isMultiSelectionMode = true,
817
535
  isLanguagePtBr = true,
818
- replaceUrl = true
536
+ state,
537
+ onStateChange
819
538
  }) {
820
539
  const [isClient, setIsClient] = (0, import_react6.useState)(false);
821
540
  (0, import_react6.useEffect)(() => {
822
541
  setIsClient(true);
823
542
  }, []);
824
- const {
825
- page: urlPage,
826
- rows: urlRows,
827
- sortField: urlSortField,
828
- sortOrder: urlSortOrder,
829
- filter: urlFilter
830
- } = getUrlParams(sortFieldInitial, sortOrderInitial);
831
- const [page, setPage] = (0, import_react6.useState)(urlPage);
832
- const [rows, setRows] = (0, import_react6.useState)(urlRows);
833
- const [first, setFirst] = (0, import_react6.useState)((urlPage - 1) * urlRows);
834
- const [sortField, setSortField] = (0, import_react6.useState)(urlSortField);
835
- const [sortOrder, setSortOrder] = (0, import_react6.useState)(urlSortOrder);
836
- const [searchText, setSearchText] = (0, import_react6.useState)(urlFilter);
543
+ const initialState = state ?? {
544
+ page: 1,
545
+ rows: 10,
546
+ sortField: sortFieldInitial,
547
+ sortOrder: sortOrderInitial,
548
+ filter: ""
549
+ };
550
+ const [page, setPage] = (0, import_react6.useState)(initialState.page);
551
+ const [rows, setRows] = (0, import_react6.useState)(initialState.rows);
552
+ const [first, setFirst] = (0, import_react6.useState)((initialState.page - 1) * initialState.rows);
553
+ const [sortField, setSortField] = (0, import_react6.useState)(initialState.sortField);
554
+ const [sortOrder, setSortOrder] = (0, import_react6.useState)(initialState.sortOrder ?? 1);
555
+ const [searchText, setSearchText] = (0, import_react6.useState)(initialState.filter ?? "");
837
556
  const [filters, setFilters] = (0, import_react6.useState)({
838
557
  ...initFilters,
839
- global: { value: urlFilter, matchMode: "contains" }
558
+ global: { value: initialState.filter, matchMode: "contains" }
840
559
  });
841
560
  const [selectedRowsData, setSelectedRowsData] = (0, import_react6.useState)([]);
842
561
  const debouncedSearch = useDebounce(searchText, 500);
@@ -863,68 +582,42 @@ function DataTableAdvancedFilterWrapper({
863
582
  globalFilterFields
864
583
  )
865
584
  });
866
- const didInitRef = (0, import_react6.useRef)(false);
867
585
  (0, import_react6.useEffect)(() => {
868
- if (didInitRef.current) return;
869
- didInitRef.current = true;
870
- window.history.replaceState(
871
- null,
872
- "",
873
- window.location.href
874
- );
875
- }, []);
876
- const updateUrlParams = (params, options = { replace: true }) => {
877
- if (typeof window === "undefined" || !replaceUrl) return;
878
- const urlParams = new URLSearchParams(window.location.search);
879
- Object.entries(params).forEach(([key, value]) => {
880
- if (value === void 0 || value === null || value === "") {
881
- urlParams.delete(key);
882
- } else {
883
- urlParams.set(
884
- key,
885
- typeof value === "string" ? value : JSON.stringify(value)
886
- );
887
- }
888
- });
889
- const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
890
- window.history.pushState(null, "", newUrl);
891
- };
892
- const hydrateFromUrl = () => {
893
- const params = new URLSearchParams(window.location.search);
894
- const pageParam = Number(params.get("page") ?? 1);
895
- const rowsParam = Number(params.get("rows") ?? rows);
896
- const sortFieldParam = params.get("sortField") ?? sortFieldInitial;
897
- const sortOrderParam = Number(params.get("sortOrder") ?? sortOrderInitial);
898
- const filterParam = params.get("filter") ?? "";
899
- setPage(pageParam);
900
- setRows(rowsParam);
901
- setFirst((pageParam - 1) * rowsParam);
902
- setSortField(sortFieldParam);
903
- setSortOrder(sortOrderParam);
904
- setSearchText(filterParam);
586
+ if (!state) return;
587
+ setPage(state.page);
588
+ setRows(state.rows);
589
+ setFirst((state.page - 1) * state.rows);
590
+ setSortField(state.sortField);
591
+ setSortOrder(state.sortOrder ?? 1);
592
+ setSearchText(state.filter ?? "");
905
593
  setFilters((prev) => ({
906
594
  ...prev,
907
595
  global: {
908
596
  ...prev.global ?? { matchMode: "contains" },
909
- value: filterParam
597
+ value: state.filter ?? ""
910
598
  }
911
599
  }));
600
+ }, [state]);
601
+ const emitStateChange = (partial) => {
602
+ if (!onStateChange) return;
603
+ onStateChange({
604
+ page,
605
+ rows,
606
+ sortField,
607
+ sortOrder,
608
+ filter: searchText,
609
+ ...partial
610
+ });
912
611
  };
913
- (0, import_react6.useEffect)(() => {
914
- if (typeof window === "undefined") return;
915
- const handlePopState = () => {
916
- hydrateFromUrl();
917
- };
918
- window.addEventListener("popstate", handlePopState);
919
- return () => {
920
- window.removeEventListener("popstate", handlePopState);
921
- };
922
- }, []);
923
612
  const onPage = (event) => {
613
+ const newPage = event.page + 1;
924
614
  setFirst(event.first);
925
615
  setRows(event.rows);
926
- setPage(event.page + 1);
927
- updateUrlParams({ page: event.page + 1, rows: event.rows });
616
+ setPage(newPage);
617
+ emitStateChange({
618
+ page: newPage,
619
+ rows: event.rows
620
+ });
928
621
  };
929
622
  const onGlobalFilterChange = (e) => {
930
623
  const value = e.target.value;
@@ -940,10 +633,16 @@ function DataTableAdvancedFilterWrapper({
940
633
  const onSort = (e) => {
941
634
  setSortField(e.sortField);
942
635
  setSortOrder(e.sortOrder);
943
- updateUrlParams({ sortField: e.sortField, sortOrder: e.sortOrder });
636
+ emitStateChange({
637
+ sortField: e.sortField,
638
+ sortOrder: e.sortOrder
639
+ });
944
640
  };
945
641
  (0, import_react6.useEffect)(() => {
946
- updateUrlParams({ page: 1, filter: debouncedSearch });
642
+ emitStateChange({
643
+ page: 1,
644
+ filter: debouncedSearch
645
+ });
947
646
  }, [debouncedSearch]);
948
647
  (0, import_react6.useEffect)(() => {
949
648
  if (customers?.items && selectedRowsData.length > 0) {
@@ -1109,7 +808,7 @@ function DataTableAdvancedFilterWrapper({
1109
808
  }
1110
809
 
1111
810
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilter.tsx
1112
- var import_api3 = require("primereact/api");
811
+ var import_api2 = require("primereact/api");
1113
812
 
1114
813
  // src/components/DataTableAdvancedFilter/utils/locale.ts
1115
814
  var localePtBr = {
@@ -1280,21 +979,20 @@ function DataTableAdvancedFilter({
1280
979
  sortFieldInitial,
1281
980
  sortOrderInitial = 1,
1282
981
  isMultiSelectionMode = true,
1283
- isLanguagePtBr = true,
1284
- replaceUrl = true
982
+ isLanguagePtBr = true
1285
983
  }) {
1286
984
  const [isClient, setIsClient] = (0, import_react8.useState)(false);
1287
985
  (0, import_react8.useEffect)(() => {
1288
- (0, import_api3.addLocale)("pt", localePtBr);
986
+ (0, import_api2.addLocale)("pt", localePtBr);
1289
987
  }, []);
1290
988
  (0, import_react8.useEffect)(() => {
1291
- (0, import_api3.locale)(isLanguagePtBr ? "pt" : "en");
989
+ (0, import_api2.locale)(isLanguagePtBr ? "pt" : "en");
1292
990
  }, [isLanguagePtBr]);
1293
991
  (0, import_react8.useEffect)(() => {
1294
992
  setIsClient(true);
1295
993
  }, []);
1296
994
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: isClient && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1297
- import_api3.PrimeReactProvider,
995
+ import_api2.PrimeReactProvider,
1298
996
  {
1299
997
  value: isLanguagePtBr ? { locale: "pt" } : { locale: "en" },
1300
998
  children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
@@ -1313,8 +1011,7 @@ function DataTableAdvancedFilter({
1313
1011
  sortFieldInitial,
1314
1012
  sortOrderInitial,
1315
1013
  isMultiSelectionMode,
1316
- isLanguagePtBr,
1317
- replaceUrl
1014
+ isLanguagePtBr
1318
1015
  }
1319
1016
  )
1320
1017
  }
@@ -1333,301 +1030,583 @@ var DateFilterTemplate = (options, mask) => {
1333
1030
  {
1334
1031
  value: parsedValue,
1335
1032
  onChange: (e) => {
1336
- if (!e.value) {
1033
+ if (!e.value) {
1034
+ options.filterCallback(null, options.index);
1035
+ return;
1036
+ }
1037
+ const date = e.value;
1038
+ const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
1039
+ 2,
1040
+ "0"
1041
+ )}-${String(date.getDate()).padStart(2, "0")}`;
1042
+ options.filterCallback(valueToFilter, options.index);
1043
+ },
1044
+ dateFormat: "dd/mm/yy",
1045
+ placeholder: "dd/mm/yyyy",
1046
+ mask: "99/99/9999",
1047
+ inputClassName: "p-column-filter"
1048
+ }
1049
+ );
1050
+ };
1051
+ var DateTimeFilterTemplate = (options, mask) => {
1052
+ const value = typeof options.value === "string" ? (0, import_moment2.default)(options.value).toDate() : options.value ?? null;
1053
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1054
+ import_calendar.Calendar,
1055
+ {
1056
+ value,
1057
+ showTime: true,
1058
+ showSeconds: true,
1059
+ hourFormat: "24",
1060
+ dateFormat: "dd/mm/yy",
1061
+ placeholder: "dd/mm/yyyy 00:00:00",
1062
+ readOnlyInput: true,
1063
+ inputClassName: "p-column-filter",
1064
+ onChange: (e) => {
1065
+ const selectedDate = e.value;
1066
+ if (!selectedDate) {
1337
1067
  options.filterCallback(null, options.index);
1338
1068
  return;
1339
1069
  }
1340
- const date = e.value;
1341
- const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
1342
- 2,
1343
- "0"
1344
- )}-${String(date.getDate()).padStart(2, "0")}`;
1345
- options.filterCallback(valueToFilter, options.index);
1070
+ const formatted = mask ? mask(selectedDate) : (0, import_moment2.default)(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1071
+ options.filterCallback(formatted, options.index);
1072
+ }
1073
+ }
1074
+ );
1075
+ };
1076
+ var ValueFilterTemplate = (options, mask) => {
1077
+ const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
1078
+ const handleChange = (e) => {
1079
+ const rawValue = e.value;
1080
+ if (rawValue === null || rawValue === void 0) {
1081
+ options.filterCallback(null, options.index);
1082
+ return;
1083
+ }
1084
+ const valueToFilter = mask ? mask(rawValue) : rawValue;
1085
+ options.filterCallback(valueToFilter, options.index);
1086
+ };
1087
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1088
+ import_inputnumber.InputNumber,
1089
+ {
1090
+ value: parsedValue,
1091
+ onValueChange: handleChange,
1092
+ mode: "currency",
1093
+ currency: "BRL",
1094
+ locale: "pt-BR",
1095
+ inputClassName: "custom-input"
1096
+ }
1097
+ );
1098
+ };
1099
+ var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
1100
+ const selectOptions = items.length > 0 ? items : [
1101
+ { label: isLanguagePtBr ? "Todos" : "All", value: null },
1102
+ { label: isLanguagePtBr ? "Sim" : "Yes", value: true },
1103
+ { label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
1104
+ ];
1105
+ const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
1106
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1107
+ import_react_select.default,
1108
+ {
1109
+ options: selectOptions,
1110
+ value: currentValue,
1111
+ onChange: (selected) => options.filterCallback(selected?.value),
1112
+ placeholder: "Todos",
1113
+ isClearable: false,
1114
+ isSearchable: false,
1115
+ className: "custom-select-filtro",
1116
+ classNamePrefix: "custom-select-filtro",
1117
+ styles: {
1118
+ control: (baseStyles, state) => ({
1119
+ ...baseStyles,
1120
+ "&:hover": {
1121
+ borderColor: state.isFocused ? "#094394" : ""
1122
+ },
1123
+ borderRadius: "6px"
1124
+ }),
1125
+ menuList: (base) => ({
1126
+ ...base,
1127
+ "::-webkit-scrollbar": {
1128
+ width: "6px",
1129
+ height: "auto",
1130
+ overflowX: "hidden",
1131
+ overflowY: "hidden"
1132
+ },
1133
+ "::-webkit-scrollbar-track": {
1134
+ background: "#fff"
1135
+ },
1136
+ "::-webkit-scrollbar-thumb": {
1137
+ background: "#888",
1138
+ borderRadius: "2rem"
1139
+ },
1140
+ "::-webkit-scrollbar-thumb:hover": {
1141
+ background: "#555"
1142
+ }
1143
+ }),
1144
+ option: (provided, state) => ({
1145
+ ...provided,
1146
+ backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1147
+ color: state.isFocused ? "#ffffff" : "black",
1148
+ "&:hover": {
1149
+ backgroundColor: "#094394",
1150
+ // Cor de fundo quando em hover
1151
+ color: "#ffffff"
1152
+ // Cor da palavra quando em hover
1153
+ }
1154
+ })
1155
+ }
1156
+ }
1157
+ );
1158
+ };
1159
+ var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1160
+ const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
1161
+ const rawFilter = options.value ?? {};
1162
+ const currentMatchMode = rawFilter.matchMode ?? "contains";
1163
+ const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
1164
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1165
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1166
+ "div",
1167
+ {
1168
+ className: "filter-wrapper",
1169
+ style: {
1170
+ display: "flex",
1171
+ flexDirection: "column",
1172
+ gap: "8px",
1173
+ minWidth: "200px"
1346
1174
  },
1347
- dateFormat: "dd/mm/yy",
1348
- placeholder: "dd/mm/yyyy",
1349
- mask: "99/99/9999",
1350
- inputClassName: "p-column-filter"
1175
+ children: [
1176
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1177
+ import_dropdown.Dropdown,
1178
+ {
1179
+ value: currentMatchMode,
1180
+ options: resolvedItems,
1181
+ optionLabel: "label",
1182
+ optionValue: "value",
1183
+ placeholder: "Tipo de filtro",
1184
+ style: { width: "100%" },
1185
+ onChange: (e) => {
1186
+ const newMatchMode = e.value;
1187
+ const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
1188
+ if (isNewSpecial) {
1189
+ options.filterCallback({
1190
+ text: null,
1191
+ matchMode: newMatchMode
1192
+ });
1193
+ return;
1194
+ }
1195
+ options.filterCallback({
1196
+ text: null,
1197
+ matchMode: newMatchMode
1198
+ });
1199
+ }
1200
+ }
1201
+ ),
1202
+ !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1203
+ import_inputtext.InputText,
1204
+ {
1205
+ value: currentValue,
1206
+ placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1207
+ style: { width: "100%" },
1208
+ className: "p-column-filter",
1209
+ onChange: (e) => {
1210
+ const value = e.target.value;
1211
+ if (value.trim()) {
1212
+ options.filterCallback({
1213
+ text: value,
1214
+ matchMode: currentMatchMode
1215
+ });
1216
+ } else {
1217
+ options.filterCallback({
1218
+ text: null,
1219
+ matchMode: currentMatchMode
1220
+ });
1221
+ }
1222
+ }
1223
+ }
1224
+ )
1225
+ ]
1226
+ }
1227
+ );
1228
+ };
1229
+
1230
+ // src/components/DataTableAdvancedFilter/filterModes.ts
1231
+ var import_api3 = require("primereact/api");
1232
+ var customMatchModes = {
1233
+ notStartsWith: "notStartsWith",
1234
+ notEndsWith: "notEndsWith",
1235
+ empty: "empty",
1236
+ notEmpty: "notEmpty"
1237
+ };
1238
+ var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
1239
+ {
1240
+ label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1241
+ value: import_api3.FilterMatchMode.CONTAINS
1242
+ },
1243
+ {
1244
+ label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1245
+ value: import_api3.FilterMatchMode.NOT_CONTAINS
1246
+ },
1247
+ {
1248
+ label: isLanguagePtBr ? "Igual" : "Equals",
1249
+ value: import_api3.FilterMatchMode.EQUALS
1250
+ },
1251
+ {
1252
+ label: isLanguagePtBr ? "Diferente" : "Not equals",
1253
+ value: import_api3.FilterMatchMode.NOT_EQUALS
1254
+ },
1255
+ {
1256
+ label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
1257
+ value: import_api3.FilterMatchMode.STARTS_WITH
1258
+ },
1259
+ {
1260
+ label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
1261
+ value: customMatchModes.notStartsWith
1262
+ },
1263
+ {
1264
+ label: isLanguagePtBr ? "Termina com" : "Ends with",
1265
+ value: import_api3.FilterMatchMode.ENDS_WITH
1266
+ },
1267
+ {
1268
+ label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
1269
+ value: customMatchModes.notEndsWith
1270
+ },
1271
+ {
1272
+ label: isLanguagePtBr ? "Vazio" : "Empty",
1273
+ value: customMatchModes.empty
1274
+ },
1275
+ {
1276
+ label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1277
+ value: customMatchModes.notEmpty
1278
+ }
1279
+ ];
1280
+ var getDefaultFilterMatchOptionsStringArray = (isLanguagePtBr = true) => [
1281
+ {
1282
+ label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1283
+ value: import_api3.FilterMatchMode.CONTAINS
1284
+ },
1285
+ {
1286
+ label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1287
+ value: import_api3.FilterMatchMode.NOT_CONTAINS
1288
+ }
1289
+ ];
1290
+ var getDefaultFilterMatchOptionsDate = (isLanguagePtBr) => [
1291
+ {
1292
+ label: isLanguagePtBr ? "Data antes de" : "Date before",
1293
+ value: import_api3.FilterMatchMode.DATE_BEFORE
1294
+ },
1295
+ {
1296
+ label: isLanguagePtBr ? "Data depois de" : "Date after",
1297
+ value: import_api3.FilterMatchMode.DATE_AFTER
1298
+ }
1299
+ ];
1300
+ var getDefaultFilterMatchOptionsEnum = (isLanguagePtBr) => [
1301
+ {
1302
+ label: isLanguagePtBr ? "Igual" : "Equals",
1303
+ value: import_api3.FilterMatchMode.EQUALS
1304
+ },
1305
+ {
1306
+ label: isLanguagePtBr ? "Diferente" : "Not equals",
1307
+ value: import_api3.FilterMatchMode.NOT_EQUALS
1308
+ },
1309
+ {
1310
+ label: isLanguagePtBr ? "Vazio" : "Empty",
1311
+ value: customMatchModes.empty
1312
+ },
1313
+ {
1314
+ label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1315
+ value: customMatchModes.notEmpty
1316
+ }
1317
+ ];
1318
+ var getDefaultFilterMatchOptionsEnumNotNullable = (isLanguagePtBr) => [
1319
+ {
1320
+ label: isLanguagePtBr ? "Igual" : "Equals",
1321
+ value: import_api3.FilterMatchMode.EQUALS
1322
+ },
1323
+ {
1324
+ label: isLanguagePtBr ? "Diferente" : "Not equals",
1325
+ value: import_api3.FilterMatchMode.NOT_EQUALS
1326
+ }
1327
+ ];
1328
+
1329
+ // src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
1330
+ var import_api4 = require("primereact/api");
1331
+ var mapMatchMode = (mode) => {
1332
+ switch (mode) {
1333
+ case "startsWith":
1334
+ return "StartsWith";
1335
+ case "contains":
1336
+ return "Contains";
1337
+ case "equals":
1338
+ return "Equals";
1339
+ case "notEquals":
1340
+ return "notEquals";
1341
+ case "endsWith":
1342
+ return "EndsWith";
1343
+ case "lt":
1344
+ case "dateBefore":
1345
+ return "LessThan";
1346
+ case "lte":
1347
+ return "LessThanOrEqualTo";
1348
+ case "gt":
1349
+ case "dateAfter":
1350
+ return "GreaterThan";
1351
+ case "gte":
1352
+ return "GreaterThanOrEqualTo";
1353
+ case "notContains":
1354
+ return "NotContains";
1355
+ case "empty":
1356
+ return "Empty";
1357
+ default:
1358
+ return "Equals";
1359
+ }
1360
+ };
1361
+ var buildFilterPayload = (fieldName, matchMode, rawValue) => {
1362
+ const normalized = normalizeFilterValue(rawValue);
1363
+ if (matchMode === "empty") {
1364
+ return {
1365
+ field: fieldName,
1366
+ operator: "Empty"
1367
+ };
1368
+ }
1369
+ if (matchMode === "notEmpty") {
1370
+ return {
1371
+ not: {
1372
+ field: fieldName,
1373
+ operator: "Empty"
1374
+ }
1375
+ };
1376
+ }
1377
+ if (normalized === null) return null;
1378
+ if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
1379
+ matchMode === "dateIsNot" || matchMode === "notContains") {
1380
+ let operator;
1381
+ switch (matchMode) {
1382
+ case "notStartsWith":
1383
+ operator = "StartsWith";
1384
+ break;
1385
+ case "notEndsWith":
1386
+ operator = "EndsWith";
1387
+ break;
1388
+ case "notContains":
1389
+ operator = "Contains";
1390
+ break;
1391
+ case "notEquals":
1392
+ case "dateIsNot":
1393
+ default:
1394
+ operator = "Equals";
1351
1395
  }
1352
- );
1396
+ return {
1397
+ not: {
1398
+ field: fieldName,
1399
+ operator,
1400
+ value: normalized
1401
+ }
1402
+ };
1403
+ }
1404
+ return {
1405
+ field: fieldName,
1406
+ operator: mapMatchMode(matchMode),
1407
+ value: normalized
1408
+ };
1353
1409
  };
1354
- var DateTimeFilterTemplate = (options, mask) => {
1355
- const value = typeof options.value === "string" ? (0, import_moment2.default)(options.value).toDate() : options.value ?? null;
1356
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1357
- import_calendar.Calendar,
1358
- {
1359
- value,
1360
- showTime: true,
1361
- showSeconds: true,
1362
- hourFormat: "24",
1363
- dateFormat: "dd/mm/yy",
1364
- placeholder: "dd/mm/yyyy 00:00:00",
1365
- readOnlyInput: true,
1366
- inputClassName: "p-column-filter",
1367
- onChange: (e) => {
1368
- const selectedDate = e.value;
1369
- if (!selectedDate) {
1370
- options.filterCallback(null, options.index);
1410
+ var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
1411
+ const finalAnd = [];
1412
+ const globalOr = [];
1413
+ const camposMap = {};
1414
+ Object.entries(filters).forEach(([field, config]) => {
1415
+ if (!config) return;
1416
+ const value = config?.value?.text ?? config?.value;
1417
+ if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
1418
+ const globalOrNodes = [];
1419
+ globalFilterFields.forEach((globalField) => {
1420
+ const fieldConfig = filters[globalField];
1421
+ if (!fieldConfig) return;
1422
+ const payload = buildFilterPayload(
1423
+ fieldConfig.filterFieldCollection ?? globalField,
1424
+ resolveMatchMode(config.matchMode, config.value),
1425
+ config.value
1426
+ );
1427
+ if (!payload) return;
1428
+ if (!fieldConfig.collection) {
1429
+ globalOrNodes.push(payload);
1371
1430
  return;
1372
1431
  }
1373
- const formatted = mask ? mask(selectedDate) : (0, import_moment2.default)(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1374
- options.filterCallback(formatted, options.index);
1432
+ const rootCollections = [];
1433
+ pushIntoCollectionTree(
1434
+ rootCollections,
1435
+ fieldConfig.collection,
1436
+ payload.field ?? payload.not?.field,
1437
+ payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
1438
+ );
1439
+ globalOrNodes.push(...rootCollections);
1440
+ });
1441
+ if (globalOrNodes.length) {
1442
+ finalAnd.push({ or: globalOrNodes });
1375
1443
  }
1444
+ return;
1376
1445
  }
1377
- );
1378
- };
1379
- var ValueFilterTemplate = (options, mask) => {
1380
- const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
1381
- const handleChange = (e) => {
1382
- const rawValue = e.value;
1383
- if (rawValue === null || rawValue === void 0) {
1384
- options.filterCallback(null, options.index);
1446
+ const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
1447
+ if (!constraints.length) return;
1448
+ const colOperator = config.operator === "or" ? "or" : "and";
1449
+ if (config.collection === "campos" && config.fieldId) {
1450
+ if (!camposMap[config.fieldId]) {
1451
+ camposMap[config.fieldId] = { operator: colOperator, values: [] };
1452
+ }
1453
+ constraints.forEach((c) => {
1454
+ const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
1455
+ const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
1456
+ if (payload) camposMap[config.fieldId].values.push(payload);
1457
+ });
1385
1458
  return;
1386
1459
  }
1387
- const valueToFilter = mask ? mask(rawValue) : rawValue;
1388
- options.filterCallback(valueToFilter, options.index);
1389
- };
1390
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1391
- import_inputnumber.InputNumber,
1392
- {
1393
- value: parsedValue,
1394
- onValueChange: handleChange,
1395
- mode: "currency",
1396
- currency: "BRL",
1397
- locale: "pt-BR",
1398
- inputClassName: "custom-input"
1460
+ const columnPayloads = constraints.map(
1461
+ (c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
1462
+ ).filter(Boolean);
1463
+ if (!columnPayloads.length) return;
1464
+ if (config.collection) {
1465
+ const rootCollections = [];
1466
+ columnPayloads.forEach((payload) => {
1467
+ pushIntoCollectionTree(
1468
+ rootCollections,
1469
+ config.collection,
1470
+ payload.field ?? payload.not?.field,
1471
+ payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
1472
+ );
1473
+ });
1474
+ rootCollections.forEach((c) => finalAnd.push(c));
1475
+ return;
1399
1476
  }
1400
- );
1401
- };
1402
- var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
1403
- const selectOptions = items.length > 0 ? items : [
1404
- { label: isLanguagePtBr ? "Todos" : "All", value: null },
1405
- { label: isLanguagePtBr ? "Sim" : "Yes", value: true },
1406
- { label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
1407
- ];
1408
- const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
1409
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1410
- import_react_select.default,
1411
- {
1412
- options: selectOptions,
1413
- value: currentValue,
1414
- onChange: (selected) => options.filterCallback(selected?.value),
1415
- placeholder: "Todos",
1416
- isClearable: false,
1417
- isSearchable: false,
1418
- className: "custom-select-filtro",
1419
- classNamePrefix: "custom-select-filtro",
1420
- styles: {
1421
- control: (baseStyles, state) => ({
1422
- ...baseStyles,
1423
- "&:hover": {
1424
- borderColor: state.isFocused ? "#094394" : ""
1425
- },
1426
- borderRadius: "6px"
1427
- }),
1428
- menuList: (base) => ({
1429
- ...base,
1430
- "::-webkit-scrollbar": {
1431
- width: "6px",
1432
- height: "auto",
1433
- overflowX: "hidden",
1434
- overflowY: "hidden"
1435
- },
1436
- "::-webkit-scrollbar-track": {
1437
- background: "#fff"
1438
- },
1439
- "::-webkit-scrollbar-thumb": {
1440
- background: "#888",
1441
- borderRadius: "2rem"
1442
- },
1443
- "::-webkit-scrollbar-thumb:hover": {
1444
- background: "#555"
1445
- }
1446
- }),
1447
- option: (provided, state) => ({
1448
- ...provided,
1449
- backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1450
- color: state.isFocused ? "#ffffff" : "black",
1451
- "&:hover": {
1452
- backgroundColor: "#094394",
1453
- // Cor de fundo quando em hover
1454
- color: "#ffffff"
1455
- // Cor da palavra quando em hover
1456
- }
1457
- })
1477
+ finalAnd.push({ [colOperator]: columnPayloads });
1478
+ });
1479
+ Object.entries(camposMap).forEach(([fieldId, config]) => {
1480
+ if (!config.values.length) return;
1481
+ finalAnd.push({
1482
+ collection: "campos",
1483
+ any: {
1484
+ and: [
1485
+ { field: "tipocampo.id", operator: "Equals", value: fieldId },
1486
+ { [config.operator]: config.values }
1487
+ ]
1458
1488
  }
1489
+ });
1490
+ });
1491
+ return finalAnd.length ? { and: finalAnd } : void 0;
1492
+ };
1493
+ function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
1494
+ const collections = collectionPath.split(".");
1495
+ let current = root;
1496
+ collections.forEach((collection) => {
1497
+ let node = current.find(
1498
+ (n) => n.collection === collection && n.any
1499
+ );
1500
+ if (!node) {
1501
+ node = {
1502
+ collection,
1503
+ any: { or: [] }
1504
+ };
1505
+ current.push(node);
1459
1506
  }
1507
+ current = node.any.or;
1508
+ });
1509
+ current.push({
1510
+ ...payloadBase,
1511
+ field: fieldName
1512
+ });
1513
+ }
1514
+ function getMatchModeByTipo(tipo) {
1515
+ switch (tipo) {
1516
+ case "NumeroInteiro":
1517
+ case "NumeroDecimal":
1518
+ return import_api4.FilterMatchMode.EQUALS;
1519
+ default:
1520
+ return import_api4.FilterMatchMode.CONTAINS;
1521
+ }
1522
+ }
1523
+ function buildDynamicCampoFilters(campos) {
1524
+ return campos?.reduce((acc, campo) => {
1525
+ acc[`${campo.id}`] = {
1526
+ operator: import_api4.FilterOperator.AND,
1527
+ constraints: [
1528
+ {
1529
+ value: null,
1530
+ matchMode: getMatchModeByTipo(campo.tipoDado)
1531
+ }
1532
+ ],
1533
+ collection: "campos",
1534
+ filterFieldCollection: "valor",
1535
+ fieldId: campo.id
1536
+ // opcional (útil pro backend)
1537
+ };
1538
+ return acc;
1539
+ }, {});
1540
+ }
1541
+ var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
1542
+ const params = new URLSearchParams(
1543
+ typeof window !== "undefined" ? window.location.search : ""
1460
1544
  );
1545
+ return {
1546
+ page: Number(params.get("page") ?? 1),
1547
+ rows: Number(params.get("rows") ?? 10),
1548
+ sortField: params.get("sortField") || sortFieldInitial || "",
1549
+ sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
1550
+ filter: params.get("filter") ?? ""
1551
+ };
1461
1552
  };
1462
- var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1463
- const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
1464
- const rawFilter = options.value ?? {};
1465
- const currentMatchMode = rawFilter.matchMode ?? "contains";
1466
- const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
1467
- const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1468
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1469
- "div",
1553
+ function buildSortingWithFilters(filters, sortField, order) {
1554
+ const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
1555
+ let sorting = [
1470
1556
  {
1471
- className: "filter-wrapper",
1472
- style: {
1473
- display: "flex",
1474
- flexDirection: "column",
1475
- gap: "8px",
1476
- minWidth: "200px"
1477
- },
1478
- children: [
1479
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1480
- import_dropdown.Dropdown,
1481
- {
1482
- value: currentMatchMode,
1483
- options: resolvedItems,
1484
- optionLabel: "label",
1485
- optionValue: "value",
1486
- placeholder: "Tipo de filtro",
1487
- style: { width: "100%" },
1488
- onChange: (e) => {
1489
- const newMatchMode = e.value;
1490
- const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
1491
- if (isNewSpecial) {
1492
- options.filterCallback({
1493
- text: null,
1494
- matchMode: newMatchMode
1495
- });
1496
- return;
1497
- }
1498
- options.filterCallback({
1499
- text: null,
1500
- matchMode: newMatchMode
1501
- });
1502
- }
1503
- }
1504
- ),
1505
- !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1506
- import_inputtext.InputText,
1507
- {
1508
- value: currentValue,
1509
- placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1510
- style: { width: "100%" },
1511
- className: "p-column-filter",
1512
- onChange: (e) => {
1513
- const value = e.target.value;
1514
- if (value.trim()) {
1515
- options.filterCallback({
1516
- text: value,
1517
- matchMode: currentMatchMode
1518
- });
1519
- } else {
1520
- options.filterCallback({
1521
- text: null,
1522
- matchMode: currentMatchMode
1523
- });
1524
- }
1525
- }
1526
- }
1527
- )
1528
- ]
1557
+ field: sortField,
1558
+ direction
1529
1559
  }
1530
- );
1531
- };
1532
-
1533
- // src/components/DataTableAdvancedFilter/filterModes.ts
1534
- var import_api4 = require("primereact/api");
1535
- var customMatchModes = {
1536
- notStartsWith: "notStartsWith",
1537
- notEndsWith: "notEndsWith",
1538
- empty: "empty",
1539
- notEmpty: "notEmpty"
1540
- };
1541
- var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
1542
- {
1543
- label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1544
- value: import_api4.FilterMatchMode.CONTAINS
1545
- },
1546
- {
1547
- label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1548
- value: import_api4.FilterMatchMode.NOT_CONTAINS
1549
- },
1550
- {
1551
- label: isLanguagePtBr ? "Igual" : "Equals",
1552
- value: import_api4.FilterMatchMode.EQUALS
1553
- },
1554
- {
1555
- label: isLanguagePtBr ? "Diferente" : "Not equals",
1556
- value: import_api4.FilterMatchMode.NOT_EQUALS
1557
- },
1558
- {
1559
- label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
1560
- value: import_api4.FilterMatchMode.STARTS_WITH
1561
- },
1562
- {
1563
- label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
1564
- value: customMatchModes.notStartsWith
1565
- },
1566
- {
1567
- label: isLanguagePtBr ? "Termina com" : "Ends with",
1568
- value: import_api4.FilterMatchMode.ENDS_WITH
1569
- },
1570
- {
1571
- label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
1572
- value: customMatchModes.notEndsWith
1573
- },
1574
- {
1575
- label: isLanguagePtBr ? "Vazio" : "Empty",
1576
- value: customMatchModes.empty
1577
- },
1578
- {
1579
- label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1580
- value: customMatchModes.notEmpty
1560
+ ];
1561
+ if (!filters || !sortField) {
1562
+ return sorting;
1581
1563
  }
1582
- ];
1583
- var getDefaultFilterMatchOptionsStringArray = (isLanguagePtBr = true) => [
1584
- {
1585
- label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1586
- value: import_api4.FilterMatchMode.CONTAINS
1587
- },
1588
- {
1589
- label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1590
- value: import_api4.FilterMatchMode.NOT_CONTAINS
1564
+ const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
1565
+ if (sortFilter?.fieldId) {
1566
+ sorting = [
1567
+ {
1568
+ collection: "campos",
1569
+ filter: {
1570
+ field: "tipocampo.id",
1571
+ operator: "equals",
1572
+ value: sortFilter.fieldId
1573
+ },
1574
+ first: {
1575
+ field: "valor",
1576
+ direction
1577
+ }
1578
+ }
1579
+ ];
1591
1580
  }
1592
- ];
1593
- var getDefaultFilterMatchOptionsDate = (isLanguagePtBr) => [
1594
- {
1595
- label: isLanguagePtBr ? "Data antes de" : "Date before",
1596
- value: import_api4.FilterMatchMode.DATE_BEFORE
1597
- },
1598
- {
1599
- label: isLanguagePtBr ? "Data depois de" : "Date after",
1600
- value: import_api4.FilterMatchMode.DATE_AFTER
1581
+ return sorting;
1582
+ }
1583
+ function normalizeFilterValue(raw) {
1584
+ if (raw === null || raw === void 0) return null;
1585
+ if (typeof raw === "boolean") {
1586
+ return String(raw);
1601
1587
  }
1602
- ];
1603
- var getDefaultFilterMatchOptionsEnum = (isLanguagePtBr) => [
1604
- {
1605
- label: isLanguagePtBr ? "Igual" : "Equals",
1606
- value: import_api4.FilterMatchMode.EQUALS
1607
- },
1608
- {
1609
- label: isLanguagePtBr ? "Diferente" : "Not equals",
1610
- value: import_api4.FilterMatchMode.NOT_EQUALS
1611
- },
1612
- {
1613
- label: isLanguagePtBr ? "Vazio" : "Empty",
1614
- value: customMatchModes.empty
1615
- },
1616
- {
1617
- label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1618
- value: customMatchModes.notEmpty
1588
+ if (typeof raw === "number") {
1589
+ return raw;
1619
1590
  }
1620
- ];
1621
- var getDefaultFilterMatchOptionsEnumNotNullable = (isLanguagePtBr) => [
1622
- {
1623
- label: isLanguagePtBr ? "Igual" : "Equals",
1624
- value: import_api4.FilterMatchMode.EQUALS
1625
- },
1626
- {
1627
- label: isLanguagePtBr ? "Diferente" : "Not equals",
1628
- value: import_api4.FilterMatchMode.NOT_EQUALS
1591
+ if (typeof raw === "string") {
1592
+ return raw.trim() !== "" ? raw : null;
1629
1593
  }
1630
- ];
1594
+ if (typeof raw === "object") {
1595
+ if ("text" in raw && raw.text === null) {
1596
+ return "__NULL__";
1597
+ }
1598
+ if (typeof raw.text === "string") {
1599
+ return raw.text.trim() !== "" ? raw.text : null;
1600
+ }
1601
+ }
1602
+ return null;
1603
+ }
1604
+ function resolveMatchMode(constraintMatchMode, rawValue) {
1605
+ if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
1606
+ return rawValue.matchMode;
1607
+ }
1608
+ return constraintMatchMode;
1609
+ }
1631
1610
 
1632
1611
  // src/index.tsx
1633
1612
  var import_api5 = require("primereact/api");