@sankhyalabs/sankhyablocks 8.16.0-dev.39 → 8.16.0-dev.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/dist/cjs/index-f9e81701.js +8 -28
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  4. package/dist/cjs/{snk-form-config.cjs.entry.js → snk-config-options_3.cjs.entry.js} +363 -1
  5. package/dist/cjs/{snk-filter-bar.cjs.entry.js → snk-filter-bar_4.cjs.entry.js} +685 -0
  6. package/dist/cjs/snk-simple-crud.cjs.entry.js +3 -1
  7. package/dist/collection/collection-manifest.json +11 -31
  8. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +3 -1
  9. package/dist/collection/sw.js +46 -0
  10. package/dist/components/snk-simple-crud2.js +3 -1
  11. package/dist/esm/{SnkFormConfigManager-139f09fa.js → SnkFormConfigManager-f1a0fc92.js} +1 -1
  12. package/dist/esm/{constants-8457af36.js → constants-7302ee87.js} +1 -1
  13. package/dist/esm/index-a7d3d3f1.js +8 -28
  14. package/dist/esm/loader.js +1 -1
  15. package/dist/esm/sankhyablocks.js +1 -1
  16. package/dist/esm/snk-actions-button_4.entry.js +1 -1
  17. package/dist/esm/snk-attach.entry.js +1 -1
  18. package/dist/esm/{snk-form-config.entry.js → snk-config-options_3.entry.js} +364 -4
  19. package/dist/esm/snk-configurator.entry.js +1 -1
  20. package/dist/esm/snk-crud.entry.js +1 -1
  21. package/dist/esm/snk-data-exporter.entry.js +1 -1
  22. package/dist/esm/snk-detail-view.entry.js +3 -3
  23. package/dist/esm/snk-field-config.entry.js +1 -1
  24. package/dist/esm/{snk-filter-bar.entry.js → snk-filter-bar_4.entry.js} +684 -2
  25. package/dist/esm/{snk-guides-viewer-c1ef991c.js → snk-guides-viewer-2f4dcdc5.js} +2 -2
  26. package/dist/esm/snk-guides-viewer.entry.js +3 -3
  27. package/dist/esm/snk-simple-crud.entry.js +5 -3
  28. package/dist/esm/snk-tab-config.entry.js +1 -1
  29. package/dist/sankhyablocks/p-052213ba.entry.js +1 -0
  30. package/dist/sankhyablocks/{p-11a0a7ac.entry.js → p-0b6cd238.entry.js} +1 -1
  31. package/dist/sankhyablocks/p-0e320bd2.entry.js +1 -0
  32. package/dist/sankhyablocks/{p-281bc322.entry.js → p-275de842.entry.js} +1 -1
  33. package/dist/sankhyablocks/{p-8eb67fa4.entry.js → p-2d3f9482.entry.js} +1 -1
  34. package/dist/sankhyablocks/{p-7663f597.entry.js → p-41793e17.entry.js} +1 -1
  35. package/dist/sankhyablocks/{p-1b6d51bf.entry.js → p-5e51e833.entry.js} +1 -1
  36. package/dist/sankhyablocks/{p-d3341910.entry.js → p-72c10005.entry.js} +1 -1
  37. package/dist/sankhyablocks/{p-11cc69fc.js → p-7bd9683d.js} +1 -1
  38. package/dist/sankhyablocks/{p-95df461f.entry.js → p-8b4fc28f.entry.js} +1 -1
  39. package/dist/sankhyablocks/{p-b0ef4383.js → p-95ce311a.js} +1 -1
  40. package/dist/sankhyablocks/{p-5ea74956.entry.js → p-ab1645fb.entry.js} +1 -1
  41. package/dist/sankhyablocks/{p-47f79aa0.entry.js → p-cefb0ee1.entry.js} +1 -1
  42. package/dist/sankhyablocks/p-fa6c5826.entry.js +1 -0
  43. package/dist/sankhyablocks/{p-afbb070d.js → p-fadc8339.js} +1 -1
  44. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  45. package/package.json +3 -2
  46. package/dist/cjs/snk-config-options.cjs.entry.js +0 -239
  47. package/dist/cjs/snk-filter-item.cjs.entry.js +0 -312
  48. package/dist/cjs/snk-filter-list.cjs.entry.js +0 -152
  49. package/dist/cjs/snk-filter-modal.cjs.entry.js +0 -249
  50. package/dist/cjs/snk-form.cjs.entry.js +0 -144
  51. package/dist/esm/snk-config-options.entry.js +0 -235
  52. package/dist/esm/snk-filter-item.entry.js +0 -308
  53. package/dist/esm/snk-filter-list.entry.js +0 -148
  54. package/dist/esm/snk-filter-modal.entry.js +0 -245
  55. package/dist/esm/snk-form.entry.js +0 -140
  56. package/dist/sankhyablocks/p-06898e5a.entry.js +0 -1
  57. package/dist/sankhyablocks/p-3b60db06.entry.js +0 -1
  58. package/dist/sankhyablocks/p-60b29483.entry.js +0 -1
  59. package/dist/sankhyablocks/p-70a4af56.entry.js +0 -1
  60. package/dist/sankhyablocks/p-b9679243.entry.js +0 -1
  61. package/dist/sankhyablocks/p-d3f53df2.entry.js +0 -1
  62. package/dist/sankhyablocks/p-e8763234.entry.js +0 -1
  63. package/dist/sankhyablocks/p-feba9d4b.entry.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-a7d3d3f1.js';
2
- import { DataType, StringUtils, ObjectUtils, ElementIDUtils, ErrorException, ApplicationContext } from '@sankhyalabs/core';
2
+ import { DataType, StringUtils, ObjectUtils, ElementIDUtils, ErrorException, ApplicationContext, FloatingManager, DateUtils, ArrayUtils } from '@sankhyalabs/core';
3
3
  import { EzScrollDirection } from '@sankhyalabs/ezui/dist/collection/components/ez-scroller/EzScrollDirection';
4
4
  import { C as ConfigStorage } from './ConfigStorage-7b36d041.js';
5
5
  import { toString } from '@sankhyalabs/core/dist/dataunit/metadata/DataType';
@@ -8,6 +8,8 @@ import { F as FilterOperand } from './index-ae591a44.js';
8
8
  import { F as FilterNumberVariation } from './filterNumberVariation-8cee02ea.js';
9
9
  import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
10
10
  import { P as PersonalizedFilterUtils } from './PersonalizedFilterUtils-e2b38ef7.js';
11
+ import { ModalAction } from '@sankhyalabs/ezui/dist/collection/components/ez-modal-container';
12
+ import { F as FilterType } from './filter-type.enum-a80c1b6b.js';
11
13
  import './form-config-fetcher-adbe5d34.js';
12
14
  import './DataFetcher-a9c598f2.js';
13
15
  import './PrintUtils-3e4ff0f5.js';
@@ -719,4 +721,684 @@ const SnkFilterBar = class {
719
721
  };
720
722
  SnkFilterBar.style = snkFilterBarCss;
721
723
 
722
- export { SnkFilterBar as snk_filter_bar };
724
+ const SnkFilterItem = class {
725
+ constructor(hostRef) {
726
+ registerInstance(this, hostRef);
727
+ this.visibleChanged = createEvent(this, "visibleChanged", 7);
728
+ this.filterChange = createEvent(this, "filterChange", 3);
729
+ this.innerClickCheck = (_floatingContainer, node) => {
730
+ if (node.id != FloatingManager.MODAL_ELEMENT_ID) {
731
+ return true;
732
+ }
733
+ this.detailIsVisible = false;
734
+ return false;
735
+ };
736
+ this.detailIsVisible = undefined;
737
+ this.config = undefined;
738
+ this.getMessage = undefined;
739
+ this.showChips = true;
740
+ }
741
+ observeDetailIsVisible(value) {
742
+ this.visibleChanged.emit(value);
743
+ }
744
+ /**
745
+ * Exibe os detalhes de um item da lista.
746
+ */
747
+ async showUp(open = false) {
748
+ return new Promise(resolve => {
749
+ this._filterItemElement.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" });
750
+ if (open) {
751
+ this._closeCallback = resolve;
752
+ window.requestAnimationFrame(() => {
753
+ this._floatingID = FloatingManager.float(this._popover, this._popoverContainer, this.getFloatOptions());
754
+ this._popover.show();
755
+ this.detailIsVisible = true;
756
+ });
757
+ }
758
+ });
759
+ }
760
+ updatePosition() {
761
+ if (this._floatingID == undefined) {
762
+ return;
763
+ }
764
+ FloatingManager.updateFloatPosition(this._popover, this._popoverContainer, this.getFloatOptions());
765
+ }
766
+ getFloatOptions() {
767
+ return {
768
+ autoClose: true,
769
+ innerClickTest: this.innerClickCheck,
770
+ backClickListener: () => this.onDetailCloseCallback(),
771
+ left: this.getOffsetLeft(),
772
+ top: this.getOffsetTop(),
773
+ useOverlay: true,
774
+ overlayClassName: 'ez-scrim ez-scrim--light',
775
+ isFixed: true
776
+ };
777
+ }
778
+ getOffsetLeft() {
779
+ const padding = getComputedStyle(this._filterItemElement).getPropertyValue("padding-left");
780
+ const rect = this._filterItemElement.getBoundingClientRect();
781
+ // Width baseado no conteudo do snk-filter-detail. Nesse momento ele retorna 0px pois ainda não foi criado em tela.
782
+ const filterDetailWidth = 430;
783
+ const adjustRightPosition = filterDetailWidth - (document.body.clientWidth - rect.left);
784
+ return `calc(${rect.x}px + ${padding} - ${adjustRightPosition > 0 ? adjustRightPosition : 0}px)`;
785
+ }
786
+ getOffsetTop() {
787
+ const rect = this._filterItemElement.getBoundingClientRect();
788
+ return (rect.y + rect.height) + "px";
789
+ }
790
+ controlScrollPage() {
791
+ window.removeEventListener("scroll", this.updatePosition.bind(this));
792
+ window.addEventListener("scroll", this.updatePosition.bind(this));
793
+ }
794
+ getConfigChanges() {
795
+ var _a;
796
+ const configToBeCleared = this.config;
797
+ if (!!((_a = configToBeCleared.groupedItems) === null || _a === void 0 ? void 0 : _a.length)) {
798
+ configToBeCleared.visible = false;
799
+ configToBeCleared.groupedItems = configToBeCleared.groupedItems.map(item => (Object.assign(Object.assign({}, item), { visible: false })));
800
+ }
801
+ const hasMultiValues = configToBeCleared.type === FilterItemType.MULTI_LIST && Array.isArray(configToBeCleared.value);
802
+ const newValue = hasMultiValues ? configToBeCleared.value.map((valueItem) => (Object.assign(Object.assign({}, valueItem), { check: false }))) : undefined;
803
+ return Object.assign(Object.assign({}, configToBeCleared), { value: newValue });
804
+ }
805
+ /**
806
+ * Oculta os detalhes de um item da lista.
807
+ */
808
+ async hideDetail() {
809
+ if (this.detailIsVisible) {
810
+ if (this._floatingID != undefined) {
811
+ FloatingManager.close(this._floatingID);
812
+ }
813
+ }
814
+ }
815
+ onDetailCloseCallback() {
816
+ this._floatingID = undefined;
817
+ this.detailIsVisible = false;
818
+ if (this._closeCallback) {
819
+ this._closeCallback();
820
+ this._closeCallback = undefined;
821
+ }
822
+ }
823
+ //---------------------------------------------
824
+ // Event handlers
825
+ //---------------------------------------------
826
+ clickListener(evt) {
827
+ if ([this._chipElement, this._leftIconElement, this._rightIconElement].includes(evt.target)) {
828
+ if (evt.target === this._rightIconElement && this.canClearFilter()) {
829
+ const configChanged = this.getConfigChanges();
830
+ this.filterChange.emit(configChanged);
831
+ }
832
+ else {
833
+ if (this.detailIsVisible) {
834
+ this.hideDetail();
835
+ }
836
+ else {
837
+ this.showUp(true);
838
+ }
839
+ }
840
+ evt.preventDefault();
841
+ evt.stopImmediatePropagation();
842
+ evt.stopPropagation();
843
+ }
844
+ }
845
+ mouseDownListener(evt) {
846
+ if (this.detailIsVisible && [this._chipElement, this._leftIconElement, this._rightIconElement].includes(evt.target)) {
847
+ evt.preventDefault();
848
+ evt.stopImmediatePropagation();
849
+ evt.stopPropagation();
850
+ }
851
+ }
852
+ getLabel(isTooltipLabel = false) {
853
+ var _a, _b;
854
+ const { type, value, label, props, groupedItems = [] } = this.config;
855
+ if (value || groupedItems.length) {
856
+ if (type === FilterItemType.BINARY_SELECT) {
857
+ const [optOne, optTwo] = props.options;
858
+ const tooltip = this.getMessage('snkFilterBar.binarySelectTooltip');
859
+ if (optOne.name === value) {
860
+ return isTooltipLabel ? `${tooltip} ${String(optOne.label).toLowerCase()}` : optOne.label;
861
+ }
862
+ if (optTwo.name === value) {
863
+ return isTooltipLabel ? `${tooltip} ${String(optTwo.label).toLowerCase()}` : optTwo.label;
864
+ }
865
+ }
866
+ if (type === FilterItemType.MULTI_SELECT) {
867
+ const opt = props.options.find(opt => opt.value === value);
868
+ return `${label}: ${opt.label}`;
869
+ }
870
+ if (type === FilterItemType.PERIOD) {
871
+ let { end, start } = value;
872
+ if (typeof end === "string") {
873
+ end = new Date(end);
874
+ end.setMinutes(end.getMinutes() + end.getTimezoneOffset());
875
+ }
876
+ if (typeof start === "string") {
877
+ start = new Date(start);
878
+ start.setMinutes(start.getMinutes() + start.getTimezoneOffset());
879
+ }
880
+ const dateFormater = new Intl.DateTimeFormat("pt-BR");
881
+ if (end && start) {
882
+ const isSameYear = start.getFullYear() === end.getFullYear();
883
+ const formatOptions = Object.assign({ day: '2-digit', month: '2-digit' }, ((!isSameYear || isTooltipLabel) && { year: '2-digit' }));
884
+ const startLabel = DateUtils.formatDate(start, formatOptions);
885
+ const endLabel = DateUtils.formatDate(end, formatOptions);
886
+ if (isTooltipLabel) {
887
+ return this.getMessage('snkFilterBar.fullPeriodTooltip', { LABEL: label, START_LABEL: startLabel, END_LABEL: endLabel });
888
+ }
889
+ return `${label}: ${startLabel} \u2192 ${endLabel}`;
890
+ }
891
+ else {
892
+ if (start) {
893
+ return `${label}: ${this.getMessage('snkFilterBar.onlyStartToltip')} ${dateFormater.format(start)}`;
894
+ }
895
+ else if (end) {
896
+ return `${label}: ${this.getMessage('snkFilterBar.onlyEndToltip')} ${dateFormater.format(end)}`;
897
+ }
898
+ else {
899
+ return label;
900
+ }
901
+ }
902
+ }
903
+ if (type === FilterItemType.SEARCH) {
904
+ return `${label}: ${value.value} - ${value.label}`;
905
+ }
906
+ if (type === FilterItemType.PERSONALIZED) {
907
+ const activeCount = this.calculateActiveCount(groupedItems);
908
+ if (activeCount <= 0)
909
+ return label;
910
+ return `${label}: ${this.getMessage('snkFilterBar.personalizedCount', { activeCount })}`;
911
+ }
912
+ if (type === FilterItemType.MULTI_LIST) {
913
+ const selectedOptions = ((_a = value.elements) !== null && _a !== void 0 ? _a : value).filter(item => item === null || item === void 0 ? void 0 : item.check);
914
+ return this.getLabelFromCheckedOptions(selectedOptions, label, isTooltipLabel);
915
+ }
916
+ if (type === FilterItemType.CHECK_BOX_LIST) {
917
+ const selectedValues = Object.entries(value !== null && value !== void 0 ? value : {})
918
+ .filter(([_, value]) => value === true)
919
+ .map(([key, _]) => key);
920
+ const options = (_b = props.options) !== null && _b !== void 0 ? _b : [];
921
+ const selectedOptions = options.filter(option => selectedValues.includes(option.name));
922
+ return this.getLabelFromCheckedOptions(selectedOptions, label, isTooltipLabel);
923
+ }
924
+ if (type === FilterItemType.NUMBER && props.variation === FilterNumberVariation.INTERVAL) {
925
+ const { start, end } = value;
926
+ if (start && end) {
927
+ return this.getMessage('snkFilterBar.fullIntervalTooltip', { LABEL: label, START_LABEL: start, END_LABEL: end });
928
+ }
929
+ if (start) {
930
+ return `${label}: ${this.getMessage('snkFilterBar.onlyStartToltip')} ${Number(start)}`;
931
+ }
932
+ if (end) {
933
+ return `${label}: ${this.getMessage('snkFilterBar.onlyEndToltip')} ${Number(end)}`;
934
+ }
935
+ }
936
+ return `${label}: ${value}`;
937
+ }
938
+ return label;
939
+ }
940
+ getLabelFromCheckedOptions(selectedOptions, label, isTooltipLabel) {
941
+ const checkedAmount = selectedOptions.length;
942
+ if (checkedAmount === 0) {
943
+ return `${label}`;
944
+ }
945
+ if (checkedAmount > 1) {
946
+ if (isTooltipLabel) {
947
+ const selectedOptionsDescrptions = selectedOptions.map(item => item.label);
948
+ return `${label}: ${selectedOptionsDescrptions.join(',')}`;
949
+ }
950
+ return `${label}: ${checkedAmount} ${this.getMessage('snkFilterBar.multiListToltip')}`;
951
+ }
952
+ return `${label}: ${selectedOptions[0].label}`;
953
+ }
954
+ calculateActiveCount(groupedItems) {
955
+ return groupedItems.reduce((total, item) => {
956
+ if (!!item.visible)
957
+ return total + 1;
958
+ return total;
959
+ }, 0);
960
+ }
961
+ componentDidLoad() {
962
+ if (this._filterItemElement) {
963
+ ElementIDUtils.addIDInfo(this._filterItemElement);
964
+ this._idSnkFilterDetail = `filterDetail_${this.config.id}`;
965
+ }
966
+ this.controlScrollPage();
967
+ }
968
+ componentDidRender() {
969
+ if (this._floatingID == undefined) {
970
+ if (this._popover) {
971
+ this._popover.remove();
972
+ }
973
+ }
974
+ }
975
+ /**
976
+ * Emitido quando o estado do filtro é alterado.
977
+ */
978
+ filterChangeListener() {
979
+ this.hideDetail();
980
+ }
981
+ canClearFilter() {
982
+ const { value, groupedItems = [] } = this.config;
983
+ if (value != undefined && this.config.type === FilterItemType.MULTI_LIST) {
984
+ return value.some((item) => item.check);
985
+ }
986
+ return value !== undefined || groupedItems.some(item => item.visible);
987
+ }
988
+ getRightIconName() {
989
+ if (this.canClearFilter())
990
+ return "close";
991
+ return this.detailIsVisible ? "chevron-up" : "chevron-down";
992
+ }
993
+ getLeftIconName() {
994
+ switch (this.config.type) {
995
+ case FilterItemType.PERIOD:
996
+ return "calendar";
997
+ case FilterItemType.PERSONALIZED:
998
+ return "tune";
999
+ }
1000
+ return undefined;
1001
+ }
1002
+ hasActiveElements(value) {
1003
+ var _a, _b, _c;
1004
+ return ((_c = (_b = ((_a = value === null || value === void 0 ? void 0 : value.elements) !== null && _a !== void 0 ? _a : value)) === null || _b === void 0 ? void 0 : _b.filter(val => val === null || val === void 0 ? void 0 : val.check)) === null || _c === void 0 ? void 0 : _c.length) > 0;
1005
+ }
1006
+ hasActiveValue(config) {
1007
+ return (config.type !== FilterItemType.MULTI_LIST && config.value !== undefined) || this.hasActiveElements(config.value);
1008
+ }
1009
+ getEnabledChip() {
1010
+ if (this.config.type === FilterItemType.PERSONALIZED) {
1011
+ const { groupedItems = [] } = this.config;
1012
+ return groupedItems.some(item => item.visible);
1013
+ }
1014
+ return this.hasActiveValue(this.config);
1015
+ }
1016
+ render() {
1017
+ const leftIcon = this.getLeftIconName();
1018
+ return (h(Host, null, this.showChips && (h("ez-chip", { id: this.config.id, ref: ref => this._chipElement = ref, label: this.getLabel(), value: this.getEnabledChip() }, leftIcon && (h("ez-icon", { ref: ref => this._leftIconElement = ref, iconName: leftIcon, class: "ez-padding-right--small", slot: "leftIcon" })), h("ez-icon", { ref: ref => this._rightIconElement = ref, iconName: this.getRightIconName(), class: "ez-padding-left--small", slot: "rightIcon", id: "removeFilter" }))), h("section", { class: "ez-margin-top--small sc-snk-filter-bar snk-filter__popover-container", ref: elem => this._popoverContainer = elem }, h("snk-filter-detail", { config: this.config, getMessage: this.getMessage, class: "sc-snk-filter-bar snk-filter__popover ez-padding--small ez-elevation--16", ref: elem => this._popover = elem, key: this.config.id, "data-element-id": this._idSnkFilterDetail, showHardFixed: this.showChips }))));
1019
+ }
1020
+ get _filterItemElement() { return getElement(this); }
1021
+ static get watchers() { return {
1022
+ "detailIsVisible": ["observeDetailIsVisible"]
1023
+ }; }
1024
+ };
1025
+
1026
+ const SHOW_MORE_ITEM_NAME = "__SHOWMORE__";
1027
+ const MAX_FILTERS = 5;
1028
+ const SnkFilterList = class {
1029
+ constructor(hostRef) {
1030
+ registerInstance(this, hostRef);
1031
+ this.snkItemSelected = createEvent(this, "snkItemSelected", 7);
1032
+ this._preselection = -1;
1033
+ this.innerClickCheck = (_floatingContainer, node) => {
1034
+ if (node.id != FloatingManager.MODAL_ELEMENT_ID) {
1035
+ return true;
1036
+ }
1037
+ this._detailIsVisible = false;
1038
+ return false;
1039
+ };
1040
+ this._filterArgument = undefined;
1041
+ this._showAll = undefined;
1042
+ this.label = undefined;
1043
+ this.iconName = undefined;
1044
+ this.items = undefined;
1045
+ this.getMessage = undefined;
1046
+ this.emptyText = undefined;
1047
+ this.findFilterText = undefined;
1048
+ this.buttonClass = undefined;
1049
+ }
1050
+ showDetail() {
1051
+ this._preselection = -1;
1052
+ this._floatingID = FloatingManager.float(this._popover, this._popoverContainer, {
1053
+ autoClose: true,
1054
+ innerClickTest: this.innerClickCheck,
1055
+ backClickListener: () => this.onListCloseCallback(),
1056
+ useOverlay: true
1057
+ });
1058
+ this._detailIsVisible = true;
1059
+ this._showAll = false;
1060
+ this._filterArgument = "";
1061
+ this._filterInput.setFocus();
1062
+ }
1063
+ /**
1064
+ * Oculta os detalhes do componente snk-filter-list.
1065
+ */
1066
+ async hideDetail() {
1067
+ if (this._floatingID != undefined) {
1068
+ FloatingManager.close(this._floatingID);
1069
+ }
1070
+ }
1071
+ onListCloseCallback() {
1072
+ this._floatingID = undefined;
1073
+ this._detailIsVisible = false;
1074
+ }
1075
+ buttonClick() {
1076
+ if (this._detailIsVisible) {
1077
+ this.hideDetail();
1078
+ }
1079
+ else {
1080
+ this.showDetail();
1081
+ }
1082
+ }
1083
+ componentDidLoad() {
1084
+ if (this._element) {
1085
+ ElementIDUtils.addIDInfo(this._element);
1086
+ }
1087
+ }
1088
+ componentDidRender() {
1089
+ if (this._floatingID == undefined) {
1090
+ if (this._popover) {
1091
+ this._popover.remove();
1092
+ }
1093
+ }
1094
+ }
1095
+ buildIdElement(buttonElement, name) {
1096
+ if (!buttonElement)
1097
+ return;
1098
+ const dataElement = { id: name };
1099
+ buttonElement.removeAttribute(ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME);
1100
+ ElementIDUtils.addIDInfoIfNotExists(buttonElement, "filterItemList", dataElement);
1101
+ }
1102
+ buildItemElement(item) {
1103
+ const itemId = ++this._selectableItemsCount;
1104
+ return (h("button", { ref: elem => elem && this.buildIdElement(elem, item.label), id: `filter-item${itemId}`, onFocusin: () => this._preselection = itemId, class: `ez-col ez-col--sd-12 ez-align--middle ez-padding--small sc-snk-filter-bar snk-filter-bar__filter-list-item`, onClick: () => this.itemSelected(item.name), name: item.label, key: itemId }, item.iconName ? h("ez-icon", { iconName: item.iconName, size: "small", class: `ez-padding-right--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-item__icon ${item.iconClass || ""}` }) : undefined, h("div", { class: `ez-text ez-text--medium ez-text--primary ez-padding--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-item__label ${item.labelClass || ""}` }, item.label)));
1105
+ }
1106
+ itemSelected(itemName) {
1107
+ if (itemName === SHOW_MORE_ITEM_NAME) {
1108
+ this._showAll = true;
1109
+ }
1110
+ else {
1111
+ this.hideDetail();
1112
+ this.snkItemSelected.emit(itemName);
1113
+ }
1114
+ }
1115
+ getFilterItems() {
1116
+ const items = this.items ? ArrayUtils.applyStringFilter(this._filterArgument, this.items.filter(item => item.kind === "FILTER")) : [];
1117
+ if (items.length === 0) {
1118
+ return h("div", { class: "ez-text ez-text--medium ez-text--primary ez-padding--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-items-container--empty" }, this.emptyText);
1119
+ }
1120
+ const hideItems = !this._filterArgument && !this._showAll && (items.length > MAX_FILTERS + 1);
1121
+ if (hideItems) {
1122
+ items.splice(MAX_FILTERS);
1123
+ items.push({ kind: "INTERNAL", label: "Mostrar mais", iconName: "dots-horizontal", name: SHOW_MORE_ITEM_NAME, iconClass: "snk-filter-bar__filter-list-item__icon--secondary", labelClass: "snk-filter-bar__filter-list-item__label--secondary" });
1124
+ }
1125
+ this._selectableItemsCount = 0;
1126
+ return h("div", { class: "sc-snk-filter-bar snk-filter-bar__filter-list-items-container" }, items.map(item => this.buildItemElement(item)));
1127
+ }
1128
+ getFooterItems() {
1129
+ return this.items.filter(item => item.kind === "FOOTER");
1130
+ }
1131
+ keyDownHandler(event) {
1132
+ switch (event.key) {
1133
+ case "ArrowDown":
1134
+ this.changePreselection(this._preselection + 1);
1135
+ //Paramos a propagação do evento para evitar scroll indesejado
1136
+ event.stopImmediatePropagation();
1137
+ event.stopPropagation();
1138
+ event.preventDefault();
1139
+ break;
1140
+ case "ArrowUp":
1141
+ this.changePreselection(this._preselection - 1);
1142
+ //Paramos a propagação do evento para evitar scroll indesejado
1143
+ event.stopImmediatePropagation();
1144
+ event.stopPropagation();
1145
+ event.preventDefault();
1146
+ break;
1147
+ }
1148
+ }
1149
+ changePreselection(newSelection) {
1150
+ if (newSelection < 0) {
1151
+ newSelection = this._selectableItemsCount;
1152
+ }
1153
+ this._preselection = newSelection > this._selectableItemsCount ? 0 : newSelection;
1154
+ if (this._preselection === 0) {
1155
+ this._filterInput.setFocus();
1156
+ }
1157
+ else {
1158
+ const item = this._element.querySelector(`#filter-item${this._preselection}`);
1159
+ if (item) {
1160
+ item.focus();
1161
+ }
1162
+ }
1163
+ }
1164
+ render() {
1165
+ return (h(Host, { class: "ez-flex ez-flex--column" }, h("ez-button", { class: this.buttonClass, label: this.label, onClick: () => this.buttonClick(), mode: this.iconName ? "icon" : undefined, iconName: this.iconName, size: "small" }, h("slot", { name: "leftIcon" })), h("section", { class: "ez-margin-top--small sc-snk-filter-bar snk-filter__popover-container", ref: elem => this._popoverContainer = elem }, h("div", { class: "sc-snk-filter-bar snk-filter__popover ez-padding--small ez-elevation--4", ref: elem => this._popover = elem }, h("ez-filter-input", { ref: ref => this._filterInput = ref, "data-element-id": "serachFilters", mode: "slim", label: this.findFilterText, value: this._filterArgument, onEzChange: (evt) => this._filterArgument = evt.detail, onFocus: () => this._preselection = 0 }), this.getFilterItems(), h("hr", { class: "sc-snk-filter-bar snk-filter__popover-rule" }), this.items ? this.getFooterItems().map(item => this.buildItemElement(item)) : undefined))));
1166
+ }
1167
+ get _element() { return getElement(this); }
1168
+ };
1169
+
1170
+ const snkFilterModalCss = "ez-modal{--ez-modal-content-padding:24px 12px}.snk-filter-modal__container{width:344px;max-width:344px;min-width:344px;overflow:hidden}.snk-filter-modal__content{display:flex;flex-direction:column;gap:var(--space--medium, 12px);padding-right:var(--space--3xs, 4px)}.snk-filter-modal__collapsible-box{border:var(--border--small, 1px solid) var(--color--strokes, #DCE0E8);border-radius:var(--border--radius-medium);padding:var(--space--medium, 12px) var(--space--small, 6px)}.snk-filter-modal__rendered-items{max-height:760px;overflow-x:clip;overflow-y:auto}.snk-filter-modal__rendered-items::-webkit-scrollbar{width:var(--space--small);min-width:var(--space--small);max-width:var(--space--small)}";
1171
+
1172
+ const SnkFilterModal = class {
1173
+ constructor(hostRef) {
1174
+ registerInstance(this, hostRef);
1175
+ this.getMessage = undefined;
1176
+ this.configName = undefined;
1177
+ this.filters = undefined;
1178
+ this.applyFilters = undefined;
1179
+ this.closeModal = undefined;
1180
+ this.addPersonalizedFilter = undefined;
1181
+ this.editPersonalizedFilter = undefined;
1182
+ this.deletePersonalizedFilter = undefined;
1183
+ this.filtersToDelete = [];
1184
+ this.disablePersonalizedFilter = undefined;
1185
+ }
1186
+ /**
1187
+ * Emitido quando um filtro personalizado é deletado.
1188
+ */
1189
+ deletePersonalizedFilterListener(event) {
1190
+ this.filtersToDelete.push(event.detail);
1191
+ }
1192
+ getCustomMessage(key, params) {
1193
+ var _a;
1194
+ return (_a = this.getMessage) === null || _a === void 0 ? void 0 : _a.call(this, `snkFilterBar.filterModal.${key}`, params);
1195
+ }
1196
+ //TODO: tratar clear all dos filtros personalizados
1197
+ handleClearAll() {
1198
+ const { customFilters, quickFilters, otherFilters, multiListFilters } = this.filters.reduce((acc, filter) => {
1199
+ if (filter.type === FilterItemType.MULTI_LIST) {
1200
+ acc.multiListFilters.push(filter);
1201
+ return acc;
1202
+ }
1203
+ if (filter.filterType === FilterType.QUICK_FILTER) {
1204
+ acc.quickFilters.push(filter);
1205
+ return acc;
1206
+ }
1207
+ if (filter.filterType === FilterType.CUSTOM_FILTER) {
1208
+ acc.customFilters.push(filter);
1209
+ return acc;
1210
+ }
1211
+ if (filter.filterType === FilterType.OTHER_FILTERS) {
1212
+ acc.otherFilters.push(filter);
1213
+ return acc;
1214
+ }
1215
+ return acc;
1216
+ }, { quickFilters: [], customFilters: [], otherFilters: [], multiListFilters: [] });
1217
+ this.handleClearFilterList(quickFilters);
1218
+ this.handleClearCustomFilters(customFilters);
1219
+ this.handleClearOthersFilters(otherFilters);
1220
+ multiListFilters.forEach(multiListFilter => this.handleClearSigleFilter(multiListFilter));
1221
+ }
1222
+ handleClearOthersFilters(otherFilters) {
1223
+ this.filters = this.filters.map(filter => otherFilters.includes(filter) ? (Object.assign(Object.assign({}, filter), { value: undefined })) : filter);
1224
+ }
1225
+ handleClearCustomFilters(customFilters) {
1226
+ this.filters.forEach((filter, index) => {
1227
+ if (filter.filterType === FilterType.CUSTOM_FILTER)
1228
+ this.filters[index] = this.clearAllCustomFilter(customFilters).shift();
1229
+ });
1230
+ }
1231
+ clearAllCustomFilter(filterConfigSnapshot) {
1232
+ return filterConfigSnapshot.map(filterItem => {
1233
+ const copy = Object.assign({}, filterItem);
1234
+ delete copy.value;
1235
+ copy.visible = false;
1236
+ if (copy.groupedItems) {
1237
+ copy.groupedItems = this.clearAllCustomFilter(copy.groupedItems);
1238
+ }
1239
+ return copy;
1240
+ });
1241
+ }
1242
+ handleClose() {
1243
+ const hasChangesToSave = ObjectUtils.objectToString(this.filters) !== ObjectUtils.objectToString(this._originalFilterConfig);
1244
+ if (!hasChangesToSave) {
1245
+ this.closeModal();
1246
+ return;
1247
+ }
1248
+ return ApplicationUtils.confirm(this.getCustomMessage('validations.notSaved.title'), this.getCustomMessage('validations.notSaved.message')).then((cancelAction) => {
1249
+ if (cancelAction)
1250
+ this.closeModal();
1251
+ });
1252
+ }
1253
+ handleApplyFilters() {
1254
+ const filterPersonalized = this.filters.find(filter => filter.filterType === FilterType.CUSTOM_FILTER);
1255
+ if (this.isValidCustomFilter(filterPersonalized)) {
1256
+ this.applyFilters(this.filters);
1257
+ }
1258
+ if (this.filtersToDelete.length > 0) {
1259
+ this.filtersToDelete.forEach(filter => {
1260
+ this.deletePersonalizedFilter(filter, this.configName);
1261
+ });
1262
+ this.filtersToDelete = [];
1263
+ }
1264
+ }
1265
+ isValidCustomFilter(filterPersonalized) {
1266
+ const isValid = PersonalizedFilterUtils.validateVariableValues(filterPersonalized);
1267
+ if (!isValid) {
1268
+ ApplicationUtils.alert(this.getCustomMessage('validations.notFullFilled.title'), this.getCustomMessage('validations.notFullFilled.message'));
1269
+ return false;
1270
+ }
1271
+ return true;
1272
+ }
1273
+ modalActionListener(evt) {
1274
+ const modalAction = evt.detail;
1275
+ switch (modalAction) {
1276
+ case ModalAction.CANCEL:
1277
+ this.handleClearAll();
1278
+ break;
1279
+ case ModalAction.OK:
1280
+ this.handleApplyFilters();
1281
+ break;
1282
+ case ModalAction.CLOSE:
1283
+ this.handleClose();
1284
+ break;
1285
+ }
1286
+ }
1287
+ handleFilterChange(filterConfig) {
1288
+ this.filters = this.filters.map(filter => filter.id === filterConfig.id ? filterConfig : filter);
1289
+ }
1290
+ handleClearFilterList(filterList) {
1291
+ this.filters = this.filters.map(filter => filterList.includes(filter) ? (Object.assign(Object.assign({}, filter), { value: undefined })) : filter);
1292
+ }
1293
+ handleClearSigleFilter(filterItem) {
1294
+ if (FilterItemType.MULTI_LIST === filterItem.type) {
1295
+ let filterItemCopy = ObjectUtils.copy(filterItem);
1296
+ this.uncheckFilterValues(filterItemCopy.value);
1297
+ const filterListCopy = ObjectUtils.copy(this.filters);
1298
+ const index = filterListCopy.findIndex(item => item.id === filterItem.id);
1299
+ filterListCopy.splice(index, 1, filterItemCopy);
1300
+ this.filters = ObjectUtils.copy(filterListCopy);
1301
+ return;
1302
+ }
1303
+ if (FilterItemType.CHECK_BOX_LIST === filterItem.type) {
1304
+ const filterListCopy = ObjectUtils.copy(this.filters);
1305
+ filterListCopy.find(filter => filter.id === filterItem.id).value = undefined;
1306
+ this.filters = ObjectUtils.copy(filterListCopy);
1307
+ return;
1308
+ }
1309
+ this.filters.find(filter => filter.id === filterItem.id).value = undefined;
1310
+ }
1311
+ uncheckFilterValues(valueList) {
1312
+ valueList.forEach(value => {
1313
+ if (!!value) {
1314
+ value.check = false;
1315
+ }
1316
+ });
1317
+ return valueList;
1318
+ }
1319
+ renderFilterItem(filterItem, fullRow) {
1320
+ return (h("snk-filter-modal-item", { class: fullRow ? 'ez-col ez-col--sd-12' : 'ez-col ez-col--sd-6 ez-padding--small', filterItem: filterItem, configName: this.configName, onFilterChange: (event) => this.handleFilterChange(event.detail), onEditPersonalizedFilter: evt => this.editPersonalizedFilter(evt.detail), onAddPersonalizedFilter: () => this.addPersonalizedFilter() }));
1321
+ }
1322
+ isDefaultFilterNumberVariation(filter) {
1323
+ var _a;
1324
+ return filter.type === FilterItemType.NUMBER
1325
+ && (!filter.props.variation || ((_a = filter.props) === null || _a === void 0 ? void 0 : _a.variation) === FilterNumberVariation.DEFAULT);
1326
+ }
1327
+ mountFiltersLines(filters) {
1328
+ const MAX_LINE_LENGTH = 2;
1329
+ let currentLine = 0;
1330
+ let forceAddCurrent = false;
1331
+ const filtersLines = {};
1332
+ for (let curr = 0; curr < filters.length; curr++) {
1333
+ filtersLines[currentLine] = filtersLines[currentLine] || [];
1334
+ const item = filters[curr];
1335
+ const isLast = curr === filters.length - 1;
1336
+ const currentItemMatch = item.type === FilterItemType.TEXT || this.isDefaultFilterNumberVariation(item);
1337
+ const nextItemMatch = isLast ? false : filters[curr + 1].type === FilterItemType.TEXT || this.isDefaultFilterNumberVariation(filters[curr + 1]);
1338
+ if ((currentItemMatch && nextItemMatch) || forceAddCurrent) {
1339
+ filtersLines[currentLine].push(item);
1340
+ forceAddCurrent = filtersLines[currentLine].length < MAX_LINE_LENGTH;
1341
+ if (filtersLines[currentLine].length === MAX_LINE_LENGTH)
1342
+ ++currentLine;
1343
+ continue;
1344
+ }
1345
+ filtersLines[currentLine] = filtersLines[currentLine] || [];
1346
+ filtersLines[currentLine].push(item);
1347
+ ++currentLine;
1348
+ }
1349
+ return Object.values(filtersLines);
1350
+ }
1351
+ renderFilterLine(filters) {
1352
+ const fullLine = filters.length === 1;
1353
+ return filters.map((filter) => this.renderFilterItem(filter, fullLine));
1354
+ }
1355
+ getIformedFiltersCount(listItems) {
1356
+ let countInformedItens = 0;
1357
+ listItems.forEach(item => {
1358
+ var _a, _b, _c, _d, _e, _f;
1359
+ if (FilterItemType.MULTI_LIST === item.type) {
1360
+ countInformedItens += (_e = (_d = (_c = ((_b = (_a = item.value) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : item.value)) === null || _c === void 0 ? void 0 : _c.filter(value => value === null || value === void 0 ? void 0 : value.check)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0;
1361
+ return;
1362
+ }
1363
+ if (FilterItemType.CHECK_BOX_LIST === item.type) {
1364
+ countInformedItens += Object.entries((_f = item.value) !== null && _f !== void 0 ? _f : {})
1365
+ .filter(([_, value]) => value === true)
1366
+ .map(([key, _]) => key).length;
1367
+ return;
1368
+ }
1369
+ if (item.groupedItems != undefined) {
1370
+ countInformedItens = item.groupedItems.filter(item => item.visible).length;
1371
+ return;
1372
+ }
1373
+ if (!!item.value) {
1374
+ countInformedItens++;
1375
+ }
1376
+ });
1377
+ return countInformedItens;
1378
+ }
1379
+ renderCollapsibleFilterBox(label, listItems, isSingleItem, shouldRenderFooter = true) {
1380
+ if (!listItems.length)
1381
+ return null;
1382
+ const appliedFilters = this.getIformedFiltersCount(listItems);
1383
+ const lines = this.mountFiltersLines(listItems);
1384
+ return (h("ez-collapsible-box", { class: "snk-filter-modal__collapsible-box", headerSize: "medium", value: true, label: label }, !!appliedFilters && (h("ez-badge", { class: "ez-badge--primary-subtle", slot: "rightSlot", label: appliedFilters === null || appliedFilters === void 0 ? void 0 : appliedFilters.toString() })), h("div", { class: "ez-row snk-filter-modal__rendered-items" }, lines.map(this.renderFilterLine.bind(this))), shouldRenderFooter && (h("div", { class: "ez-flex ez-flex--justify-end grow" }, h("ez-button", { class: "ez-button--tertiary", size: "medium", label: "Limpar", onClick: () => isSingleItem ? this.handleClearSigleFilter(listItems[0]) : this.handleClearFilterList(listItems) })))));
1385
+ }
1386
+ componentWillRender() {
1387
+ this._modalTitle = this.getCustomMessage('title');
1388
+ this._okButtonLabel = this.getCustomMessage('okButtonLabel');
1389
+ this._cancelButtonLabel = this.getCustomMessage('cancelButtonLabel');
1390
+ }
1391
+ componentDidLoad() {
1392
+ if (!this._originalFilterConfig)
1393
+ this._originalFilterConfig = this.filters;
1394
+ }
1395
+ render() {
1396
+ const customFilters = this.filters.filter(filter => filter.filterType === FilterType.CUSTOM_FILTER);
1397
+ const quickFilters = this.filters.filter(filter => filter.filterType === FilterType.QUICK_FILTER);
1398
+ const otherFilters = this.filters.filter(filter => filter.filterType === FilterType.OTHER_FILTERS);
1399
+ return (h("ez-modal-container", { class: "snk-filter-modal__container", modalTitle: this._modalTitle, cancelButtonLabel: this._cancelButtonLabel, okButtonLabel: this._okButtonLabel, onEzModalAction: this.modalActionListener.bind(this) }, h("div", { class: "snk-filter-modal__content ez-col--sd-12" }, !this.disablePersonalizedFilter && this.renderCollapsibleFilterBox(this.getCustomMessage('customFilters'), customFilters, false, false), this.renderCollapsibleFilterBox(this.getCustomMessage('quickFilters'), quickFilters, false), otherFilters.map(filter => this.renderCollapsibleFilterBox(filter.label, [filter], true)))));
1400
+ }
1401
+ };
1402
+ SnkFilterModal.style = snkFilterModalCss;
1403
+
1404
+ export { SnkFilterBar as snk_filter_bar, SnkFilterItem as snk_filter_item, SnkFilterList as snk_filter_list, SnkFilterModal as snk_filter_modal };