@sankhyalabs/sankhyablocks 0.0.0-bugfix-dev-KB-74246.1 → 0.0.0-bugfix-dev-KB-76362.0

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.
Files changed (86) hide show
  1. package/dist/cjs/{SnkFormConfigManager-bff848f1.js → SnkFormConfigManager-63369164.js} +3 -3
  2. package/dist/cjs/{SnkMessageBuilder-bae64d0d.js → SnkMessageBuilder-7691a2c1.js} +10 -0
  3. package/dist/cjs/index-f9e81701.js +8 -0
  4. package/dist/cjs/input-distinct-search_2.cjs.entry.js +471 -0
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  7. package/dist/cjs/snk-application.cjs.entry.js +1 -1
  8. package/dist/cjs/snk-config-options_3.cjs.entry.js +1 -1
  9. package/dist/cjs/snk-data-exporter.cjs.entry.js +2 -2
  10. package/dist/cjs/{snk-data-unit-3d4d0e2a.js → snk-data-unit-7dbdad0e.js} +1 -1
  11. package/dist/cjs/snk-data-unit.cjs.entry.js +2 -2
  12. package/dist/cjs/snk-detail-view.cjs.entry.js +3 -3
  13. package/dist/cjs/snk-distinct-search.cjs.entry.js +123 -0
  14. package/dist/cjs/{snk-guides-viewer-2b44c804.js → snk-guides-viewer-eee43c8b.js} +1 -1
  15. package/dist/cjs/snk-guides-viewer.cjs.entry.js +2 -2
  16. package/dist/cjs/snk-simple-crud.cjs.entry.js +1 -1
  17. package/dist/collection/collection-manifest.json +3 -0
  18. package/dist/collection/components/snk-distinct-search/snk-distinct-search.css +4 -0
  19. package/dist/collection/components/snk-distinct-search/snk-distinct-search.js +372 -0
  20. package/dist/collection/components/snk-distinct-search/subcomponents/input-distinct-search/input-distinct-search.css +110 -0
  21. package/dist/collection/components/snk-distinct-search/subcomponents/input-distinct-search/input-distinct-search.js +544 -0
  22. package/dist/collection/components/snk-distinct-search/subcomponents/search-modal/search-modal.css +28 -0
  23. package/dist/collection/components/snk-distinct-search/subcomponents/search-modal/search-modal.js +593 -0
  24. package/dist/collection/components/snk-distinct-search/types/index.js +1 -0
  25. package/dist/collection/components/snk-distinct-search/utils/filter-distinct-search.js +15 -0
  26. package/dist/collection/components/snk-form-config/SnkFormConfigManager.js +3 -3
  27. package/dist/collection/lib/http/data-fetcher/fetchers/distinct-search-fetcher.js +25 -0
  28. package/dist/collection/lib/message/SnkMessageBuilder.js +2 -0
  29. package/dist/collection/lib/message/resources/snk-distinct-search.msg.js +9 -0
  30. package/dist/components/SnkFormConfigManager.js +3 -3
  31. package/dist/components/SnkMessageBuilder.js +10 -0
  32. package/dist/components/filter-distinct-search.js +17 -0
  33. package/dist/components/index.d.ts +3 -0
  34. package/dist/components/index.js +3 -0
  35. package/dist/components/input-distinct-search.d.ts +11 -0
  36. package/dist/components/input-distinct-search.js +6 -0
  37. package/dist/components/input-distinct-search2.js +264 -0
  38. package/dist/components/search-modal.d.ts +11 -0
  39. package/dist/components/search-modal.js +6 -0
  40. package/dist/components/search-modal2.js +264 -0
  41. package/dist/components/snk-distinct-search.d.ts +11 -0
  42. package/dist/components/snk-distinct-search.js +163 -0
  43. package/dist/esm/{SnkFormConfigManager-f0532f7d.js → SnkFormConfigManager-b409c745.js} +3 -3
  44. package/dist/esm/{SnkMessageBuilder-6fff4a4c.js → SnkMessageBuilder-7ace6803.js} +10 -0
  45. package/dist/esm/index-a7d3d3f1.js +8 -0
  46. package/dist/esm/input-distinct-search_2.entry.js +466 -0
  47. package/dist/esm/loader.js +1 -1
  48. package/dist/esm/sankhyablocks.js +1 -1
  49. package/dist/esm/snk-application.entry.js +1 -1
  50. package/dist/esm/snk-config-options_3.entry.js +1 -1
  51. package/dist/esm/snk-data-exporter.entry.js +2 -2
  52. package/dist/esm/{snk-data-unit-618e0b80.js → snk-data-unit-7a579dbd.js} +1 -1
  53. package/dist/esm/snk-data-unit.entry.js +2 -2
  54. package/dist/esm/snk-detail-view.entry.js +3 -3
  55. package/dist/esm/snk-distinct-search.entry.js +119 -0
  56. package/dist/esm/{snk-guides-viewer-15c916a3.js → snk-guides-viewer-e8ca764a.js} +1 -1
  57. package/dist/esm/snk-guides-viewer.entry.js +2 -2
  58. package/dist/esm/snk-simple-crud.entry.js +1 -1
  59. package/dist/sankhyablocks/{p-9c3138f5.entry.js → p-00f9fe5c.entry.js} +1 -1
  60. package/dist/sankhyablocks/p-0e206e62.js +1 -0
  61. package/dist/sankhyablocks/{p-c88ad28e.entry.js → p-0e250436.entry.js} +1 -1
  62. package/dist/sankhyablocks/{p-da87e42c.entry.js → p-154aa2a6.entry.js} +1 -1
  63. package/dist/sankhyablocks/p-18cb1acb.entry.js +1 -0
  64. package/dist/sankhyablocks/{p-bab79110.entry.js → p-30ebcbe0.entry.js} +1 -1
  65. package/dist/sankhyablocks/p-3755b46f.entry.js +1 -0
  66. package/dist/sankhyablocks/{p-d1da52e1.entry.js → p-42130213.entry.js} +1 -1
  67. package/dist/sankhyablocks/{p-e41bd8ee.entry.js → p-b389ed49.entry.js} +1 -1
  68. package/dist/sankhyablocks/{p-a75e9dcc.js → p-c75fae8e.js} +1 -1
  69. package/dist/sankhyablocks/p-d8665750.js +1 -0
  70. package/dist/sankhyablocks/{p-ae50d69f.js → p-e3a285a2.js} +1 -1
  71. package/dist/sankhyablocks/{p-c1adf0dd.entry.js → p-f4e221b2.entry.js} +1 -1
  72. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  73. package/dist/types/components/snk-distinct-search/snk-distinct-search.d.ts +83 -0
  74. package/dist/types/components/snk-distinct-search/subcomponents/input-distinct-search/input-distinct-search.d.ts +105 -0
  75. package/dist/types/components/snk-distinct-search/subcomponents/search-modal/search-modal.d.ts +127 -0
  76. package/dist/types/components/snk-distinct-search/types/index.d.ts +12 -0
  77. package/dist/types/components/snk-distinct-search/utils/filter-distinct-search.d.ts +4 -0
  78. package/dist/types/components.d.ts +393 -1
  79. package/dist/types/lib/http/data-fetcher/fetchers/distinct-search-fetcher.d.ts +6 -0
  80. package/dist/types/lib/message/resources/snk-distinct-search.msg.d.ts +2 -0
  81. package/package.json +1 -1
  82. package/react/components.d.ts +3 -0
  83. package/react/components.js +3 -0
  84. package/react/components.js.map +1 -1
  85. package/dist/sankhyablocks/p-17425c72.js +0 -1
  86. package/dist/sankhyablocks/p-a0ebd886.js +0 -1
@@ -88,13 +88,13 @@ class SnkFormConfigManager {
88
88
  const fields = (_a = this._config) === null || _a === void 0 ? void 0 : _a.fields;
89
89
  const hasConfig = this.hasConfig();
90
90
  if (hasConfig && !forceEmptyConfig) {
91
- return fields.map(({ label, name, readOnly, visible, required, tab, group }) => {
91
+ return fields.map(({ label, name, readOnly, visible, required, tab }) => {
92
92
  var _a;
93
93
  if (label == undefined) {
94
94
  const currentField = (_a = this._dataUnit) === null || _a === void 0 ? void 0 : _a.getField(name);
95
- return Object.assign(Object.assign({}, currentField), { name: name !== null && name !== void 0 ? name : currentField.name, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : currentField.readOnly, visible: visible !== null && visible !== void 0 ? visible : currentField.visible, required: required !== null && required !== void 0 ? required : currentField.required, tab: tab, group: group });
95
+ return Object.assign(Object.assign({}, currentField), { name: name !== null && name !== void 0 ? name : currentField.name, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : currentField.readOnly, visible: visible !== null && visible !== void 0 ? visible : currentField.visible, required: required !== null && required !== void 0 ? required : currentField.required, tab: tab });
96
96
  }
97
- return { name, label, readOnly, visible, required, tab, group };
97
+ return { name, label, readOnly, visible, required, tab };
98
98
  })
99
99
  .filter(field => this.isFieldVisible(field, descriptionFilter));
100
100
  }
@@ -172,6 +172,15 @@ const snkAttachMessages$1 = {
172
172
  }
173
173
  };
174
174
 
175
+ const snkDistinctSearchMessages = {
176
+ titleBadgeNew: "novo",
177
+ titleAdd: "Adicionar",
178
+ availableResults: "resultados disponíveis",
179
+ availableResult: "resultado disponível",
180
+ limitResult: "Esta pesquisa foi limitada, existem mais resultados",
181
+ emptyResult: "Nenhum resultado disponível. <br/>Você pode adicionar um novo termo",
182
+ };
183
+
175
184
  const snkConfigOptionsMessages = {
176
185
  label: {
177
186
  nameField: "Nome do Campo *",
@@ -552,6 +561,7 @@ class SnkMessageBuilder {
552
561
  snkEntityList: snkEntityListMessages,
553
562
  snkActionsButton: snkActionsButtonMessages,
554
563
  snkPrintSelector: snkPrintSelectorMessages,
564
+ snkDistinctSearch: snkDistinctSearchMessages,
555
565
  };
556
566
  this._currentOperation = OperationMap.CLEAN;
557
567
  this._domainName = domainName;
@@ -0,0 +1,17 @@
1
+ function normalizeString(text = "") {
2
+ return text.normalize('NFD').replace(/[\u0300-\u036f/\s'"&.-]/g, "").toUpperCase();
3
+ }
4
+ function filterItems(searchArgument, distinctItems, maxItems) {
5
+ const normalizedSearch = normalizeString(searchArgument);
6
+ const filteredDistincts = distinctItems.filter((item) => normalizeString(item).includes(normalizedSearch));
7
+ const isLimited = filteredDistincts.length > maxItems;
8
+ const items = filteredDistincts.slice(0, maxItems);
9
+ return { items, isLimited };
10
+ }
11
+ function getMatchOption(value, distinctItems) {
12
+ const normalizedSearch = normalizeString(value);
13
+ const item = distinctItems.find((item) => normalizeString(item) === normalizedSearch);
14
+ return item;
15
+ }
16
+
17
+ export { filterItems as f, getMatchOption as g, normalizeString as n };
@@ -1,4 +1,6 @@
1
1
  /* sankhyablocks custom elements */
2
+ export { InputDistinctSearch as InputDistinctSearch } from '../types/components/snk-distinct-search/subcomponents/input-distinct-search/input-distinct-search';
3
+ export { SearchModal as SearchModal } from '../types/components/snk-distinct-search/subcomponents/search-modal/search-modal';
2
4
  export { SnkActionsButton as SnkActionsButton } from '../types/components/snk-actions-button/snk-actions-button';
3
5
  export { SnkActionsForm as SnkActionsForm } from '../types/components/snk-actions-button/subcomponents/snk-actions-form';
4
6
  export { SnkApplication as SnkApplication } from '../types/components/snk-application/snk-application';
@@ -11,6 +13,7 @@ export { SnkCustomSlotElements as SnkCustomSlotElements } from '../types/compone
11
13
  export { SnkDataExporter as SnkDataExporter } from '../types/components/snk-data-exporter/snk-data-exporter';
12
14
  export { SnkDataUnit as SnkDataUnit } from '../types/components/snk-data-unit/snk-data-unit';
13
15
  export { SnkDetailView as SnkDetailView } from '../types/components/snk-crud/subcomponents/snk-detail-view/snk-detail-view';
16
+ export { SnkDistinctSearch as SnkDistinctSearch } from '../types/components/snk-distinct-search/snk-distinct-search';
14
17
  export { SnkEntityList as SnkEntityList } from '../types/components/snk-entity-list/snk-entity-list';
15
18
  export { SnkExporterEmailSender as SnkExporterEmailSender } from '../types/components/snk-data-exporter/exporter-email-sender/snk-exporter-email-sender';
16
19
  export { SnkExpressionGroup as SnkExpressionGroup } from '../types/components/snk-personalized-filter/subcomponents/snk-expression-group/snk-expression-group';
@@ -1,4 +1,6 @@
1
1
  export { setAssetPath, setNonce, setPlatformOptions } from '@stencil/core/internal/client';
2
+ export { InputDistinctSearch, defineCustomElement as defineCustomElementInputDistinctSearch } from './input-distinct-search.js';
3
+ export { SearchModal, defineCustomElement as defineCustomElementSearchModal } from './search-modal.js';
2
4
  export { SnkActionsButton, defineCustomElement as defineCustomElementSnkActionsButton } from './snk-actions-button.js';
3
5
  export { SnkActionsForm, defineCustomElement as defineCustomElementSnkActionsForm } from './snk-actions-form.js';
4
6
  export { SnkApplication, defineCustomElement as defineCustomElementSnkApplication } from './snk-application.js';
@@ -11,6 +13,7 @@ export { SnkCustomSlotElements, defineCustomElement as defineCustomElementSnkCus
11
13
  export { SnkDataExporter, defineCustomElement as defineCustomElementSnkDataExporter } from './snk-data-exporter.js';
12
14
  export { SnkDataUnit, defineCustomElement as defineCustomElementSnkDataUnit } from './snk-data-unit.js';
13
15
  export { SnkDetailView, defineCustomElement as defineCustomElementSnkDetailView } from './snk-detail-view.js';
16
+ export { SnkDistinctSearch, defineCustomElement as defineCustomElementSnkDistinctSearch } from './snk-distinct-search.js';
14
17
  export { SnkEntityList, defineCustomElement as defineCustomElementSnkEntityList } from './snk-entity-list.js';
15
18
  export { SnkExporterEmailSender, defineCustomElement as defineCustomElementSnkExporterEmailSender } from './snk-exporter-email-sender.js';
16
19
  export { SnkExpressionGroup, defineCustomElement as defineCustomElementSnkExpressionGroup } from './snk-expression-group.js';
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface InputDistinctSearch extends Components.InputDistinctSearch, HTMLElement {}
4
+ export const InputDistinctSearch: {
5
+ prototype: InputDistinctSearch;
6
+ new (): InputDistinctSearch;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,6 @@
1
+ import { I as InputDistinctSearch$1, d as defineCustomElement$1 } from './input-distinct-search2.js';
2
+
3
+ const InputDistinctSearch = InputDistinctSearch$1;
4
+ const defineCustomElement = defineCustomElement$1;
5
+
6
+ export { InputDistinctSearch, defineCustomElement };
@@ -0,0 +1,264 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h, Fragment, Host } from '@stencil/core/internal/client';
2
+ import { KeyboardManager } from '@sankhyalabs/core';
3
+ import { f as filterItems, n as normalizeString, g as getMatchOption } from './filter-distinct-search.js';
4
+
5
+ const inputDistinctSearchCss = ":host{--max-height-popover:180px;--scrollbar--color-default:var(--scrollbar--default, #626e82);--scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--scrollbar--border-radius:var(--border--radius-small, 6px);--scrollbar--width:var(--space--medium, 12px)}.divider{margin:var(--space--extra-small, 3px) 0;border:var(--border--small, 1px solid) var(--color--disable-secondary, #F2F5F8)}.new-value{color:var(--text--primary, #626e82);padding:var(--space--2xs, 8px) var(--space--3xs, 4px);font-size:var(--text--medium, 14px);font-family:var(--font-pattern, Roboto);cursor:pointer;border-radius:var(--border--radius-small, 6px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border:none;background:none;width:100%;display:flex;min-height:max-content}.new-value-selected{background-color:var(--color--primary-300, #E2F4EF)}.new-value:hover{background-color:var(--background--medium, #e0e0e0)}.popover-content{margin:var(--space--small, 6px);max-height:calc(var(--max-height-popover) - (2 * var(--space--small, 6px)));display:flex;flex-direction:column}.list-container{overflow:auto;scrollbar-width:thin;scrollbar-color:var(--scrollbar--color-clicked) var(--scrollbar--color-background);padding-right:var(--space--small, 6px)}.list-container::-webkit-scrollbar{background-color:var(--scrollbar--color-background);width:var(--scrollbar--width);max-width:var(--scrollbar--width);min-width:var(--scrollbar--width)}.list-container::-webkit-scrollbar-track{background-color:var(--scrollbar--color-background);border-radius:var(--scrollbar--border-radius)}.list-container::-webkit-scrollbar-thumb{background-color:var(--scrollbar--color-default);border-radius:var(--scrollbar--border-radius)}.list-container::-webkit-scrollbar-thumb:vertical:hover,.list-container::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--scrollbar--color-hover)}.list-container::-webkit-scrollbar-thumb:vertical:active,.list-container::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--scrollbar--color-clicked)}ez-popover{--ez-popover__box--z-index:15}.space-error{--ez-popover__margin:-19px 0 0 0}ez-list{--ez-list__item--margin:0}ez-text-input{--ez-text-input__icon--margin:var(--space--xs, 12px)}.badge-primary{--ez-badge--background-color:var(--color--primary-300);--ez-badge--color:var(--color--primary)}";
6
+
7
+ const InputDistinctSearch = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
8
+ constructor() {
9
+ super();
10
+ this.__registerHost();
11
+ this.__attachShadow();
12
+ this.changeValue = createEvent(this, "changeValue", 7);
13
+ this.iconClick = createEvent(this, "iconClick", 7);
14
+ this.textValue = "";
15
+ this.isNewItem = false;
16
+ this.filteredItems = [];
17
+ this.isNewItemSelected = false;
18
+ this.application = undefined;
19
+ this.distinctItems = [];
20
+ this.label = "";
21
+ this.value = "";
22
+ this.maxItems = 100;
23
+ this.debounceTime = 300;
24
+ this.canShowError = false;
25
+ this.mode = 'regular';
26
+ this.restrict = undefined;
27
+ this.errorMessage = undefined;
28
+ }
29
+ async observerValue(newValue) {
30
+ await this.selectedNewItem(newValue, true);
31
+ }
32
+ /**
33
+ * Seleciona um item
34
+ */
35
+ async selectValue(value, isNewItem = false) {
36
+ this.isNewItem = isNewItem;
37
+ this.textValue = value;
38
+ await this._refFilterInput.setValue(value);
39
+ }
40
+ /**
41
+ * Método para limpa o campo de entrada de pesquisa
42
+ */
43
+ clearInput() {
44
+ this._refFilterInput.setValue("");
45
+ }
46
+ /**
47
+ * Retorna se o conteúdo é inválido.
48
+ */
49
+ isInvalid() {
50
+ return this._refFilterInput.isInvalid();
51
+ }
52
+ /**
53
+ * Remove o foco do campo
54
+ */
55
+ setBlur() {
56
+ this._refFilterInput.setBlur();
57
+ }
58
+ /**
59
+ * Aplica o foco do campo
60
+ */
61
+ setFocus() {
62
+ this._refFilterInput.setFocus();
63
+ }
64
+ getMessage(key) {
65
+ return this.application.messagesBuilder.getMessage(key, null);
66
+ }
67
+ async optionLoader(searchArgument) {
68
+ return new Promise((resolve) => {
69
+ if (this._debounceTimeout) {
70
+ clearTimeout(this._debounceTimeout);
71
+ }
72
+ this._debounceTimeout = setTimeout(() => {
73
+ const { items } = filterItems(searchArgument, this.distinctItems, this.maxItems);
74
+ this.filteredItems = items;
75
+ resolve();
76
+ }, this.debounceTime);
77
+ });
78
+ }
79
+ async openPopOver() {
80
+ var _a;
81
+ await ((_a = this._refPopOver) === null || _a === void 0 ? void 0 : _a.showUnder(this._refFilterInput));
82
+ }
83
+ async closePopOver() {
84
+ var _a;
85
+ this.isNewItemSelected = false;
86
+ await ((_a = this._refPopOver) === null || _a === void 0 ? void 0 : _a.hide());
87
+ await this._refList.removeSelection();
88
+ }
89
+ async onTextChange(event) {
90
+ this.textValue = event.detail;
91
+ await this.optionLoader(event.detail);
92
+ await this.selectFirstItem();
93
+ }
94
+ onIconClick() {
95
+ this.iconClick.emit();
96
+ }
97
+ buidItems() {
98
+ var _a;
99
+ const items = (_a = this.filteredItems) === null || _a === void 0 ? void 0 : _a.map((item) => ({
100
+ label: item,
101
+ id: normalizeString(item),
102
+ }));
103
+ return items;
104
+ }
105
+ async setValue(value, isNewItem = false, preventEventEmit = false) {
106
+ this.isNewItem = isNewItem;
107
+ this.textValue = value;
108
+ await this._refFilterInput.setValue(value);
109
+ await this.closePopOver();
110
+ if (!preventEventEmit) {
111
+ this.changeValue.emit({
112
+ value,
113
+ isNewItem,
114
+ });
115
+ }
116
+ }
117
+ async selectedNewItem(value, preventEventEmit = false) {
118
+ if (!this.textValue && !value) {
119
+ await this.setValue("", false, preventEventEmit);
120
+ return;
121
+ }
122
+ const item = getMatchOption(value !== null && value !== void 0 ? value : this.textValue, this.distinctItems);
123
+ if (item) {
124
+ await this.setValue(item, false, preventEventEmit);
125
+ return;
126
+ }
127
+ await this.setValue(this.textValue || value, true, preventEventEmit);
128
+ }
129
+ async setSelectedValue() {
130
+ const selectedValue = await this._refList.getSelection();
131
+ await this.selectedNewItem((selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.label) || this.textValue, true);
132
+ await this._refFilterInput.setBlur();
133
+ this._element.focus();
134
+ }
135
+ async selectNextItem() {
136
+ if (this.isNewItemSelected) {
137
+ return;
138
+ }
139
+ const itemSelected = await this._refList.getSelection();
140
+ const itemsAmount = this.filteredItems.length;
141
+ const indexSelected = this.filteredItems.findIndex((item) => item === (itemSelected === null || itemSelected === void 0 ? void 0 : itemSelected.label));
142
+ const isLastItemSelected = indexSelected === (itemsAmount - 1);
143
+ const optionNewItemIsAvailable = !!this.textValue;
144
+ if (!isLastItemSelected || !optionNewItemIsAvailable) {
145
+ this.isNewItemSelected = false;
146
+ await this._refList.selectNextItem();
147
+ return;
148
+ }
149
+ this.isNewItemSelected = true;
150
+ await this._refList.removeSelection();
151
+ }
152
+ async selectPreviousItem() {
153
+ const itemsAmount = this.filteredItems.length;
154
+ const lastItem = this.filteredItems[itemsAmount - 1];
155
+ if (this.isNewItemSelected && lastItem) {
156
+ this.isNewItemSelected = false;
157
+ await this._refList.setSelection({
158
+ id: normalizeString(lastItem),
159
+ label: lastItem
160
+ });
161
+ return;
162
+ }
163
+ await this._refList.selectPreviousItem();
164
+ }
165
+ bindKeyboardManager() {
166
+ this._keyboardManager = new KeyboardManager({ propagate: false, element: this._element });
167
+ this._keyboardManager
168
+ .bind("ArrowDown", () => { this.selectNextItem(); })
169
+ .bind("ArrowUp", () => { this.selectPreviousItem(); })
170
+ .bind("Enter", () => { this.setSelectedValue(); })
171
+ .bind("Tab", () => { this.setSelectedValue(); });
172
+ }
173
+ unbindKeyboardManager() {
174
+ this._keyboardManager
175
+ .unbind("ArrowDown")
176
+ .unbind("ArrowUp")
177
+ .unbind("Enter")
178
+ .unbind("Tab");
179
+ }
180
+ async selectFirstItem() {
181
+ if (!this.filteredItems.length) {
182
+ await this._refList.removeSelection();
183
+ this.isNewItemSelected = true;
184
+ return;
185
+ }
186
+ const firstItem = this.filteredItems[0];
187
+ this.isNewItemSelected = false;
188
+ await this._refList.setSelection({
189
+ id: normalizeString(firstItem),
190
+ label: firstItem,
191
+ });
192
+ }
193
+ initializeComponent() {
194
+ const { items } = filterItems("", this.distinctItems, this.maxItems);
195
+ this.filteredItems = items;
196
+ }
197
+ componentWillLoad() {
198
+ this.initializeComponent();
199
+ }
200
+ async componentDidLoad() {
201
+ this.bindKeyboardManager();
202
+ this.selectFirstItem();
203
+ await this.selectedNewItem(this.value, true);
204
+ }
205
+ disconnectedCallback() {
206
+ this.unbindKeyboardManager();
207
+ }
208
+ buildNewItemOption() {
209
+ if (!this.textValue) {
210
+ return;
211
+ }
212
+ return (h(Fragment, null, !!this.filteredItems.length &&
213
+ h("hr", { class: "divider" }), h("button", { slot: "bottomSlot", class: {
214
+ "new-value": true,
215
+ "new-value-selected": this.isNewItemSelected,
216
+ }, title: `${this.getMessage("snkDistinctSearch.titleAdd")} '${this.textValue}'`, onClick: () => this.selectedNewItem.bind(this)(undefined, true) }, this.getMessage("snkDistinctSearch.titleAdd"), " '", this.textValue, "'")));
217
+ }
218
+ render() {
219
+ return (h(Host, { onBlur: () => this.selectedNewItem.bind(this)() }, h("ez-filter-input", { ref: (ref) => this._refFilterInput = ref, label: this.label, value: this.textValue, onEzChange: this.onTextChange.bind(this), onEzIconClick: this.onIconClick.bind(this), onEzFocusIn: this.openPopOver.bind(this), canShowError: this.canShowError, mode: this.mode, restrict: this.restrict, errorMessage: this.errorMessage, enabledIconClick: true }, this.isNewItem &&
220
+ h("ez-badge", { slot: "right", label: this.getMessage("snkDistinctSearch.titleBadgeNew"), size: "small-medium", class: "badge-primary" })), h("ez-popover", { ref: (ref) => this._refPopOver = ref, boxWidth: "full-width", autoClose: false, overlayType: "none", class: {
221
+ 'space-error': this.canShowError,
222
+ } }, h("div", { class: "popover-content" }, h("section", { class: "list-container" }, h("ez-list", { ref: (ref) => this._refList = ref, dataSource: this.buidItems(), onEzClickItem: ({ detail }) => this.setValue.bind(this)(detail.label, false, true), ezSelectable: true, hoverFeedback: true, disableShortcuts: true })), this.buildNewItemOption()))));
223
+ }
224
+ get _element() { return this; }
225
+ static get watchers() { return {
226
+ "value": ["observerValue"]
227
+ }; }
228
+ static get style() { return inputDistinctSearchCss; }
229
+ }, [1, "input-distinct-search", {
230
+ "application": [16],
231
+ "distinctItems": [16],
232
+ "label": [1],
233
+ "value": [1],
234
+ "maxItems": [2, "max-items"],
235
+ "debounceTime": [2, "debounce-time"],
236
+ "canShowError": [4, "can-show-error"],
237
+ "mode": [1],
238
+ "restrict": [1],
239
+ "errorMessage": [1, "error-message"],
240
+ "textValue": [32],
241
+ "isNewItem": [32],
242
+ "filteredItems": [32],
243
+ "isNewItemSelected": [32],
244
+ "selectValue": [64],
245
+ "clearInput": [64],
246
+ "isInvalid": [64],
247
+ "setBlur": [64],
248
+ "setFocus": [64]
249
+ }]);
250
+ function defineCustomElement() {
251
+ if (typeof customElements === "undefined") {
252
+ return;
253
+ }
254
+ const components = ["input-distinct-search"];
255
+ components.forEach(tagName => { switch (tagName) {
256
+ case "input-distinct-search":
257
+ if (!customElements.get(tagName)) {
258
+ customElements.define(tagName, InputDistinctSearch);
259
+ }
260
+ break;
261
+ } });
262
+ }
263
+
264
+ export { InputDistinctSearch as I, defineCustomElement as d };
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface SearchModal extends Components.SearchModal, HTMLElement {}
4
+ export const SearchModal: {
5
+ prototype: SearchModal;
6
+ new (): SearchModal;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,6 @@
1
+ import { S as SearchModal$1, d as defineCustomElement$1 } from './search-modal2.js';
2
+
3
+ const SearchModal = SearchModal$1;
4
+ const defineCustomElement = defineCustomElement$1;
5
+
6
+ export { SearchModal, defineCustomElement };
@@ -0,0 +1,264 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
+ import { EzScrollDirection } from '@sankhyalabs/ezui/dist/collection/components/ez-scroller/EzScrollDirection';
3
+ import { KeyboardManager } from '@sankhyalabs/core';
4
+ import { f as filterItems, n as normalizeString, g as getMatchOption } from './filter-distinct-search.js';
5
+
6
+ const searchModalCss = ".sc-search-modal-h{display:block}ez-popup.sc-search-modal{--ez-popup__title--font-size:var(--title--large, 20px);--ez-popup__container--height:380px}.search-modal-scroller.sc-search-modal{height:174px}.search-modal-text.sc-search-modal{font-family:var(--font-pattern);color:var(--text--primary);font-size:var(--text--medium)}ez-filter-input.sc-search-modal>input.sc-search-modal{text-overflow:ellipsis}.ez-content.sc-search-modal{height:190px;display:flex;align-items:center;justify-content:center}";
7
+
8
+ const SearchModal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
9
+ constructor() {
10
+ super();
11
+ this.__registerHost();
12
+ this.popupClose = createEvent(this, "popupClose", 7);
13
+ this.changeValue = createEvent(this, "changeValue", 7);
14
+ this.debounceTimeout = null;
15
+ this.filteredItems = [];
16
+ this.searchFocus = false;
17
+ this.isLimited = false;
18
+ this.application = undefined;
19
+ this.listItens = [];
20
+ this.opened = false;
21
+ this.value = undefined;
22
+ this.canShowError = false;
23
+ this.emptyMessage = undefined;
24
+ this.debounceTime = 300;
25
+ this.maxItens = 100;
26
+ this.label = 'Pesquisar';
27
+ this.mode = 'regular';
28
+ this.restrict = undefined;
29
+ this.errorMessage = undefined;
30
+ }
31
+ /**
32
+ * Método para adicionar a nova palavra e chamar o método closeModal() para fechar o modal
33
+ */
34
+ addNewItem() {
35
+ this.closeModal();
36
+ this.changeValue.emit({ isNewItem: true, value: this.value });
37
+ }
38
+ /**
39
+ * Método para limpa o campo de entrada de pesquisa
40
+ */
41
+ clearInput() {
42
+ this._refFilterInput.setValue("");
43
+ }
44
+ /**
45
+ * Método para fechar o modal
46
+ */
47
+ closeModal() {
48
+ this._popupElement.opened = false;
49
+ this.popupClose.emit(false);
50
+ }
51
+ /**
52
+ * Método para abrir o modal
53
+ */
54
+ openModal() {
55
+ this._popupElement.opened = true;
56
+ setTimeout(() => this.setFocus(), 100);
57
+ }
58
+ /**
59
+ * Retorna se o conteúdo é inválido.
60
+ */
61
+ isInvalid() {
62
+ this._refFilterInput.isInvalid();
63
+ }
64
+ /**
65
+ * Remove o foco do campo
66
+ */
67
+ setBlur() {
68
+ this._refFilterInput.setBlur();
69
+ this.searchFocus = false;
70
+ }
71
+ /**
72
+ * Aplica o foco do campo
73
+ */
74
+ setFocus() {
75
+ this._refFilterInput.setFocus();
76
+ this.searchFocus = true;
77
+ }
78
+ /**
79
+ * Método para tratar a mensagem de erro
80
+ */
81
+ watchPropErrorMessage() {
82
+ this._refFilterInput.errorMessage = this.errorMessage;
83
+ }
84
+ /**
85
+ * Método para tratar o value do input
86
+ */
87
+ watchPropValue() {
88
+ this._refFilterInput.value = this.value;
89
+ }
90
+ /**
91
+ * Atualiza a lista de itens à medida que o usuário digita no campo de pesquisa.
92
+ */
93
+ async handleInput(event) {
94
+ if (this.debounceTimeout) {
95
+ clearTimeout(this.debounceTimeout);
96
+ }
97
+ this.value = event.detail;
98
+ this.debounceTimeout = setTimeout(async () => {
99
+ var _a;
100
+ const { isLimited, items } = filterItems(event.detail, this.listItens, this.maxItens);
101
+ this.filteredItems = items;
102
+ this.isLimited = isLimited;
103
+ await ((_a = this._refList) === null || _a === void 0 ? void 0 : _a.removeSelection());
104
+ }, this.debounceTime);
105
+ }
106
+ initializeComponent() {
107
+ this.filteredItems = this.listItens;
108
+ }
109
+ getMessage(key) {
110
+ return this.application.messagesBuilder.getMessage(key, null);
111
+ }
112
+ componentWillLoad() {
113
+ this.initializeComponent();
114
+ }
115
+ componentDidLoad() {
116
+ this.bindKeyboardManager();
117
+ this._refFilterInput.value = this.value;
118
+ const { isLimited, items } = filterItems(this.value, this.listItens, this.maxItens);
119
+ this.filteredItems = items;
120
+ this.isLimited = isLimited;
121
+ }
122
+ disconnectedCallback() {
123
+ this.unbindKeyboardManager();
124
+ }
125
+ buildItems() {
126
+ var _a;
127
+ const items = (_a = this.filteredItems) === null || _a === void 0 ? void 0 : _a.map((item) => ({
128
+ label: item,
129
+ id: normalizeString(item),
130
+ }));
131
+ return items;
132
+ }
133
+ async tabSelect() {
134
+ var _a;
135
+ const selectedValue = await ((_a = this._refList) === null || _a === void 0 ? void 0 : _a.getSelection());
136
+ if (this.searchFocus && this._refList) {
137
+ this.searchFocus = false;
138
+ this._refList.focus();
139
+ await this.selectFirstItem();
140
+ }
141
+ else if (selectedValue) {
142
+ await this._refList.removeSelection();
143
+ await this._refButton.setFocus();
144
+ }
145
+ else {
146
+ await this._refButton.setBlur();
147
+ this.setFocus();
148
+ }
149
+ }
150
+ bindKeyboardManager() {
151
+ this._keyboardManager = new KeyboardManager({ propagate: false, element: this._element });
152
+ this._keyboardManager
153
+ .bind("ArrowDown", () => { this.selectNextItem(); })
154
+ .bind("ArrowUp", () => { this.selectPreviousItem(); })
155
+ .bind("Enter", () => { this.setSelectedValue(); })
156
+ .bind("Tab", () => { this.tabSelect(); });
157
+ }
158
+ unbindKeyboardManager() {
159
+ this._keyboardManager
160
+ .unbind("ArrowDown")
161
+ .unbind("ArrowUp")
162
+ .unbind("Enter")
163
+ .unbind("Tab");
164
+ }
165
+ async setSelectedValue() {
166
+ var _a;
167
+ const selectedValue = await ((_a = this._refList) === null || _a === void 0 ? void 0 : _a.getSelection());
168
+ if (selectedValue) {
169
+ this.changeValue.emit({ isNewItem: false, value: selectedValue.label });
170
+ this.closeModal();
171
+ }
172
+ else if (this.searchFocus && this.enabledButtonNewItem()) {
173
+ this.addNewItem();
174
+ }
175
+ }
176
+ async selectNextItem() {
177
+ var _a;
178
+ const itemSelected = await ((_a = this._refList) === null || _a === void 0 ? void 0 : _a.getSelection());
179
+ if (this.searchFocus && !itemSelected) {
180
+ this.setBlur();
181
+ await this.selectFirstItem();
182
+ return;
183
+ }
184
+ await this._refList.selectNextItem();
185
+ }
186
+ async selectPreviousItem() {
187
+ const itemSelected = await this._refList.getSelection();
188
+ if (itemSelected === undefined)
189
+ return;
190
+ await this._refList.selectPreviousItem();
191
+ }
192
+ async selectFirstItem() {
193
+ if (!this.filteredItems.length) {
194
+ await this._refList.removeSelection();
195
+ return;
196
+ }
197
+ const firstItem = this.filteredItems[0];
198
+ await this._refList.setSelection({
199
+ id: normalizeString(firstItem),
200
+ label: firstItem,
201
+ });
202
+ }
203
+ enabledButtonNewItem() {
204
+ if (this.value === undefined)
205
+ return false;
206
+ if (getMatchOption(this.value, this.listItens))
207
+ return false;
208
+ return this.value.trim().length === 0 ? false : true;
209
+ }
210
+ buildMessage() {
211
+ if (this.isLimited) {
212
+ return this.getMessage("snkDistinctSearch.limitResult");
213
+ }
214
+ return `${this.filteredItems.length} ${this.filteredItems.length > 1 ? this.getMessage("snkDistinctSearch.availableResults") : this.getMessage("snkDistinctSearch.availableResult")}`;
215
+ }
216
+ render() {
217
+ var _a;
218
+ return (h(Host, null, h("ez-popup", { ref: (ref) => this._popupElement = ref, size: "400px", "ez-title": this.label, onEzClosePopup: () => this.popupClose.emit(false), "height-mode": "full" }, h("div", null, h("ez-filter-input", { ref: (ref) => this._refFilterInput = ref, label: "Pesquisar", onEzChange: this.handleInput.bind(this), onBlur: () => this.searchFocus = false, onEzFocusIn: () => this.searchFocus = true, errorMessage: this.errorMessage, canShowError: this.canShowError, mode: this.mode, value: this.value, restrict: this.restrict }), this.filteredItems.length === 0 ? (h("div", { class: "ez-content" }, h("div", { class: "ez-text--center search-modal-text" }, this.emptyMessage))) : (h("div", null, h("div", { class: "search-modal-text ez-padding-vertical--medium" }, this.buildMessage()), h("ez-scroller", { class: "search-modal-scroller", direction: EzScrollDirection.VERTICAL }, h("ez-list", { ref: (ref) => this._refList = ref, dataSource: this.buildItems(), onEzClickItem: ({ label }) => this.setSelectedValue.bind(this)(label), ezSelectable: true, hoverFeedback: true, disableShortcuts: true })))), h("div", { class: "ez-flex ez-flex--justify-end" }, h("ez-button", { ref: (ref) => this._refButton = ref, class: "ez-button--tertiary", enabled: this.enabledButtonNewItem(), label: `${this.getMessage("snkDistinctSearch.titleAdd")} ${(_a = this.label) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()}`, onClick: () => this.addNewItem() }))))));
219
+ }
220
+ get _element() { return this; }
221
+ static get watchers() { return {
222
+ "errorMessage": ["watchPropErrorMessage"],
223
+ "value": ["watchPropValue"]
224
+ }; }
225
+ static get style() { return searchModalCss; }
226
+ }, [2, "search-modal", {
227
+ "application": [16],
228
+ "listItens": [1040],
229
+ "opened": [1540],
230
+ "value": [1],
231
+ "canShowError": [4, "can-show-error"],
232
+ "emptyMessage": [1, "empty-message"],
233
+ "debounceTime": [2, "debounce-time"],
234
+ "maxItens": [2, "max-itens"],
235
+ "label": [1],
236
+ "mode": [1],
237
+ "restrict": [1],
238
+ "errorMessage": [1, "error-message"],
239
+ "filteredItems": [32],
240
+ "searchFocus": [32],
241
+ "isLimited": [32],
242
+ "addNewItem": [64],
243
+ "clearInput": [64],
244
+ "closeModal": [64],
245
+ "openModal": [64],
246
+ "isInvalid": [64],
247
+ "setBlur": [64],
248
+ "setFocus": [64]
249
+ }]);
250
+ function defineCustomElement() {
251
+ if (typeof customElements === "undefined") {
252
+ return;
253
+ }
254
+ const components = ["search-modal"];
255
+ components.forEach(tagName => { switch (tagName) {
256
+ case "search-modal":
257
+ if (!customElements.get(tagName)) {
258
+ customElements.define(tagName, SearchModal);
259
+ }
260
+ break;
261
+ } });
262
+ }
263
+
264
+ export { SearchModal as S, defineCustomElement as d };
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface SnkDistinctSearch extends Components.SnkDistinctSearch, HTMLElement {}
4
+ export const SnkDistinctSearch: {
5
+ prototype: SnkDistinctSearch;
6
+ new (): SnkDistinctSearch;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;