@charlesgomes/leafcode-shared-lib-react 1.0.51 → 1.0.53

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,66 +582,39 @@ function DataTableAdvancedFilterWrapper({
863
582
  globalFilterFields
864
583
  )
865
584
  });
866
- const updateUrlParams = (params, mode = "push") => {
867
- if (typeof window === "undefined" || !replaceUrl) return;
868
- const urlParams = new URLSearchParams(window.location.search);
869
- Object.entries(params).forEach(([key, value]) => {
870
- if (value === void 0 || value === null || value === "") {
871
- urlParams.delete(key);
872
- } else {
873
- urlParams.set(
874
- key,
875
- typeof value === "string" ? value : JSON.stringify(value)
876
- );
877
- }
878
- });
879
- const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
880
- if (mode === "replace") {
881
- window.history.replaceState(null, "", newUrl);
882
- } else {
883
- window.history.pushState(null, "", newUrl);
884
- }
885
- };
886
- const hydrateFromUrl = () => {
887
- const params = new URLSearchParams(window.location.search);
888
- const pageParam = Number(params.get("page") ?? 1);
889
- const rowsParam = Number(params.get("rows") ?? rows);
890
- const sortFieldParam = params.get("sortField") ?? sortFieldInitial;
891
- const sortOrderParam = Number(params.get("sortOrder") ?? sortOrderInitial);
892
- const filterParam = params.get("filter") ?? "";
893
- setPage(pageParam);
894
- setRows(rowsParam);
895
- setFirst((pageParam - 1) * rowsParam);
896
- setSortField(sortFieldParam);
897
- setSortOrder(sortOrderParam);
898
- setSearchText(filterParam);
585
+ (0, import_react6.useEffect)(() => {
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 ?? "");
899
593
  setFilters((prev) => ({
900
594
  ...prev,
901
595
  global: {
902
596
  ...prev.global ?? { matchMode: "contains" },
903
- value: filterParam
597
+ value: state.filter ?? ""
904
598
  }
905
599
  }));
600
+ }, [state]);
601
+ const emitStateChange = (nextState) => {
602
+ if (!onStateChange) return;
603
+ onStateChange(nextState);
906
604
  };
907
- (0, import_react6.useEffect)(() => {
908
- if (typeof window === "undefined") return;
909
- const handlePopState = () => {
910
- hydrateFromUrl();
911
- };
912
- window.addEventListener("popstate", handlePopState);
913
- return () => {
914
- window.removeEventListener("popstate", handlePopState);
915
- };
916
- }, []);
917
605
  const onPage = (event) => {
918
606
  const newPage = event.page + 1;
607
+ const newRows = event.rows;
919
608
  setFirst(event.first);
920
- setRows(event.rows);
609
+ setRows(newRows);
921
610
  setPage(newPage);
922
- updateUrlParams(
923
- { page: newPage, rows: event.rows },
924
- "push"
925
- );
611
+ emitStateChange({
612
+ page: newPage,
613
+ rows: newRows,
614
+ sortField,
615
+ sortOrder,
616
+ filter: searchText
617
+ });
926
618
  };
927
619
  const onGlobalFilterChange = (e) => {
928
620
  const value = e.target.value;
@@ -938,16 +630,22 @@ function DataTableAdvancedFilterWrapper({
938
630
  const onSort = (e) => {
939
631
  setSortField(e.sortField);
940
632
  setSortOrder(e.sortOrder);
941
- updateUrlParams(
942
- { sortField: e.sortField, sortOrder: e.sortOrder },
943
- "push"
944
- );
633
+ emitStateChange({
634
+ page,
635
+ rows,
636
+ sortField: e.sortField,
637
+ sortOrder: e.sortOrder,
638
+ filter: searchText
639
+ });
945
640
  };
946
641
  (0, import_react6.useEffect)(() => {
947
- updateUrlParams(
948
- { page: 1, filter: debouncedSearch },
949
- "replace"
950
- );
642
+ emitStateChange({
643
+ page: 1,
644
+ rows,
645
+ sortField,
646
+ sortOrder,
647
+ filter: debouncedSearch
648
+ });
951
649
  }, [debouncedSearch]);
952
650
  (0, import_react6.useEffect)(() => {
953
651
  if (customers?.items && selectedRowsData.length > 0) {
@@ -1113,7 +811,7 @@ function DataTableAdvancedFilterWrapper({
1113
811
  }
1114
812
 
1115
813
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilter.tsx
1116
- var import_api3 = require("primereact/api");
814
+ var import_api2 = require("primereact/api");
1117
815
 
1118
816
  // src/components/DataTableAdvancedFilter/utils/locale.ts
1119
817
  var localePtBr = {
@@ -1284,21 +982,20 @@ function DataTableAdvancedFilter({
1284
982
  sortFieldInitial,
1285
983
  sortOrderInitial = 1,
1286
984
  isMultiSelectionMode = true,
1287
- isLanguagePtBr = true,
1288
- replaceUrl = true
985
+ isLanguagePtBr = true
1289
986
  }) {
1290
987
  const [isClient, setIsClient] = (0, import_react8.useState)(false);
1291
988
  (0, import_react8.useEffect)(() => {
1292
- (0, import_api3.addLocale)("pt", localePtBr);
989
+ (0, import_api2.addLocale)("pt", localePtBr);
1293
990
  }, []);
1294
991
  (0, import_react8.useEffect)(() => {
1295
- (0, import_api3.locale)(isLanguagePtBr ? "pt" : "en");
992
+ (0, import_api2.locale)(isLanguagePtBr ? "pt" : "en");
1296
993
  }, [isLanguagePtBr]);
1297
994
  (0, import_react8.useEffect)(() => {
1298
995
  setIsClient(true);
1299
996
  }, []);
1300
997
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: isClient && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1301
- import_api3.PrimeReactProvider,
998
+ import_api2.PrimeReactProvider,
1302
999
  {
1303
1000
  value: isLanguagePtBr ? { locale: "pt" } : { locale: "en" },
1304
1001
  children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
@@ -1317,8 +1014,7 @@ function DataTableAdvancedFilter({
1317
1014
  sortFieldInitial,
1318
1015
  sortOrderInitial,
1319
1016
  isMultiSelectionMode,
1320
- isLanguagePtBr,
1321
- replaceUrl
1017
+ isLanguagePtBr
1322
1018
  }
1323
1019
  )
1324
1020
  }
@@ -1337,301 +1033,583 @@ var DateFilterTemplate = (options, mask) => {
1337
1033
  {
1338
1034
  value: parsedValue,
1339
1035
  onChange: (e) => {
1340
- if (!e.value) {
1036
+ if (!e.value) {
1037
+ options.filterCallback(null, options.index);
1038
+ return;
1039
+ }
1040
+ const date = e.value;
1041
+ const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
1042
+ 2,
1043
+ "0"
1044
+ )}-${String(date.getDate()).padStart(2, "0")}`;
1045
+ options.filterCallback(valueToFilter, options.index);
1046
+ },
1047
+ dateFormat: "dd/mm/yy",
1048
+ placeholder: "dd/mm/yyyy",
1049
+ mask: "99/99/9999",
1050
+ inputClassName: "p-column-filter"
1051
+ }
1052
+ );
1053
+ };
1054
+ var DateTimeFilterTemplate = (options, mask) => {
1055
+ const value = typeof options.value === "string" ? (0, import_moment2.default)(options.value).toDate() : options.value ?? null;
1056
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1057
+ import_calendar.Calendar,
1058
+ {
1059
+ value,
1060
+ showTime: true,
1061
+ showSeconds: true,
1062
+ hourFormat: "24",
1063
+ dateFormat: "dd/mm/yy",
1064
+ placeholder: "dd/mm/yyyy 00:00:00",
1065
+ readOnlyInput: true,
1066
+ inputClassName: "p-column-filter",
1067
+ onChange: (e) => {
1068
+ const selectedDate = e.value;
1069
+ if (!selectedDate) {
1341
1070
  options.filterCallback(null, options.index);
1342
1071
  return;
1343
1072
  }
1344
- const date = e.value;
1345
- const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
1346
- 2,
1347
- "0"
1348
- )}-${String(date.getDate()).padStart(2, "0")}`;
1349
- options.filterCallback(valueToFilter, options.index);
1073
+ const formatted = mask ? mask(selectedDate) : (0, import_moment2.default)(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1074
+ options.filterCallback(formatted, options.index);
1075
+ }
1076
+ }
1077
+ );
1078
+ };
1079
+ var ValueFilterTemplate = (options, mask) => {
1080
+ const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
1081
+ const handleChange = (e) => {
1082
+ const rawValue = e.value;
1083
+ if (rawValue === null || rawValue === void 0) {
1084
+ options.filterCallback(null, options.index);
1085
+ return;
1086
+ }
1087
+ const valueToFilter = mask ? mask(rawValue) : rawValue;
1088
+ options.filterCallback(valueToFilter, options.index);
1089
+ };
1090
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1091
+ import_inputnumber.InputNumber,
1092
+ {
1093
+ value: parsedValue,
1094
+ onValueChange: handleChange,
1095
+ mode: "currency",
1096
+ currency: "BRL",
1097
+ locale: "pt-BR",
1098
+ inputClassName: "custom-input"
1099
+ }
1100
+ );
1101
+ };
1102
+ var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
1103
+ const selectOptions = items.length > 0 ? items : [
1104
+ { label: isLanguagePtBr ? "Todos" : "All", value: null },
1105
+ { label: isLanguagePtBr ? "Sim" : "Yes", value: true },
1106
+ { label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
1107
+ ];
1108
+ const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
1109
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1110
+ import_react_select.default,
1111
+ {
1112
+ options: selectOptions,
1113
+ value: currentValue,
1114
+ onChange: (selected) => options.filterCallback(selected?.value),
1115
+ placeholder: "Todos",
1116
+ isClearable: false,
1117
+ isSearchable: false,
1118
+ className: "custom-select-filtro",
1119
+ classNamePrefix: "custom-select-filtro",
1120
+ styles: {
1121
+ control: (baseStyles, state) => ({
1122
+ ...baseStyles,
1123
+ "&:hover": {
1124
+ borderColor: state.isFocused ? "#094394" : ""
1125
+ },
1126
+ borderRadius: "6px"
1127
+ }),
1128
+ menuList: (base) => ({
1129
+ ...base,
1130
+ "::-webkit-scrollbar": {
1131
+ width: "6px",
1132
+ height: "auto",
1133
+ overflowX: "hidden",
1134
+ overflowY: "hidden"
1135
+ },
1136
+ "::-webkit-scrollbar-track": {
1137
+ background: "#fff"
1138
+ },
1139
+ "::-webkit-scrollbar-thumb": {
1140
+ background: "#888",
1141
+ borderRadius: "2rem"
1142
+ },
1143
+ "::-webkit-scrollbar-thumb:hover": {
1144
+ background: "#555"
1145
+ }
1146
+ }),
1147
+ option: (provided, state) => ({
1148
+ ...provided,
1149
+ backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1150
+ color: state.isFocused ? "#ffffff" : "black",
1151
+ "&:hover": {
1152
+ backgroundColor: "#094394",
1153
+ // Cor de fundo quando em hover
1154
+ color: "#ffffff"
1155
+ // Cor da palavra quando em hover
1156
+ }
1157
+ })
1158
+ }
1159
+ }
1160
+ );
1161
+ };
1162
+ var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1163
+ const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
1164
+ const rawFilter = options.value ?? {};
1165
+ const currentMatchMode = rawFilter.matchMode ?? "contains";
1166
+ const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
1167
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1168
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1169
+ "div",
1170
+ {
1171
+ className: "filter-wrapper",
1172
+ style: {
1173
+ display: "flex",
1174
+ flexDirection: "column",
1175
+ gap: "8px",
1176
+ minWidth: "200px"
1350
1177
  },
1351
- dateFormat: "dd/mm/yy",
1352
- placeholder: "dd/mm/yyyy",
1353
- mask: "99/99/9999",
1354
- inputClassName: "p-column-filter"
1178
+ children: [
1179
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1180
+ import_dropdown.Dropdown,
1181
+ {
1182
+ value: currentMatchMode,
1183
+ options: resolvedItems,
1184
+ optionLabel: "label",
1185
+ optionValue: "value",
1186
+ placeholder: "Tipo de filtro",
1187
+ style: { width: "100%" },
1188
+ onChange: (e) => {
1189
+ const newMatchMode = e.value;
1190
+ const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
1191
+ if (isNewSpecial) {
1192
+ options.filterCallback({
1193
+ text: null,
1194
+ matchMode: newMatchMode
1195
+ });
1196
+ return;
1197
+ }
1198
+ options.filterCallback({
1199
+ text: null,
1200
+ matchMode: newMatchMode
1201
+ });
1202
+ }
1203
+ }
1204
+ ),
1205
+ !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1206
+ import_inputtext.InputText,
1207
+ {
1208
+ value: currentValue,
1209
+ placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1210
+ style: { width: "100%" },
1211
+ className: "p-column-filter",
1212
+ onChange: (e) => {
1213
+ const value = e.target.value;
1214
+ if (value.trim()) {
1215
+ options.filterCallback({
1216
+ text: value,
1217
+ matchMode: currentMatchMode
1218
+ });
1219
+ } else {
1220
+ options.filterCallback({
1221
+ text: null,
1222
+ matchMode: currentMatchMode
1223
+ });
1224
+ }
1225
+ }
1226
+ }
1227
+ )
1228
+ ]
1229
+ }
1230
+ );
1231
+ };
1232
+
1233
+ // src/components/DataTableAdvancedFilter/filterModes.ts
1234
+ var import_api3 = require("primereact/api");
1235
+ var customMatchModes = {
1236
+ notStartsWith: "notStartsWith",
1237
+ notEndsWith: "notEndsWith",
1238
+ empty: "empty",
1239
+ notEmpty: "notEmpty"
1240
+ };
1241
+ var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
1242
+ {
1243
+ label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1244
+ value: import_api3.FilterMatchMode.CONTAINS
1245
+ },
1246
+ {
1247
+ label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1248
+ value: import_api3.FilterMatchMode.NOT_CONTAINS
1249
+ },
1250
+ {
1251
+ label: isLanguagePtBr ? "Igual" : "Equals",
1252
+ value: import_api3.FilterMatchMode.EQUALS
1253
+ },
1254
+ {
1255
+ label: isLanguagePtBr ? "Diferente" : "Not equals",
1256
+ value: import_api3.FilterMatchMode.NOT_EQUALS
1257
+ },
1258
+ {
1259
+ label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
1260
+ value: import_api3.FilterMatchMode.STARTS_WITH
1261
+ },
1262
+ {
1263
+ label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
1264
+ value: customMatchModes.notStartsWith
1265
+ },
1266
+ {
1267
+ label: isLanguagePtBr ? "Termina com" : "Ends with",
1268
+ value: import_api3.FilterMatchMode.ENDS_WITH
1269
+ },
1270
+ {
1271
+ label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
1272
+ value: customMatchModes.notEndsWith
1273
+ },
1274
+ {
1275
+ label: isLanguagePtBr ? "Vazio" : "Empty",
1276
+ value: customMatchModes.empty
1277
+ },
1278
+ {
1279
+ label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1280
+ value: customMatchModes.notEmpty
1281
+ }
1282
+ ];
1283
+ var getDefaultFilterMatchOptionsStringArray = (isLanguagePtBr = true) => [
1284
+ {
1285
+ label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1286
+ value: import_api3.FilterMatchMode.CONTAINS
1287
+ },
1288
+ {
1289
+ label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1290
+ value: import_api3.FilterMatchMode.NOT_CONTAINS
1291
+ }
1292
+ ];
1293
+ var getDefaultFilterMatchOptionsDate = (isLanguagePtBr) => [
1294
+ {
1295
+ label: isLanguagePtBr ? "Data antes de" : "Date before",
1296
+ value: import_api3.FilterMatchMode.DATE_BEFORE
1297
+ },
1298
+ {
1299
+ label: isLanguagePtBr ? "Data depois de" : "Date after",
1300
+ value: import_api3.FilterMatchMode.DATE_AFTER
1301
+ }
1302
+ ];
1303
+ var getDefaultFilterMatchOptionsEnum = (isLanguagePtBr) => [
1304
+ {
1305
+ label: isLanguagePtBr ? "Igual" : "Equals",
1306
+ value: import_api3.FilterMatchMode.EQUALS
1307
+ },
1308
+ {
1309
+ label: isLanguagePtBr ? "Diferente" : "Not equals",
1310
+ value: import_api3.FilterMatchMode.NOT_EQUALS
1311
+ },
1312
+ {
1313
+ label: isLanguagePtBr ? "Vazio" : "Empty",
1314
+ value: customMatchModes.empty
1315
+ },
1316
+ {
1317
+ label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1318
+ value: customMatchModes.notEmpty
1319
+ }
1320
+ ];
1321
+ var getDefaultFilterMatchOptionsEnumNotNullable = (isLanguagePtBr) => [
1322
+ {
1323
+ label: isLanguagePtBr ? "Igual" : "Equals",
1324
+ value: import_api3.FilterMatchMode.EQUALS
1325
+ },
1326
+ {
1327
+ label: isLanguagePtBr ? "Diferente" : "Not equals",
1328
+ value: import_api3.FilterMatchMode.NOT_EQUALS
1329
+ }
1330
+ ];
1331
+
1332
+ // src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
1333
+ var import_api4 = require("primereact/api");
1334
+ var mapMatchMode = (mode) => {
1335
+ switch (mode) {
1336
+ case "startsWith":
1337
+ return "StartsWith";
1338
+ case "contains":
1339
+ return "Contains";
1340
+ case "equals":
1341
+ return "Equals";
1342
+ case "notEquals":
1343
+ return "notEquals";
1344
+ case "endsWith":
1345
+ return "EndsWith";
1346
+ case "lt":
1347
+ case "dateBefore":
1348
+ return "LessThan";
1349
+ case "lte":
1350
+ return "LessThanOrEqualTo";
1351
+ case "gt":
1352
+ case "dateAfter":
1353
+ return "GreaterThan";
1354
+ case "gte":
1355
+ return "GreaterThanOrEqualTo";
1356
+ case "notContains":
1357
+ return "NotContains";
1358
+ case "empty":
1359
+ return "Empty";
1360
+ default:
1361
+ return "Equals";
1362
+ }
1363
+ };
1364
+ var buildFilterPayload = (fieldName, matchMode, rawValue) => {
1365
+ const normalized = normalizeFilterValue(rawValue);
1366
+ if (matchMode === "empty") {
1367
+ return {
1368
+ field: fieldName,
1369
+ operator: "Empty"
1370
+ };
1371
+ }
1372
+ if (matchMode === "notEmpty") {
1373
+ return {
1374
+ not: {
1375
+ field: fieldName,
1376
+ operator: "Empty"
1377
+ }
1378
+ };
1379
+ }
1380
+ if (normalized === null) return null;
1381
+ if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
1382
+ matchMode === "dateIsNot" || matchMode === "notContains") {
1383
+ let operator;
1384
+ switch (matchMode) {
1385
+ case "notStartsWith":
1386
+ operator = "StartsWith";
1387
+ break;
1388
+ case "notEndsWith":
1389
+ operator = "EndsWith";
1390
+ break;
1391
+ case "notContains":
1392
+ operator = "Contains";
1393
+ break;
1394
+ case "notEquals":
1395
+ case "dateIsNot":
1396
+ default:
1397
+ operator = "Equals";
1355
1398
  }
1356
- );
1399
+ return {
1400
+ not: {
1401
+ field: fieldName,
1402
+ operator,
1403
+ value: normalized
1404
+ }
1405
+ };
1406
+ }
1407
+ return {
1408
+ field: fieldName,
1409
+ operator: mapMatchMode(matchMode),
1410
+ value: normalized
1411
+ };
1357
1412
  };
1358
- var DateTimeFilterTemplate = (options, mask) => {
1359
- const value = typeof options.value === "string" ? (0, import_moment2.default)(options.value).toDate() : options.value ?? null;
1360
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1361
- import_calendar.Calendar,
1362
- {
1363
- value,
1364
- showTime: true,
1365
- showSeconds: true,
1366
- hourFormat: "24",
1367
- dateFormat: "dd/mm/yy",
1368
- placeholder: "dd/mm/yyyy 00:00:00",
1369
- readOnlyInput: true,
1370
- inputClassName: "p-column-filter",
1371
- onChange: (e) => {
1372
- const selectedDate = e.value;
1373
- if (!selectedDate) {
1374
- options.filterCallback(null, options.index);
1413
+ var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
1414
+ const finalAnd = [];
1415
+ const globalOr = [];
1416
+ const camposMap = {};
1417
+ Object.entries(filters).forEach(([field, config]) => {
1418
+ if (!config) return;
1419
+ const value = config?.value?.text ?? config?.value;
1420
+ if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
1421
+ const globalOrNodes = [];
1422
+ globalFilterFields.forEach((globalField) => {
1423
+ const fieldConfig = filters[globalField];
1424
+ if (!fieldConfig) return;
1425
+ const payload = buildFilterPayload(
1426
+ fieldConfig.filterFieldCollection ?? globalField,
1427
+ resolveMatchMode(config.matchMode, config.value),
1428
+ config.value
1429
+ );
1430
+ if (!payload) return;
1431
+ if (!fieldConfig.collection) {
1432
+ globalOrNodes.push(payload);
1375
1433
  return;
1376
1434
  }
1377
- const formatted = mask ? mask(selectedDate) : (0, import_moment2.default)(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1378
- options.filterCallback(formatted, options.index);
1435
+ const rootCollections = [];
1436
+ pushIntoCollectionTree(
1437
+ rootCollections,
1438
+ fieldConfig.collection,
1439
+ payload.field ?? payload.not?.field,
1440
+ payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
1441
+ );
1442
+ globalOrNodes.push(...rootCollections);
1443
+ });
1444
+ if (globalOrNodes.length) {
1445
+ finalAnd.push({ or: globalOrNodes });
1379
1446
  }
1447
+ return;
1380
1448
  }
1381
- );
1382
- };
1383
- var ValueFilterTemplate = (options, mask) => {
1384
- const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
1385
- const handleChange = (e) => {
1386
- const rawValue = e.value;
1387
- if (rawValue === null || rawValue === void 0) {
1388
- options.filterCallback(null, options.index);
1449
+ const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
1450
+ if (!constraints.length) return;
1451
+ const colOperator = config.operator === "or" ? "or" : "and";
1452
+ if (config.collection === "campos" && config.fieldId) {
1453
+ if (!camposMap[config.fieldId]) {
1454
+ camposMap[config.fieldId] = { operator: colOperator, values: [] };
1455
+ }
1456
+ constraints.forEach((c) => {
1457
+ const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
1458
+ const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
1459
+ if (payload) camposMap[config.fieldId].values.push(payload);
1460
+ });
1389
1461
  return;
1390
1462
  }
1391
- const valueToFilter = mask ? mask(rawValue) : rawValue;
1392
- options.filterCallback(valueToFilter, options.index);
1393
- };
1394
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1395
- import_inputnumber.InputNumber,
1396
- {
1397
- value: parsedValue,
1398
- onValueChange: handleChange,
1399
- mode: "currency",
1400
- currency: "BRL",
1401
- locale: "pt-BR",
1402
- inputClassName: "custom-input"
1463
+ const columnPayloads = constraints.map(
1464
+ (c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
1465
+ ).filter(Boolean);
1466
+ if (!columnPayloads.length) return;
1467
+ if (config.collection) {
1468
+ const rootCollections = [];
1469
+ columnPayloads.forEach((payload) => {
1470
+ pushIntoCollectionTree(
1471
+ rootCollections,
1472
+ config.collection,
1473
+ payload.field ?? payload.not?.field,
1474
+ payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
1475
+ );
1476
+ });
1477
+ rootCollections.forEach((c) => finalAnd.push(c));
1478
+ return;
1403
1479
  }
1404
- );
1405
- };
1406
- var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
1407
- const selectOptions = items.length > 0 ? items : [
1408
- { label: isLanguagePtBr ? "Todos" : "All", value: null },
1409
- { label: isLanguagePtBr ? "Sim" : "Yes", value: true },
1410
- { label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
1411
- ];
1412
- const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
1413
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1414
- import_react_select.default,
1415
- {
1416
- options: selectOptions,
1417
- value: currentValue,
1418
- onChange: (selected) => options.filterCallback(selected?.value),
1419
- placeholder: "Todos",
1420
- isClearable: false,
1421
- isSearchable: false,
1422
- className: "custom-select-filtro",
1423
- classNamePrefix: "custom-select-filtro",
1424
- styles: {
1425
- control: (baseStyles, state) => ({
1426
- ...baseStyles,
1427
- "&:hover": {
1428
- borderColor: state.isFocused ? "#094394" : ""
1429
- },
1430
- borderRadius: "6px"
1431
- }),
1432
- menuList: (base) => ({
1433
- ...base,
1434
- "::-webkit-scrollbar": {
1435
- width: "6px",
1436
- height: "auto",
1437
- overflowX: "hidden",
1438
- overflowY: "hidden"
1439
- },
1440
- "::-webkit-scrollbar-track": {
1441
- background: "#fff"
1442
- },
1443
- "::-webkit-scrollbar-thumb": {
1444
- background: "#888",
1445
- borderRadius: "2rem"
1446
- },
1447
- "::-webkit-scrollbar-thumb:hover": {
1448
- background: "#555"
1449
- }
1450
- }),
1451
- option: (provided, state) => ({
1452
- ...provided,
1453
- backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1454
- color: state.isFocused ? "#ffffff" : "black",
1455
- "&:hover": {
1456
- backgroundColor: "#094394",
1457
- // Cor de fundo quando em hover
1458
- color: "#ffffff"
1459
- // Cor da palavra quando em hover
1460
- }
1461
- })
1480
+ finalAnd.push({ [colOperator]: columnPayloads });
1481
+ });
1482
+ Object.entries(camposMap).forEach(([fieldId, config]) => {
1483
+ if (!config.values.length) return;
1484
+ finalAnd.push({
1485
+ collection: "campos",
1486
+ any: {
1487
+ and: [
1488
+ { field: "tipocampo.id", operator: "Equals", value: fieldId },
1489
+ { [config.operator]: config.values }
1490
+ ]
1462
1491
  }
1492
+ });
1493
+ });
1494
+ return finalAnd.length ? { and: finalAnd } : void 0;
1495
+ };
1496
+ function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
1497
+ const collections = collectionPath.split(".");
1498
+ let current = root;
1499
+ collections.forEach((collection) => {
1500
+ let node = current.find(
1501
+ (n) => n.collection === collection && n.any
1502
+ );
1503
+ if (!node) {
1504
+ node = {
1505
+ collection,
1506
+ any: { or: [] }
1507
+ };
1508
+ current.push(node);
1463
1509
  }
1510
+ current = node.any.or;
1511
+ });
1512
+ current.push({
1513
+ ...payloadBase,
1514
+ field: fieldName
1515
+ });
1516
+ }
1517
+ function getMatchModeByTipo(tipo) {
1518
+ switch (tipo) {
1519
+ case "NumeroInteiro":
1520
+ case "NumeroDecimal":
1521
+ return import_api4.FilterMatchMode.EQUALS;
1522
+ default:
1523
+ return import_api4.FilterMatchMode.CONTAINS;
1524
+ }
1525
+ }
1526
+ function buildDynamicCampoFilters(campos) {
1527
+ return campos?.reduce((acc, campo) => {
1528
+ acc[`${campo.id}`] = {
1529
+ operator: import_api4.FilterOperator.AND,
1530
+ constraints: [
1531
+ {
1532
+ value: null,
1533
+ matchMode: getMatchModeByTipo(campo.tipoDado)
1534
+ }
1535
+ ],
1536
+ collection: "campos",
1537
+ filterFieldCollection: "valor",
1538
+ fieldId: campo.id
1539
+ // opcional (útil pro backend)
1540
+ };
1541
+ return acc;
1542
+ }, {});
1543
+ }
1544
+ var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
1545
+ const params = new URLSearchParams(
1546
+ typeof window !== "undefined" ? window.location.search : ""
1464
1547
  );
1548
+ return {
1549
+ page: Number(params.get("page") ?? 1),
1550
+ rows: Number(params.get("rows") ?? 10),
1551
+ sortField: params.get("sortField") || sortFieldInitial || "",
1552
+ sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
1553
+ filter: params.get("filter") ?? ""
1554
+ };
1465
1555
  };
1466
- var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1467
- const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
1468
- const rawFilter = options.value ?? {};
1469
- const currentMatchMode = rawFilter.matchMode ?? "contains";
1470
- const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
1471
- const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1472
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1473
- "div",
1556
+ function buildSortingWithFilters(filters, sortField, order) {
1557
+ const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
1558
+ let sorting = [
1474
1559
  {
1475
- className: "filter-wrapper",
1476
- style: {
1477
- display: "flex",
1478
- flexDirection: "column",
1479
- gap: "8px",
1480
- minWidth: "200px"
1481
- },
1482
- children: [
1483
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1484
- import_dropdown.Dropdown,
1485
- {
1486
- value: currentMatchMode,
1487
- options: resolvedItems,
1488
- optionLabel: "label",
1489
- optionValue: "value",
1490
- placeholder: "Tipo de filtro",
1491
- style: { width: "100%" },
1492
- onChange: (e) => {
1493
- const newMatchMode = e.value;
1494
- const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
1495
- if (isNewSpecial) {
1496
- options.filterCallback({
1497
- text: null,
1498
- matchMode: newMatchMode
1499
- });
1500
- return;
1501
- }
1502
- options.filterCallback({
1503
- text: null,
1504
- matchMode: newMatchMode
1505
- });
1506
- }
1507
- }
1508
- ),
1509
- !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1510
- import_inputtext.InputText,
1511
- {
1512
- value: currentValue,
1513
- placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1514
- style: { width: "100%" },
1515
- className: "p-column-filter",
1516
- onChange: (e) => {
1517
- const value = e.target.value;
1518
- if (value.trim()) {
1519
- options.filterCallback({
1520
- text: value,
1521
- matchMode: currentMatchMode
1522
- });
1523
- } else {
1524
- options.filterCallback({
1525
- text: null,
1526
- matchMode: currentMatchMode
1527
- });
1528
- }
1529
- }
1530
- }
1531
- )
1532
- ]
1560
+ field: sortField,
1561
+ direction
1533
1562
  }
1534
- );
1535
- };
1536
-
1537
- // src/components/DataTableAdvancedFilter/filterModes.ts
1538
- var import_api4 = require("primereact/api");
1539
- var customMatchModes = {
1540
- notStartsWith: "notStartsWith",
1541
- notEndsWith: "notEndsWith",
1542
- empty: "empty",
1543
- notEmpty: "notEmpty"
1544
- };
1545
- var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
1546
- {
1547
- label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1548
- value: import_api4.FilterMatchMode.CONTAINS
1549
- },
1550
- {
1551
- label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1552
- value: import_api4.FilterMatchMode.NOT_CONTAINS
1553
- },
1554
- {
1555
- label: isLanguagePtBr ? "Igual" : "Equals",
1556
- value: import_api4.FilterMatchMode.EQUALS
1557
- },
1558
- {
1559
- label: isLanguagePtBr ? "Diferente" : "Not equals",
1560
- value: import_api4.FilterMatchMode.NOT_EQUALS
1561
- },
1562
- {
1563
- label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
1564
- value: import_api4.FilterMatchMode.STARTS_WITH
1565
- },
1566
- {
1567
- label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
1568
- value: customMatchModes.notStartsWith
1569
- },
1570
- {
1571
- label: isLanguagePtBr ? "Termina com" : "Ends with",
1572
- value: import_api4.FilterMatchMode.ENDS_WITH
1573
- },
1574
- {
1575
- label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
1576
- value: customMatchModes.notEndsWith
1577
- },
1578
- {
1579
- label: isLanguagePtBr ? "Vazio" : "Empty",
1580
- value: customMatchModes.empty
1581
- },
1582
- {
1583
- label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1584
- value: customMatchModes.notEmpty
1563
+ ];
1564
+ if (!filters || !sortField) {
1565
+ return sorting;
1585
1566
  }
1586
- ];
1587
- var getDefaultFilterMatchOptionsStringArray = (isLanguagePtBr = true) => [
1588
- {
1589
- label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
1590
- value: import_api4.FilterMatchMode.CONTAINS
1591
- },
1592
- {
1593
- label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
1594
- value: import_api4.FilterMatchMode.NOT_CONTAINS
1567
+ const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
1568
+ if (sortFilter?.fieldId) {
1569
+ sorting = [
1570
+ {
1571
+ collection: "campos",
1572
+ filter: {
1573
+ field: "tipocampo.id",
1574
+ operator: "equals",
1575
+ value: sortFilter.fieldId
1576
+ },
1577
+ first: {
1578
+ field: "valor",
1579
+ direction
1580
+ }
1581
+ }
1582
+ ];
1595
1583
  }
1596
- ];
1597
- var getDefaultFilterMatchOptionsDate = (isLanguagePtBr) => [
1598
- {
1599
- label: isLanguagePtBr ? "Data antes de" : "Date before",
1600
- value: import_api4.FilterMatchMode.DATE_BEFORE
1601
- },
1602
- {
1603
- label: isLanguagePtBr ? "Data depois de" : "Date after",
1604
- value: import_api4.FilterMatchMode.DATE_AFTER
1584
+ return sorting;
1585
+ }
1586
+ function normalizeFilterValue(raw) {
1587
+ if (raw === null || raw === void 0) return null;
1588
+ if (typeof raw === "boolean") {
1589
+ return String(raw);
1605
1590
  }
1606
- ];
1607
- var getDefaultFilterMatchOptionsEnum = (isLanguagePtBr) => [
1608
- {
1609
- label: isLanguagePtBr ? "Igual" : "Equals",
1610
- value: import_api4.FilterMatchMode.EQUALS
1611
- },
1612
- {
1613
- label: isLanguagePtBr ? "Diferente" : "Not equals",
1614
- value: import_api4.FilterMatchMode.NOT_EQUALS
1615
- },
1616
- {
1617
- label: isLanguagePtBr ? "Vazio" : "Empty",
1618
- value: customMatchModes.empty
1619
- },
1620
- {
1621
- label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
1622
- value: customMatchModes.notEmpty
1591
+ if (typeof raw === "number") {
1592
+ return raw;
1623
1593
  }
1624
- ];
1625
- var getDefaultFilterMatchOptionsEnumNotNullable = (isLanguagePtBr) => [
1626
- {
1627
- label: isLanguagePtBr ? "Igual" : "Equals",
1628
- value: import_api4.FilterMatchMode.EQUALS
1629
- },
1630
- {
1631
- label: isLanguagePtBr ? "Diferente" : "Not equals",
1632
- value: import_api4.FilterMatchMode.NOT_EQUALS
1594
+ if (typeof raw === "string") {
1595
+ return raw.trim() !== "" ? raw : null;
1633
1596
  }
1634
- ];
1597
+ if (typeof raw === "object") {
1598
+ if ("text" in raw && raw.text === null) {
1599
+ return "__NULL__";
1600
+ }
1601
+ if (typeof raw.text === "string") {
1602
+ return raw.text.trim() !== "" ? raw.text : null;
1603
+ }
1604
+ }
1605
+ return null;
1606
+ }
1607
+ function resolveMatchMode(constraintMatchMode, rawValue) {
1608
+ if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
1609
+ return rawValue.matchMode;
1610
+ }
1611
+ return constraintMatchMode;
1612
+ }
1635
1613
 
1636
1614
  // src/index.tsx
1637
1615
  var import_api5 = require("primereact/api");