@charlesgomes/leafcode-shared-lib-react 1.0.44 → 1.0.46

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.css CHANGED
@@ -439,9 +439,6 @@ th {
439
439
  .p-datatable .p-datatable-tbody > tr > td:nth-last-child(2) {
440
440
  border-right: 1px solid #edf0f2 !important;
441
441
  }
442
- .react-tooltip {
443
- z-index: 99 !important;
444
- }
445
442
  .box-icones-actions-column:hover {
446
443
  opacity: 1;
447
444
  }
@@ -520,3 +517,9 @@ th {
520
517
  .p-datepicker-calendar th {
521
518
  padding: 0;
522
519
  }
520
+ .p-datatable-scrollable-table > .p-datatable-thead {
521
+ z-index: 11;
522
+ }
523
+ .react-tooltip {
524
+ z-index: 11 !important;
525
+ }
package/dist/index.d.mts CHANGED
@@ -126,4 +126,22 @@ declare const getDefaultFilterMatchOptionsEnumNotNullable: (isLanguagePtBr: bool
126
126
  value: FilterMatchMode;
127
127
  }[];
128
128
 
129
- export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, type IDataTableProps, type IItemProps, ModalBase, SelectFilterTemplate, ValueFilterTemplate, customMatchModes, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsEnumNotNullable, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray };
129
+ declare const mapPrimeToBackendFilters: (filters: any, globalFilterFields: string[]) => {
130
+ and: any[];
131
+ } | undefined;
132
+ type CampoDinamico = {
133
+ id: string;
134
+ tipoDado: string;
135
+ };
136
+ declare function buildDynamicCampoFilters(campos: CampoDinamico[]): Record<string, any>;
137
+ declare const getUrlParams: (sortFieldInitial: string, sortOrderInitial: 1 | -1) => {
138
+ page: number;
139
+ rows: number;
140
+ sortField: string;
141
+ sortOrder: 1 | -1;
142
+ filter: string;
143
+ };
144
+ type SortingResult = any[];
145
+ declare function buildSortingWithFilters(filters: Record<string, any>, sortField?: string, order?: number): SortingResult;
146
+
147
+ export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, type IDataTableProps, type IItemProps, ModalBase, SelectFilterTemplate, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsEnumNotNullable, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getUrlParams, mapPrimeToBackendFilters };
package/dist/index.d.ts CHANGED
@@ -126,4 +126,22 @@ declare const getDefaultFilterMatchOptionsEnumNotNullable: (isLanguagePtBr: bool
126
126
  value: FilterMatchMode;
127
127
  }[];
128
128
 
129
- export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, type IDataTableProps, type IItemProps, ModalBase, SelectFilterTemplate, ValueFilterTemplate, customMatchModes, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsEnumNotNullable, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray };
129
+ declare const mapPrimeToBackendFilters: (filters: any, globalFilterFields: string[]) => {
130
+ and: any[];
131
+ } | undefined;
132
+ type CampoDinamico = {
133
+ id: string;
134
+ tipoDado: string;
135
+ };
136
+ declare function buildDynamicCampoFilters(campos: CampoDinamico[]): Record<string, any>;
137
+ declare const getUrlParams: (sortFieldInitial: string, sortOrderInitial: 1 | -1) => {
138
+ page: number;
139
+ rows: number;
140
+ sortField: string;
141
+ sortOrder: 1 | -1;
142
+ filter: string;
143
+ };
144
+ type SortingResult = any[];
145
+ declare function buildSortingWithFilters(filters: Record<string, any>, sortField?: string, order?: number): SortingResult;
146
+
147
+ export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, type IDataTableProps, type IItemProps, ModalBase, SelectFilterTemplate, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsEnumNotNullable, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getUrlParams, mapPrimeToBackendFilters };
package/dist/index.js CHANGED
@@ -40,12 +40,16 @@ __export(index_exports, {
40
40
  ModalBase: () => ModalBase,
41
41
  SelectFilterTemplate: () => SelectFilterTemplate,
42
42
  ValueFilterTemplate: () => ValueFilterTemplate,
43
+ buildDynamicCampoFilters: () => buildDynamicCampoFilters,
44
+ buildSortingWithFilters: () => buildSortingWithFilters,
43
45
  customMatchModes: () => customMatchModes,
44
46
  getDefaultFilterMatchOptionsDate: () => getDefaultFilterMatchOptionsDate,
45
47
  getDefaultFilterMatchOptionsEnum: () => getDefaultFilterMatchOptionsEnum,
46
48
  getDefaultFilterMatchOptionsEnumNotNullable: () => getDefaultFilterMatchOptionsEnumNotNullable,
47
49
  getDefaultFilterMatchOptionsString: () => getDefaultFilterMatchOptionsString,
48
- getDefaultFilterMatchOptionsStringArray: () => getDefaultFilterMatchOptionsStringArray
50
+ getDefaultFilterMatchOptionsStringArray: () => getDefaultFilterMatchOptionsStringArray,
51
+ getUrlParams: () => getUrlParams,
52
+ mapPrimeToBackendFilters: () => mapPrimeToBackendFilters
49
53
  });
50
54
  module.exports = __toCommonJS(index_exports);
51
55
 
@@ -234,22 +238,22 @@ function centsToReal(value) {
234
238
 
235
239
  // src/components/TooltipCustom.tsx
236
240
  var import_react_tooltip = require("react-tooltip");
241
+ var import_react_dom = require("react-dom");
237
242
  var import_jsx_runtime5 = require("react/jsx-runtime");
238
243
  function TooltipCustom({ label, id }) {
239
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
240
- import_react_tooltip.Tooltip,
241
- {
242
- className: "tooltip-icone",
243
- opacity: 1,
244
- place: "top",
245
- content: label,
246
- anchorSelect: `#${id}`,
247
- style: {
248
- zIndex: 9999
249
- },
250
- positionStrategy: "fixed",
251
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "tooltip-custom", children: label })
252
- }
244
+ return (0, import_react_dom.createPortal)(
245
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
246
+ import_react_tooltip.Tooltip,
247
+ {
248
+ anchorSelect: `#${id}`,
249
+ place: "top",
250
+ positionStrategy: "fixed",
251
+ className: "tooltip-icone",
252
+ style: { zIndex: 11 },
253
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "tooltip-custom", children: label })
254
+ }
255
+ ),
256
+ document.body
253
257
  );
254
258
  }
255
259
 
@@ -497,21 +501,6 @@ function DynamicColumns({
497
501
  return array;
498
502
  }
499
503
 
500
- // src/utils/DataTableUtils.tsx
501
- var import_api2 = require("primereact/api");
502
- var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
503
- const params = new URLSearchParams(
504
- typeof window !== "undefined" ? window.location.search : ""
505
- );
506
- return {
507
- page: Number(params.get("page") ?? 1),
508
- rows: Number(params.get("rows") ?? 10),
509
- sortField: params.get("sortField") || sortFieldInitial || "",
510
- sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
511
- filter: params.get("filter") ?? ""
512
- };
513
- };
514
-
515
504
  // src/hooks/use-debounce.ts
516
505
  var import_react5 = require("react");
517
506
  var useDebounce = (value, delay) => {
@@ -527,6 +516,288 @@ var useDebounce = (value, delay) => {
527
516
  return debouncedValue;
528
517
  };
529
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
+
530
801
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilterWrapper.tsx
531
802
  var import_jsx_runtime9 = require("react/jsx-runtime");
532
803
  function DataTableAdvancedFilterWrapper({
@@ -802,7 +1073,7 @@ function DataTableAdvancedFilterWrapper({
802
1073
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilter.tsx
803
1074
  var import_api3 = require("primereact/api");
804
1075
 
805
- // src/utils/locale.ts
1076
+ // src/components/DataTableAdvancedFilter/utils/locale.ts
806
1077
  var localePtBr = {
807
1078
  accept: "Sim",
808
1079
  addRule: "Adicionar Regra",
@@ -1334,10 +1605,14 @@ var import_api5 = require("primereact/api");
1334
1605
  ModalBase,
1335
1606
  SelectFilterTemplate,
1336
1607
  ValueFilterTemplate,
1608
+ buildDynamicCampoFilters,
1609
+ buildSortingWithFilters,
1337
1610
  customMatchModes,
1338
1611
  getDefaultFilterMatchOptionsDate,
1339
1612
  getDefaultFilterMatchOptionsEnum,
1340
1613
  getDefaultFilterMatchOptionsEnumNotNullable,
1341
1614
  getDefaultFilterMatchOptionsString,
1342
- getDefaultFilterMatchOptionsStringArray
1615
+ getDefaultFilterMatchOptionsStringArray,
1616
+ getUrlParams,
1617
+ mapPrimeToBackendFilters
1343
1618
  });
package/dist/index.mjs CHANGED
@@ -183,22 +183,22 @@ function centsToReal(value) {
183
183
 
184
184
  // src/components/TooltipCustom.tsx
185
185
  import { Tooltip } from "react-tooltip";
186
+ import { createPortal } from "react-dom";
186
187
  import { jsx as jsx5 } from "react/jsx-runtime";
187
188
  function TooltipCustom({ label, id }) {
188
- return /* @__PURE__ */ jsx5(
189
- Tooltip,
190
- {
191
- className: "tooltip-icone",
192
- opacity: 1,
193
- place: "top",
194
- content: label,
195
- anchorSelect: `#${id}`,
196
- style: {
197
- zIndex: 9999
198
- },
199
- positionStrategy: "fixed",
200
- children: /* @__PURE__ */ jsx5("div", { className: "tooltip-custom", children: label })
201
- }
189
+ return createPortal(
190
+ /* @__PURE__ */ jsx5(
191
+ Tooltip,
192
+ {
193
+ anchorSelect: `#${id}`,
194
+ place: "top",
195
+ positionStrategy: "fixed",
196
+ className: "tooltip-icone",
197
+ style: { zIndex: 11 },
198
+ children: /* @__PURE__ */ jsx5("div", { className: "tooltip-custom", children: label })
199
+ }
200
+ ),
201
+ document.body
202
202
  );
203
203
  }
204
204
 
@@ -446,21 +446,6 @@ function DynamicColumns({
446
446
  return array;
447
447
  }
448
448
 
449
- // src/utils/DataTableUtils.tsx
450
- import { FilterMatchMode as FilterMatchMode3, FilterOperator } from "primereact/api";
451
- var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
452
- const params = new URLSearchParams(
453
- typeof window !== "undefined" ? window.location.search : ""
454
- );
455
- return {
456
- page: Number(params.get("page") ?? 1),
457
- rows: Number(params.get("rows") ?? 10),
458
- sortField: params.get("sortField") || sortFieldInitial || "",
459
- sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
460
- filter: params.get("filter") ?? ""
461
- };
462
- };
463
-
464
449
  // src/hooks/use-debounce.ts
465
450
  import { useEffect as useEffect2, useState } from "react";
466
451
  var useDebounce = (value, delay) => {
@@ -476,6 +461,288 @@ var useDebounce = (value, delay) => {
476
461
  return debouncedValue;
477
462
  };
478
463
 
464
+ // src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
465
+ import { FilterMatchMode as FilterMatchMode3, FilterOperator } from "primereact/api";
466
+ var mapMatchMode = (mode) => {
467
+ switch (mode) {
468
+ case "startsWith":
469
+ return "StartsWith";
470
+ case "contains":
471
+ return "Contains";
472
+ case "equals":
473
+ return "Equals";
474
+ case "notEquals":
475
+ return "notEquals";
476
+ case "endsWith":
477
+ return "EndsWith";
478
+ case "lt":
479
+ case "dateBefore":
480
+ return "LessThan";
481
+ case "lte":
482
+ return "LessThanOrEqualTo";
483
+ case "gt":
484
+ case "dateAfter":
485
+ return "GreaterThan";
486
+ case "gte":
487
+ return "GreaterThanOrEqualTo";
488
+ case "notContains":
489
+ return "NotContains";
490
+ case "empty":
491
+ return "Empty";
492
+ default:
493
+ return "Equals";
494
+ }
495
+ };
496
+ var buildFilterPayload = (fieldName, matchMode, rawValue) => {
497
+ const normalized = normalizeFilterValue(rawValue);
498
+ if (matchMode === "empty") {
499
+ return {
500
+ field: fieldName,
501
+ operator: "Empty"
502
+ };
503
+ }
504
+ if (matchMode === "notEmpty") {
505
+ return {
506
+ not: {
507
+ field: fieldName,
508
+ operator: "Empty"
509
+ }
510
+ };
511
+ }
512
+ if (normalized === null) return null;
513
+ if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
514
+ matchMode === "dateIsNot" || matchMode === "notContains") {
515
+ let operator;
516
+ switch (matchMode) {
517
+ case "notStartsWith":
518
+ operator = "StartsWith";
519
+ break;
520
+ case "notEndsWith":
521
+ operator = "EndsWith";
522
+ break;
523
+ case "notContains":
524
+ operator = "Contains";
525
+ break;
526
+ case "notEquals":
527
+ case "dateIsNot":
528
+ default:
529
+ operator = "Equals";
530
+ }
531
+ return {
532
+ not: {
533
+ field: fieldName,
534
+ operator,
535
+ value: normalized
536
+ }
537
+ };
538
+ }
539
+ return {
540
+ field: fieldName,
541
+ operator: mapMatchMode(matchMode),
542
+ value: normalized
543
+ };
544
+ };
545
+ var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
546
+ const finalAnd = [];
547
+ const globalOr = [];
548
+ const camposMap = {};
549
+ Object.entries(filters).forEach(([field, config]) => {
550
+ if (!config) return;
551
+ const value = config?.value?.text ?? config?.value;
552
+ if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
553
+ const globalOrNodes = [];
554
+ globalFilterFields.forEach((globalField) => {
555
+ const fieldConfig = filters[globalField];
556
+ if (!fieldConfig) return;
557
+ const payload = buildFilterPayload(
558
+ fieldConfig.filterFieldCollection ?? globalField,
559
+ resolveMatchMode(config.matchMode, config.value),
560
+ config.value
561
+ );
562
+ if (!payload) return;
563
+ if (!fieldConfig.collection) {
564
+ globalOrNodes.push(payload);
565
+ return;
566
+ }
567
+ const rootCollections = [];
568
+ pushIntoCollectionTree(
569
+ rootCollections,
570
+ fieldConfig.collection,
571
+ payload.field ?? payload.not?.field,
572
+ payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
573
+ );
574
+ globalOrNodes.push(...rootCollections);
575
+ });
576
+ if (globalOrNodes.length) {
577
+ finalAnd.push({ or: globalOrNodes });
578
+ }
579
+ return;
580
+ }
581
+ const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
582
+ if (!constraints.length) return;
583
+ const colOperator = config.operator === "or" ? "or" : "and";
584
+ if (config.collection === "campos" && config.fieldId) {
585
+ if (!camposMap[config.fieldId]) {
586
+ camposMap[config.fieldId] = { operator: colOperator, values: [] };
587
+ }
588
+ constraints.forEach((c) => {
589
+ const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
590
+ const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
591
+ if (payload) camposMap[config.fieldId].values.push(payload);
592
+ });
593
+ return;
594
+ }
595
+ const columnPayloads = constraints.map(
596
+ (c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
597
+ ).filter(Boolean);
598
+ if (!columnPayloads.length) return;
599
+ if (config.collection) {
600
+ const rootCollections = [];
601
+ columnPayloads.forEach((payload) => {
602
+ pushIntoCollectionTree(
603
+ rootCollections,
604
+ config.collection,
605
+ payload.field ?? payload.not?.field,
606
+ payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
607
+ );
608
+ });
609
+ rootCollections.forEach((c) => finalAnd.push(c));
610
+ return;
611
+ }
612
+ finalAnd.push({ [colOperator]: columnPayloads });
613
+ });
614
+ Object.entries(camposMap).forEach(([fieldId, config]) => {
615
+ if (!config.values.length) return;
616
+ finalAnd.push({
617
+ collection: "campos",
618
+ any: {
619
+ and: [
620
+ { field: "tipocampo.id", operator: "Equals", value: fieldId },
621
+ { [config.operator]: config.values }
622
+ ]
623
+ }
624
+ });
625
+ });
626
+ return finalAnd.length ? { and: finalAnd } : void 0;
627
+ };
628
+ function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
629
+ const collections = collectionPath.split(".");
630
+ let current = root;
631
+ collections.forEach((collection) => {
632
+ let node = current.find(
633
+ (n) => n.collection === collection && n.any
634
+ );
635
+ if (!node) {
636
+ node = {
637
+ collection,
638
+ any: { or: [] }
639
+ };
640
+ current.push(node);
641
+ }
642
+ current = node.any.or;
643
+ });
644
+ current.push({
645
+ ...payloadBase,
646
+ field: fieldName
647
+ });
648
+ }
649
+ function getMatchModeByTipo(tipo) {
650
+ switch (tipo) {
651
+ case "NumeroInteiro":
652
+ case "NumeroDecimal":
653
+ return FilterMatchMode3.EQUALS;
654
+ default:
655
+ return FilterMatchMode3.CONTAINS;
656
+ }
657
+ }
658
+ function buildDynamicCampoFilters(campos) {
659
+ return campos?.reduce((acc, campo) => {
660
+ acc[`${campo.id}`] = {
661
+ operator: FilterOperator.AND,
662
+ constraints: [
663
+ {
664
+ value: null,
665
+ matchMode: getMatchModeByTipo(campo.tipoDado)
666
+ }
667
+ ],
668
+ collection: "campos",
669
+ filterFieldCollection: "valor",
670
+ fieldId: campo.id
671
+ // opcional (útil pro backend)
672
+ };
673
+ return acc;
674
+ }, {});
675
+ }
676
+ var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
677
+ const params = new URLSearchParams(
678
+ typeof window !== "undefined" ? window.location.search : ""
679
+ );
680
+ return {
681
+ page: Number(params.get("page") ?? 1),
682
+ rows: Number(params.get("rows") ?? 10),
683
+ sortField: params.get("sortField") || sortFieldInitial || "",
684
+ sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
685
+ filter: params.get("filter") ?? ""
686
+ };
687
+ };
688
+ function buildSortingWithFilters(filters, sortField, order) {
689
+ const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
690
+ let sorting = [
691
+ {
692
+ field: sortField,
693
+ direction
694
+ }
695
+ ];
696
+ if (!filters || !sortField) {
697
+ return sorting;
698
+ }
699
+ const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
700
+ if (sortFilter?.fieldId) {
701
+ sorting = [
702
+ {
703
+ collection: "campos",
704
+ filter: {
705
+ field: "tipocampo.id",
706
+ operator: "equals",
707
+ value: sortFilter.fieldId
708
+ },
709
+ first: {
710
+ field: "valor",
711
+ direction
712
+ }
713
+ }
714
+ ];
715
+ }
716
+ return sorting;
717
+ }
718
+ function normalizeFilterValue(raw) {
719
+ if (raw === null || raw === void 0) return null;
720
+ if (typeof raw === "boolean") {
721
+ return String(raw);
722
+ }
723
+ if (typeof raw === "number") {
724
+ return raw;
725
+ }
726
+ if (typeof raw === "string") {
727
+ return raw.trim() !== "" ? raw : null;
728
+ }
729
+ if (typeof raw === "object") {
730
+ if ("text" in raw && raw.text === null) {
731
+ return "__NULL__";
732
+ }
733
+ if (typeof raw.text === "string") {
734
+ return raw.text.trim() !== "" ? raw.text : null;
735
+ }
736
+ }
737
+ return null;
738
+ }
739
+ function resolveMatchMode(constraintMatchMode, rawValue) {
740
+ if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
741
+ return rawValue.matchMode;
742
+ }
743
+ return constraintMatchMode;
744
+ }
745
+
479
746
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilterWrapper.tsx
480
747
  import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
481
748
  function DataTableAdvancedFilterWrapper({
@@ -751,7 +1018,7 @@ function DataTableAdvancedFilterWrapper({
751
1018
  // src/components/DataTableAdvancedFilter/DataTableAdvancedFilter.tsx
752
1019
  import { addLocale, locale, PrimeReactProvider } from "primereact/api";
753
1020
 
754
- // src/utils/locale.ts
1021
+ // src/components/DataTableAdvancedFilter/utils/locale.ts
755
1022
  var localePtBr = {
756
1023
  accept: "Sim",
757
1024
  addRule: "Adicionar Regra",
@@ -1282,10 +1549,14 @@ export {
1282
1549
  ModalBase,
1283
1550
  SelectFilterTemplate,
1284
1551
  ValueFilterTemplate,
1552
+ buildDynamicCampoFilters,
1553
+ buildSortingWithFilters,
1285
1554
  customMatchModes,
1286
1555
  getDefaultFilterMatchOptionsDate,
1287
1556
  getDefaultFilterMatchOptionsEnum,
1288
1557
  getDefaultFilterMatchOptionsEnumNotNullable,
1289
1558
  getDefaultFilterMatchOptionsString,
1290
- getDefaultFilterMatchOptionsStringArray
1559
+ getDefaultFilterMatchOptionsStringArray,
1560
+ getUrlParams,
1561
+ mapPrimeToBackendFilters
1291
1562
  };
@@ -530,10 +530,6 @@ th {
530
530
  border-right: 1px solid #edf0f2 !important;
531
531
  }
532
532
 
533
- .react-tooltip {
534
- z-index: 99 !important;
535
- }
536
-
537
533
  .box-icones-actions-column:hover {
538
534
  opacity: 1;
539
535
  }
@@ -627,3 +623,11 @@ th {
627
623
  .p-datepicker-calendar th {
628
624
  padding: 0;
629
625
  }
626
+
627
+ .p-datatable-scrollable-table > .p-datatable-thead {
628
+ z-index: 11;
629
+ }
630
+
631
+ .react-tooltip {
632
+ z-index: 11 !important;
633
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charlesgomes/leafcode-shared-lib-react",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "Lib de componentes react",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",