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