wj-elements 0.1.136 → 0.1.137

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 (202) hide show
  1. package/dist/dark.css +223 -0
  2. package/dist/infinite-scroll.element-XVJukzjy.js +272 -0
  3. package/dist/infinite-scroll.element-XVJukzjy.js.map +1 -0
  4. package/dist/light.css +534 -0
  5. package/dist/list.element-Ce1vIm1O.js +50 -0
  6. package/dist/list.element-Ce1vIm1O.js.map +1 -0
  7. package/dist/localize.js +70 -0
  8. package/dist/localize.js.map +1 -0
  9. package/dist/popup.element-tyYxow0p.js +1623 -0
  10. package/dist/popup.element-tyYxow0p.js.map +1 -0
  11. package/dist/router-links-CJnOdbas.js +150 -0
  12. package/dist/router-links-CJnOdbas.js.map +1 -0
  13. package/dist/styles.css +849 -0
  14. package/dist/wje-accordion-item.js +113 -0
  15. package/dist/wje-accordion-item.js.map +1 -0
  16. package/dist/wje-accordion.js +122 -0
  17. package/dist/wje-accordion.js.map +1 -0
  18. package/dist/wje-animation.js +4326 -0
  19. package/dist/wje-animation.js.map +1 -0
  20. package/dist/wje-aside.js +55 -0
  21. package/dist/wje-aside.js.map +1 -0
  22. package/dist/wje-avatar.js +90 -0
  23. package/dist/wje-avatar.js.map +1 -0
  24. package/dist/wje-badge.js +71 -0
  25. package/dist/wje-badge.js.map +1 -0
  26. package/dist/wje-breadcrumb.js +195 -0
  27. package/dist/wje-breadcrumb.js.map +1 -0
  28. package/dist/wje-breadcrumbs.js +140 -0
  29. package/dist/wje-breadcrumbs.js.map +1 -0
  30. package/dist/wje-button-group.js +85 -0
  31. package/dist/wje-button-group.js.map +1 -0
  32. package/dist/wje-button.js +352 -0
  33. package/dist/wje-button.js.map +1 -0
  34. package/dist/wje-card-content.js +48 -0
  35. package/dist/wje-card-content.js.map +1 -0
  36. package/dist/wje-card-controls.js +48 -0
  37. package/dist/wje-card-controls.js.map +1 -0
  38. package/dist/wje-card-header.js +48 -0
  39. package/dist/wje-card-header.js.map +1 -0
  40. package/dist/wje-card-subtitle.js +55 -0
  41. package/dist/wje-card-subtitle.js.map +1 -0
  42. package/dist/wje-card-title.js +55 -0
  43. package/dist/wje-card-title.js.map +1 -0
  44. package/dist/wje-card.js +56 -0
  45. package/dist/wje-card.js.map +1 -0
  46. package/dist/wje-carousel-item.js +63 -0
  47. package/dist/wje-carousel-item.js.map +1 -0
  48. package/dist/wje-carousel.js +380 -0
  49. package/dist/wje-carousel.js.map +1 -0
  50. package/dist/wje-checkbox.js +540 -0
  51. package/dist/wje-checkbox.js.map +1 -0
  52. package/dist/wje-chip.js +76 -0
  53. package/dist/wje-chip.js.map +1 -0
  54. package/dist/wje-col.js +38 -0
  55. package/dist/wje-col.js.map +1 -0
  56. package/dist/wje-color-picker.js +1339 -0
  57. package/dist/wje-color-picker.js.map +1 -0
  58. package/dist/wje-container.js +56 -0
  59. package/dist/wje-container.js.map +1 -0
  60. package/dist/wje-copy-button.js +218 -0
  61. package/dist/wje-copy-button.js.map +1 -0
  62. package/dist/wje-dialog.js +249 -0
  63. package/dist/wje-dialog.js.map +1 -0
  64. package/dist/wje-divider.js +55 -0
  65. package/dist/wje-divider.js.map +1 -0
  66. package/dist/wje-dropdown.js +194 -0
  67. package/dist/wje-dropdown.js.map +1 -0
  68. package/dist/wje-element.js +967 -0
  69. package/dist/wje-element.js.map +1 -0
  70. package/dist/wje-fetchAndParseCSS.js +60 -0
  71. package/dist/wje-fetchAndParseCSS.js.map +1 -0
  72. package/dist/wje-file-upload-item.js +140 -0
  73. package/dist/wje-file-upload-item.js.map +1 -0
  74. package/dist/wje-file-upload.js +552 -0
  75. package/dist/wje-file-upload.js.map +1 -0
  76. package/dist/wje-footer.js +52 -0
  77. package/dist/wje-footer.js.map +1 -0
  78. package/dist/wje-form.js +53 -0
  79. package/dist/wje-form.js.map +1 -0
  80. package/dist/wje-format-digital.js +146 -0
  81. package/dist/wje-format-digital.js.map +1 -0
  82. package/dist/wje-grid.js +54 -0
  83. package/dist/wje-grid.js.map +1 -0
  84. package/dist/wje-header.js +56 -0
  85. package/dist/wje-header.js.map +1 -0
  86. package/dist/wje-icon-picker.js +349 -0
  87. package/dist/wje-icon-picker.js.map +1 -0
  88. package/dist/wje-icon.js +191 -0
  89. package/dist/wje-icon.js.map +1 -0
  90. package/dist/wje-img-comparer.js +131 -0
  91. package/dist/wje-img-comparer.js.map +1 -0
  92. package/dist/wje-img.js +80 -0
  93. package/dist/wje-img.js.map +1 -0
  94. package/dist/wje-infinite-scroll.js +6 -0
  95. package/dist/wje-infinite-scroll.js.map +1 -0
  96. package/dist/wje-input-file.js +111 -0
  97. package/dist/wje-input-file.js.map +1 -0
  98. package/dist/wje-input.js +452 -0
  99. package/dist/wje-input.js.map +1 -0
  100. package/dist/wje-item.js +88 -0
  101. package/dist/wje-item.js.map +1 -0
  102. package/dist/wje-kanban.js +462 -0
  103. package/dist/wje-kanban.js.map +1 -0
  104. package/dist/wje-label.js +53 -0
  105. package/dist/wje-label.js.map +1 -0
  106. package/dist/wje-list.js +6 -0
  107. package/dist/wje-list.js.map +1 -0
  108. package/dist/wje-main.js +52 -0
  109. package/dist/wje-main.js.map +1 -0
  110. package/dist/wje-masonry.js +267 -0
  111. package/dist/wje-masonry.js.map +1 -0
  112. package/dist/wje-master.js +687 -0
  113. package/dist/wje-master.js.map +1 -0
  114. package/dist/wje-menu-button.js +60 -0
  115. package/dist/wje-menu-button.js.map +1 -0
  116. package/dist/wje-menu-item.js +545 -0
  117. package/dist/wje-menu-item.js.map +1 -0
  118. package/dist/wje-menu-label.js +55 -0
  119. package/dist/wje-menu-label.js.map +1 -0
  120. package/dist/wje-menu.js +72 -0
  121. package/dist/wje-menu.js.map +1 -0
  122. package/dist/wje-option.js +112 -0
  123. package/dist/wje-option.js.map +1 -0
  124. package/dist/wje-options.js +355 -0
  125. package/dist/wje-options.js.map +1 -0
  126. package/dist/wje-orgchart-group.js +72 -0
  127. package/dist/wje-orgchart-group.js.map +1 -0
  128. package/dist/wje-orgchart-item.js +98 -0
  129. package/dist/wje-orgchart-item.js.map +1 -0
  130. package/dist/wje-orgchart.js +49 -0
  131. package/dist/wje-orgchart.js.map +1 -0
  132. package/dist/wje-popup.js +6 -0
  133. package/dist/wje-popup.js.map +1 -0
  134. package/dist/wje-progress-bar.js +213 -0
  135. package/dist/wje-progress-bar.js.map +1 -0
  136. package/dist/wje-qr-code.js +2892 -0
  137. package/dist/wje-qr-code.js.map +1 -0
  138. package/dist/wje-radio-group.js +228 -0
  139. package/dist/wje-radio-group.js.map +1 -0
  140. package/dist/wje-radio.js +106 -0
  141. package/dist/wje-radio.js.map +1 -0
  142. package/dist/wje-rate.js +300 -0
  143. package/dist/wje-rate.js.map +1 -0
  144. package/dist/wje-relative-time.js +115 -0
  145. package/dist/wje-relative-time.js.map +1 -0
  146. package/dist/wje-reorder-dropzone.js +49 -0
  147. package/dist/wje-reorder-dropzone.js.map +1 -0
  148. package/dist/wje-reorder-handle.js +218 -0
  149. package/dist/wje-reorder-handle.js.map +1 -0
  150. package/dist/wje-reorder-item.js +61 -0
  151. package/dist/wje-reorder-item.js.map +1 -0
  152. package/dist/wje-reorder.js +281 -0
  153. package/dist/wje-reorder.js.map +1 -0
  154. package/dist/wje-route.js +43 -0
  155. package/dist/wje-route.js.map +1 -0
  156. package/dist/wje-router-link.js +64 -0
  157. package/dist/wje-router-link.js.map +1 -0
  158. package/dist/wje-router-outlet.js +192 -0
  159. package/dist/wje-router-outlet.js.map +1 -0
  160. package/dist/wje-routerx.js +1437 -0
  161. package/dist/wje-routerx.js.map +1 -0
  162. package/dist/wje-row.js +49 -0
  163. package/dist/wje-row.js.map +1 -0
  164. package/dist/wje-select.js +630 -0
  165. package/dist/wje-select.js.map +1 -0
  166. package/dist/wje-slider.js +221 -0
  167. package/dist/wje-slider.js.map +1 -0
  168. package/dist/wje-sliding-container.js +474 -0
  169. package/dist/wje-sliding-container.js.map +1 -0
  170. package/dist/wje-split-view.js +153 -0
  171. package/dist/wje-split-view.js.map +1 -0
  172. package/dist/wje-status.js +61 -0
  173. package/dist/wje-status.js.map +1 -0
  174. package/dist/wje-step.js +50 -0
  175. package/dist/wje-step.js.map +1 -0
  176. package/dist/wje-stepper.js +231 -0
  177. package/dist/wje-stepper.js.map +1 -0
  178. package/dist/wje-store.js +401 -0
  179. package/dist/wje-store.js.map +1 -0
  180. package/dist/wje-tab-group.js +137 -0
  181. package/dist/wje-tab-group.js.map +1 -0
  182. package/dist/wje-tab-panel.js +46 -0
  183. package/dist/wje-tab-panel.js.map +1 -0
  184. package/dist/wje-tab.js +59 -0
  185. package/dist/wje-tab.js.map +1 -0
  186. package/dist/wje-textarea.js +373 -0
  187. package/dist/wje-textarea.js.map +1 -0
  188. package/dist/wje-thumbnail.js +54 -0
  189. package/dist/wje-thumbnail.js.map +1 -0
  190. package/dist/wje-toast.js +334 -0
  191. package/dist/wje-toast.js.map +1 -0
  192. package/dist/wje-toggle.js +125 -0
  193. package/dist/wje-toggle.js.map +1 -0
  194. package/dist/wje-toolbar-action.js +72 -0
  195. package/dist/wje-toolbar-action.js.map +1 -0
  196. package/dist/wje-toolbar.js +63 -0
  197. package/dist/wje-toolbar.js.map +1 -0
  198. package/dist/wje-tooltip.js +166 -0
  199. package/dist/wje-tooltip.js.map +1 -0
  200. package/dist/wje-visually-hidden.js +55 -0
  201. package/dist/wje-visually-hidden.js.map +1 -0
  202. package/package.json +1 -1
@@ -0,0 +1,630 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import WJElement, { event } from "./wje-element.js";
5
+ import Button from "./wje-button.js";
6
+ import "./wje-popup.js";
7
+ import Icon from "./wje-icon.js";
8
+ import Label from "./wje-label.js";
9
+ import Chip from "./wje-chip.js";
10
+ import Input from "./wje-input.js";
11
+ import Option from "./wje-option.js";
12
+ import Options from "./wje-options.js";
13
+ import { P as Popup } from "./popup.element-tyYxow0p.js";
14
+ const styles = "/*\n[ WJ Select ]\n*/\n\n:host {\n --wje-select-border-width: 1px;\n --wje-select-border-style: solid;\n --wje-select-border-color: var(--wje-border-color);\n\n --wje-select-options-border-width: 1px;\n --wje-select-options-border-style: var(--wje-border-style);\n --wje-select-options-border-color: var(--wje-border-color);\n\n --wje-select-background: var(--wje-background);\n --wje-select-line-height: 20px;\n --wje-select-color: var(--wje-color);\n --wje-select-border-radius: var(--wje-border-radius-medium);\n\n --wje-select-margin-bottom: 0.5rem;\n margin-bottom: var(--wje-select-margin-bottom);\n\n width: 100%;\n display: block;\n [slot='arrow'] {\n transform: rotate(0deg);\n transition: all 0.2s ease-in;\n }\n}\n\n.native-select {\n &.default {\n .wrapper {\n display: block;\n border-width: var(--wje-select-border-width);\n border-style: var(--wje-select-border-style);\n border-color: var(--wje-select-border-color);\n border-radius: var(--wje-select-border-radius);\n padding-inline: 0.5rem;\n padding-top: 0.125rem;\n padding-bottom: 0.125rem;\n }\n .input-wrapper {\n padding: 0;\n min-height: 28px;\n margin-top: -4px;\n }\n &.focused {\n wje-label {\n opacity: 0.67;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n wje-label {\n margin: 0;\n display: block;\n opacity: 1;\n cursor: text;\n transition: opacity 0.2s ease 0s;\n line-height: var(--wje-select-line-height);\n &.fade {\n opacity: 0.5;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n }\n &.standard {\n .wrapper {\n background-color: var(--wje-select-background);\n border-width: var(--wje-select-border-width);\n border-style: var(--wje-select-border-style);\n border-color: var(--wje-select-border-color);\n border-radius: var(--wje-select-border-radius);\n }\n .input-wrapper {\n background: transparent;\n width: 100%;\n }\n }\n}\n\n.wrapper {\n display: flex;\n width: 100%;\n}\n\n.input-wrapper {\n display: grid;\n grid-template-columns: auto 1fr auto auto auto;\n align-items: center;\n background-color: var(--wje-select-background);\n min-height: 28px;\n color: var(--wje-select-color);\n line-height: var(--wje-select-line-height);\n appearance: none;\n padding: 2px 0.5rem;\n font-size: 14px !important;\n font-weight: normal;\n vertical-align: middle;\n}\n\ninput {\n color: var(--wje-select-color);\n line-height: var(--wje-select-line-height);\n font-size: 14px !important;\n font-weight: 400;\n letter-spacing: 0.01em;\n border: medium;\n height: 25px;\n min-height: 25px;\n padding: 0;\n background: none;\n box-shadow: none;\n width: 100%;\n outline: 0;\n font-size: 14px !important;\n}\n\n::placeholder {\n opacity: 1;\n}\n\n:host [active] {\n .wrapper {\n border-radius: var(--wje-select-border-radius) var(--wje-select-border-radius) 0 0;\n }\n [slot='arrow'] {\n transform: rotate(180deg);\n transition: all 0.2s ease-in;\n }\n}\n\n.options-wrapper {\n border-width: var(--wje-select-options-border-width);\n border-style: var(--wje-select-options-border-style);\n border-color: var(--wje-select-options-border-color);\n border-radius: 0 0 var(--wje-select-border-radius) var(--wje-select-border-radius);\n margin-top: calc(0px - var(--wje-select-border-width));\n background: var(--wje-select-background);\n overflow: hidden;\n}\n\n.find {\n --wje-input-border-radius: 0;\n --wje-input-border-width: 0 0 1px 0;\n}\n\n.list {\n overflow: auto;\n height: 100%;\n}\n\n.options-wrapper:has(.find) .list {\n height: calc(100% - 32px - 0.5rem);\n}\n\n:host([multiple]) input {\n position: absolute;\n z-index: -1;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n opacity: 0;\n}\n\n:host([multiple]) .chips {\n display: flex;\n flex: 1;\n align-items: center;\n flex-wrap: wrap;\n}\n\n:host([disabled]) .input-wrapper {\n opacity: 0.5;\n pointer-events: none;\n cursor: not-allowed;\n}\n\n.counter {\n padding-inline: 0.5rem;\n}\n\nwje-chip {\n --wje-chip-margin: 0 0.25rem 0 0;\n}\n\nwje-button {\n --wje-padding-top: 0.25rem;\n --wje-padding-start: 0.25rem;\n --wje-padding-end: 0.25rem;\n --wje-padding-bottom: 0.25rem;\n --wje-button-margin-inline: 0 0.25rem;\n}\n\n.slot-start,\n.slot-end {\n &:not(:empty) {\n margin-right: 0.5rem;\n }\n}\n";
15
+ class Select extends WJElement {
16
+ /**
17
+ * Creates an instance of Select.
18
+ */
19
+ constructor() {
20
+ super();
21
+ __publicField(this, "dependencies", {
22
+ "wje-button": Button,
23
+ "wje-popup": Popup,
24
+ "wje-icon": Icon,
25
+ "wje-label": Label,
26
+ "wje-chip": Chip,
27
+ "wje-input": Input,
28
+ "wje-option": Option,
29
+ "wje-options": Options
30
+ });
31
+ __publicField(this, "className", "Select");
32
+ /**
33
+ * Handles the option change event.
34
+ * @param {Event} e The event.
35
+ */
36
+ __publicField(this, "optionChange", (e) => {
37
+ let allOptions = this.getAllOptions();
38
+ if (!this.hasAttribute("multiple")) {
39
+ allOptions.forEach((option) => {
40
+ option.selected = false;
41
+ option.removeAttribute("selected");
42
+ });
43
+ this.popup.removeAttribute("active");
44
+ }
45
+ e.target.selected = !e.target.hasAttribute("selected");
46
+ this.selections();
47
+ });
48
+ /**
49
+ * Handles the chip remove event.
50
+ * @param {Event} e The event.
51
+ */
52
+ __publicField(this, "removeChip", (e) => {
53
+ let option = e.target.option;
54
+ option.selected = false;
55
+ option.removeAttribute("selected");
56
+ e.target.parentNode.removeChild(e.target);
57
+ this.selections();
58
+ });
59
+ this._selected = [];
60
+ this.counterEl = null;
61
+ this.internals = this.attachInternals();
62
+ }
63
+ /**
64
+ * Setter for the value attribute.
65
+ * @param {string} value The value to set.
66
+ */
67
+ set value(value) {
68
+ if (Array.isArray(value)) {
69
+ this.internals.setFormValue(JSON.stringify(value));
70
+ } else {
71
+ this.internals.setFormValue(value);
72
+ }
73
+ }
74
+ /**
75
+ * Getter for the value attribute.
76
+ * @returns {string} The value of the attribute.
77
+ */
78
+ get value() {
79
+ return this.selected;
80
+ }
81
+ /**
82
+ * Getter for the customErrorDisplay attribute.
83
+ * @returns {boolean} Whether the attribute is present.
84
+ */
85
+ get customErrorDisplay() {
86
+ return this.hasAttribute("custom-error-display");
87
+ }
88
+ /**
89
+ * Getter for the validateOnChange attribute.
90
+ * @returns {boolean} Whether the attribute is present.
91
+ */
92
+ get validateOnChange() {
93
+ return this.hasAttribute("validate-on-change");
94
+ }
95
+ /**
96
+ * Getter for the invalid attribute.
97
+ * @returns {boolean} Whether the attribute is present.
98
+ */
99
+ get invalid() {
100
+ return this.hasAttribute("invalid");
101
+ }
102
+ /**
103
+ * Setter for the invalid attribute.
104
+ * @param {boolean} isInvalid Whether the input is invalid.
105
+ */
106
+ set invalid(isInvalid) {
107
+ if (isInvalid) this.setAttribute("invalid", "");
108
+ else this.removeAttribute("invalid");
109
+ }
110
+ /**
111
+ * Getter for the form attribute.
112
+ * @returns {HTMLFormElement} The form the input is associated with.
113
+ */
114
+ get form() {
115
+ return this.internals.form;
116
+ }
117
+ /**
118
+ * Getter for the name attribute.
119
+ * @returns {string} The name of the input.
120
+ */
121
+ get name() {
122
+ return this.getAttribute("name");
123
+ }
124
+ /**
125
+ * Getter for the type attribute.
126
+ * @returns {string} The type of the input.
127
+ */
128
+ get type() {
129
+ return this.localName;
130
+ }
131
+ /**
132
+ * Getter for the validity attribute.
133
+ * @returns {ValidityState} The validity state of the input.
134
+ */
135
+ get validity() {
136
+ return this.internals.validity;
137
+ }
138
+ /**
139
+ * Getter for the validationMessage attribute.
140
+ * @returns {string} The validation message of the input.
141
+ */
142
+ get validationMessage() {
143
+ return this.internals.validationMessage;
144
+ }
145
+ /**
146
+ * Getter for the willValidate attribute.
147
+ * @returns {boolean} Whether the input will be validated.
148
+ */
149
+ get willValidate() {
150
+ return this.internals.willValidate;
151
+ }
152
+ /**
153
+ * @summary Getter for the defaultValue attribute.
154
+ * This method retrieves the 'value' attribute of the custom input element.
155
+ * The 'value' attribute represents the default value of the input element.
156
+ * If the 'value' attribute is not set, it returns an empty string.
157
+ * @returns {string} The default value of the input element.
158
+ */
159
+ get defaultValue() {
160
+ return this.getAttribute("value") ?? "";
161
+ }
162
+ /**
163
+ * @summary Setter for the defaultValue attribute.
164
+ * This method sets the 'value' attribute of the custom input element to the provided value.
165
+ * The 'value' attribute represents the default value of the input element.
166
+ * @param {string} value The value to set as the default value.
167
+ */
168
+ set defaultValue(value) {
169
+ this.setAttribute("value", value);
170
+ }
171
+ /**
172
+ * Sets the label value.
173
+ * @param {Array} value The selected value to set.
174
+ */
175
+ set selected(value) {
176
+ this._selected = value;
177
+ }
178
+ /**
179
+ * Returns the selected value.
180
+ * @returns {Array} The selected value.
181
+ */
182
+ get selected() {
183
+ return this.getSelected();
184
+ }
185
+ /**
186
+ * Sets the trigger value.
187
+ * @param {string} value The trigger value to set.
188
+ */
189
+ set trigger(value) {
190
+ this.setAttribute("trigger", value);
191
+ }
192
+ /**
193
+ * Returns the trigger value.
194
+ * @returns {string} The trigger value.
195
+ */
196
+ get trigger() {
197
+ return this.getAttribute("trigger") || "click";
198
+ }
199
+ /**
200
+ * Returns the CSS styles for the component.
201
+ * @static
202
+ * @returns {CSSStyleSheet}
203
+ */
204
+ static get cssStyleSheet() {
205
+ return styles;
206
+ }
207
+ /**
208
+ * Returns the list of attributes to observe for changes.
209
+ * @static
210
+ * @returns {Array<string>}
211
+ */
212
+ static get observedAttributes() {
213
+ return ["active", "value"];
214
+ }
215
+ /**
216
+ * Sets up the attributes for the component.
217
+ */
218
+ setupAttributes() {
219
+ this.isShadowRoot = "open";
220
+ }
221
+ /**
222
+ * Draws the component for the select.
223
+ * @returns {DocumentFragment}
224
+ */
225
+ draw() {
226
+ let fragment = document.createDocumentFragment();
227
+ this.classList.add("wje-placement", this.placement ? "wje-" + this.placement : "wje-start");
228
+ let native = document.createElement("div");
229
+ native.setAttribute("part", "native");
230
+ native.classList.add("native-select", this.variant || "default");
231
+ let wrapper = document.createElement("div");
232
+ wrapper.classList.add("wrapper");
233
+ wrapper.setAttribute("slot", "anchor");
234
+ let label = document.createElement("wje-label");
235
+ label.innerText = this.label || "";
236
+ let inputWrapper = document.createElement("div");
237
+ inputWrapper.setAttribute("part", "input-wrapper");
238
+ inputWrapper.classList.add("input-wrapper");
239
+ let slotStart = document.createElement("div");
240
+ slotStart.classList.add("slot-start");
241
+ let input = document.createElement("input");
242
+ input.setAttribute("type", "text");
243
+ input.setAttribute("part", "input");
244
+ input.setAttribute("autocomplete", "off");
245
+ input.setAttribute("readonly", "");
246
+ input.setAttribute("placeholder", this.placeholder || "");
247
+ let slotEnd = document.createElement("div");
248
+ slotEnd.classList.add("slot-end");
249
+ let arrow = document.createElement("wje-icon");
250
+ arrow.setAttribute("name", "chevron-down");
251
+ arrow.setAttribute("slot", "arrow");
252
+ let chips = document.createElement("div");
253
+ chips.classList.add("chips");
254
+ chips.innerText = this.placeholder || "";
255
+ let optionsWrapper = document.createElement("div");
256
+ optionsWrapper.setAttribute("part", "options-wrapper");
257
+ optionsWrapper.classList.add("options-wrapper");
258
+ optionsWrapper.style.setProperty("height", this.maxHeight || "auto");
259
+ let list = document.createElement("div");
260
+ list.classList.add("list");
261
+ let slot = document.createElement("slot");
262
+ let clear = document.createElement("wje-button");
263
+ clear.setAttribute("fill", "link");
264
+ clear.setAttribute("part", "clear");
265
+ let clearIcon = document.createElement("wje-icon");
266
+ clearIcon.setAttribute("name", "x");
267
+ clear.appendChild(clearIcon);
268
+ let popup = document.createElement("wje-popup");
269
+ popup.setAttribute("placement", "bottom-start");
270
+ popup.setAttribute("manual", "");
271
+ popup.setAttribute("size", "");
272
+ if (this.hasAttribute("disabled")) popup.setAttribute("disabled", "");
273
+ if (this.variant === "standard") {
274
+ if (this.hasAttribute("label")) native.appendChild(label);
275
+ } else {
276
+ wrapper.appendChild(label);
277
+ }
278
+ inputWrapper.appendChild(slotStart);
279
+ inputWrapper.appendChild(input);
280
+ if (this.hasAttribute("multiple")) inputWrapper.appendChild(chips);
281
+ if (this.hasAttribute("clearable")) inputWrapper.appendChild(clear);
282
+ inputWrapper.appendChild(slotEnd);
283
+ inputWrapper.appendChild(arrow);
284
+ list.appendChild(slot);
285
+ if (this.hasAttribute("find")) {
286
+ let find = document.createElement("wje-input");
287
+ find.setAttribute("variant", "standard");
288
+ find.setAttribute("placeholder", "Hľadať");
289
+ find.classList.add("find");
290
+ optionsWrapper.appendChild(find);
291
+ this.findEl = find;
292
+ }
293
+ optionsWrapper.appendChild(list);
294
+ wrapper.appendChild(inputWrapper);
295
+ popup.appendChild(wrapper);
296
+ popup.appendChild(optionsWrapper);
297
+ if (this.trigger === "click") popup.setAttribute("manual", "");
298
+ native.appendChild(popup);
299
+ this.native = native;
300
+ this.popup = popup;
301
+ this.labelElement = label;
302
+ this.slotStart = slotStart;
303
+ this.slotEnd = slotEnd;
304
+ this.input = input;
305
+ this.optionsWrapper = optionsWrapper;
306
+ this.chips = chips;
307
+ this.clear = clear;
308
+ this.list = list;
309
+ fragment.appendChild(native);
310
+ return fragment;
311
+ }
312
+ /**
313
+ * Sets up the event listeners after the component is drawn.
314
+ */
315
+ afterDraw() {
316
+ this.input.addEventListener("focus", (e) => {
317
+ this.labelElement.classList.add("fade");
318
+ this.native.classList.add("focused");
319
+ });
320
+ this.input.addEventListener("blur", (e) => {
321
+ this.native.classList.remove("focused");
322
+ if (!e.target.value) this.labelElement.classList.remove("fade");
323
+ });
324
+ this.addEventListener("wje-option:change", this.optionChange);
325
+ this.clear.addEventListener("wje-button:click", (e) => {
326
+ this.getAllOptions().forEach((option) => {
327
+ option.selected = false;
328
+ option.removeAttribute("selected");
329
+ });
330
+ this.selections();
331
+ e.stopPropagation();
332
+ });
333
+ this.selections(true);
334
+ this.list.addEventListener("wje-options:load", (e) => {
335
+ this.list.scrollTo(0, 0);
336
+ });
337
+ if (this.hasAttribute("find") && this.findEl instanceof HTMLElement) {
338
+ event.addListener(this.findEl, "keyup", "", (e) => {
339
+ const optionsElement = this.querySelector("wje-options");
340
+ if (optionsElement && optionsElement.hasAttribute("lazy")) {
341
+ optionsElement.setAttribute("search", e.target.value);
342
+ } else {
343
+ let value = e.target.value.trim().toLowerCase();
344
+ this.getAllOptions().forEach((option) => {
345
+ if (option.textContent.trim().toLowerCase().includes(value)) option.style.display = "block";
346
+ else option.style.display = "none";
347
+ });
348
+ }
349
+ });
350
+ }
351
+ }
352
+ /**
353
+ * Returns all the options as HTML.
354
+ * @returns {NodeList} The options as HTML.
355
+ */
356
+ getAllOptions() {
357
+ return this.querySelectorAll("wje-option");
358
+ }
359
+ /**
360
+ * Returns the selected options as HTML.
361
+ * @returns {NodeList} The selected options as HTML.
362
+ */
363
+ getSelectedOptions() {
364
+ return this.querySelectorAll("wje-option[selected]");
365
+ }
366
+ /**
367
+ * Returns the selected options.
368
+ * @returns {Array} The selected options.
369
+ */
370
+ getSelected() {
371
+ let selectedOptions = this.getSelectedOptions();
372
+ selectedOptions = Array.isArray(selectedOptions) ? selectedOptions : Array.from(selectedOptions);
373
+ selectedOptions = selectedOptions.map((option) => {
374
+ return {
375
+ value: option.value,
376
+ text: option.textContent.trim()
377
+ };
378
+ });
379
+ return selectedOptions;
380
+ }
381
+ /**
382
+ * Handles the selection change.
383
+ * @param {Element} option The option that changed.
384
+ * @param {number} length The length of the selected options.
385
+ */
386
+ selectionChanged(option = null, length = 0) {
387
+ var _a, _b;
388
+ if (this.hasAttribute("multiple")) {
389
+ this.value = this.selectedOptions.map((el) => el.value).reverse();
390
+ if (this.placeholder && length === 0) {
391
+ this.chips.innerHTML = this.placeholder;
392
+ this.input.value = "";
393
+ } else {
394
+ if (this.counterEl instanceof HTMLElement || length > +this.maxOptions) {
395
+ this.counter();
396
+ } else {
397
+ if (option !== null) this.chips.appendChild(this.getChip(option));
398
+ }
399
+ }
400
+ } else {
401
+ let value = (option == null ? void 0 : option.textContent.trim()) || "";
402
+ this.value = (_b = (_a = this.selectedOptions) == null ? void 0 : _a.map((el) => el.value)) == null ? void 0 : _b.at(0);
403
+ this.input.value = value;
404
+ if (option && option instanceof HTMLElement) {
405
+ this.slotStart.innerHTML = "";
406
+ if (option == null ? void 0 : option.querySelector("[slot=start]")) {
407
+ this.slotStart.appendChild(option == null ? void 0 : option.querySelector("[slot=start]").cloneNode(true));
408
+ }
409
+ this.slotEnd.innerHTML = "";
410
+ if (option == null ? void 0 : option.querySelector("[slot=end]")) {
411
+ this.slotEnd.appendChild(option == null ? void 0 : option.querySelector("[slot=end]").cloneNode(true));
412
+ }
413
+ }
414
+ }
415
+ }
416
+ /**
417
+ * Updates the selected options and their corresponding chips.
418
+ * @param {boolean} [silence] Determines whether to suppress the "wje-select:change" event.
419
+ * @returns {void}
420
+ * @description
421
+ * This method fetches the currently selected options and updates the `selectedOptions` array.
422
+ * It clears and rebuilds the chips representing the selected items in the UI.
423
+ * If the number of selected options reaches the maximum allowed (`maxOptions`), it stops updating the counter.
424
+ * Optionally, it dispatches a custom event when the selection changes unless `silence` is set to `true`.
425
+ * //@fires wje-select:change - Dispatched when the selection changes, unless `silence` is `true`.
426
+ * @example
427
+ * // Call the method and allow event dispatch
428
+ * selections();
429
+ * @example
430
+ * // Call the method without dispatching the event
431
+ * selections(true);
432
+ */
433
+ selections(silence = false) {
434
+ let options = this.getSelectedOptions();
435
+ this.selectedOptions = Array.isArray(options) ? options : Array.from(options);
436
+ if (this.selectedOptions.length >= +this.maxOptions) {
437
+ this.counterEl = null;
438
+ }
439
+ if (this.chips) {
440
+ this.chips.innerHTML = "";
441
+ }
442
+ if (this.selectedOptions.length > 0) {
443
+ this.selectedOptions.forEach((option, index) => {
444
+ this.selectionChanged(option, ++index);
445
+ });
446
+ } else {
447
+ this.selectionChanged();
448
+ }
449
+ if (silence) return;
450
+ event.dispatchCustomEvent(this, "wje-select:change");
451
+ }
452
+ /**
453
+ * Manages the display of a counter element to indicate the number of items exceeding the maximum allowed options.
454
+ * - If the number of selected items equals the maximum allowed, the counter element is removed.
455
+ * - If the counter element doesn't exist and the number of items exceeds the maximum, it is created and updated.
456
+ */
457
+ counter() {
458
+ if (this.counterEl && this.value.length === +this.maxOptions) {
459
+ this.counterEl.remove();
460
+ this.counterEl = null;
461
+ return;
462
+ }
463
+ if (!this.counterEl) {
464
+ this.counterEl = document.createElement("span");
465
+ this.counterEl.classList.add("counter");
466
+ this.chips.appendChild(this.counterEl);
467
+ }
468
+ this.counterEl.innerText = `+${this.value.length - +this.maxOptions}`;
469
+ }
470
+ /**
471
+ * Returns a chip element.
472
+ * @param {Element} option The option to get the chip for.
473
+ * @returns {Element} The chip element.
474
+ */
475
+ getChip(option) {
476
+ let chip = document.createElement("wje-chip");
477
+ chip.setAttribute("removable", "");
478
+ chip.addEventListener("wje:chip-remove", this.removeChip);
479
+ chip.option = option;
480
+ let label = document.createElement("wje-label");
481
+ label.innerText = option.textContent.trim();
482
+ chip.appendChild(label);
483
+ return chip;
484
+ }
485
+ /**
486
+ * Generates an HTML option element based on the provided item and mapping.
487
+ * @param {object} item The item to generate the option for.
488
+ * @param {object} [map] The mapping object that specifies the properties of the item to use for the option's value and text.
489
+ * @param {string} [map.value] The property of the item to use for the option's value.
490
+ * @param {string} [map.text] The property of the item to use for the option's text.
491
+ * @returns {HTMLElement} The generated HTML option element.
492
+ */
493
+ htmlOption(item, map = { value: "value", text: "text" }) {
494
+ let option = document.createElement("wje-option");
495
+ if (item[map.value] === null) {
496
+ console.warn(`The item ${JSON.stringify(item)} does not have the property ${map.value}`);
497
+ }
498
+ if (item[map.text] === null) {
499
+ console.warn(`The item ${JSON.stringify(item)} does not have the property ${map.text}`);
500
+ }
501
+ option.setAttribute("value", item[map.value] ?? "");
502
+ option.innerText = item[map.text] ?? "";
503
+ return option;
504
+ }
505
+ /**
506
+ * Adds an option to the select element.
507
+ * @param {any} optionData The data for the option to be added.
508
+ * @param {boolean} [silent] Whether to suppress any events triggered by the addition of the option.
509
+ * @param {object} [map] The mapping object specifying the properties of the option data to be used for the value and text of the option.
510
+ */
511
+ addOption(optionData, silent = false, map = { value: "value", text: "text" }) {
512
+ if (!optionData) return;
513
+ const optionsElement = this.querySelector("wje-options");
514
+ if (optionsElement) {
515
+ optionsElement.addOption(optionData, silent, map);
516
+ return;
517
+ }
518
+ let option = this.htmlOption(optionData, map);
519
+ this.appendChild(option);
520
+ }
521
+ /**
522
+ * Adds options to the select element.
523
+ * @param {Array | object} optionsData The options data to be added. Can be an array of objects or a single object.
524
+ * @param {boolean} [silent] Indicates whether to trigger events when adding options. Default is false.
525
+ * @param {object} [map] The mapping object that specifies the properties of the options data object. Default is { value: "value", text: "text" }.
526
+ */
527
+ addOptions(optionsData, silent = false, map = { value: "value", text: "text" }) {
528
+ if (!Array.isArray(optionsData)) {
529
+ this.addOption(optionsData, silent, map);
530
+ } else {
531
+ const optionsElement = this.querySelector("wje-options");
532
+ if (optionsElement) {
533
+ optionsElement.addOptions(optionsData, silent, map);
534
+ return;
535
+ }
536
+ optionsData.forEach((item) => {
537
+ this.addOption(item, silent, map);
538
+ });
539
+ }
540
+ }
541
+ /**
542
+ * Selects an option with the specified value.
543
+ * @param {string} value The value of the option to be selected.
544
+ * @param {boolean} [silent] Whether to suppress firing events.
545
+ */
546
+ selectOption(value, silent = false) {
547
+ if (!value) return;
548
+ let option = this.querySelector(`wje-option[value="${value}"]`);
549
+ if (option) {
550
+ option.selected = true;
551
+ }
552
+ if (this.drawingStatus > this.drawingStatuses.START) this.selections(silent);
553
+ }
554
+ /**
555
+ * Selects one or multiple options in the select element.
556
+ * @param {Array|any} values The value(s) of the option(s) to be selected.
557
+ * @param {boolean} [silent] Whether to trigger the change event or not.
558
+ */
559
+ selectOptions(values, silent = false) {
560
+ if (!Array.isArray(values)) {
561
+ this.selectOption(values, silent);
562
+ } else {
563
+ values.forEach((value) => {
564
+ this.selectOption(value, silent);
565
+ });
566
+ }
567
+ }
568
+ /**
569
+ * @summary Callback function that is called when the custom element is associated with a form.
570
+ * This function adds an event listener to the form's submit event, which validates the input and propagates the validation.
571
+ * @param {HTMLFormElement} form The form the custom element is associated with.
572
+ */
573
+ formAssociatedCallback(form) {
574
+ form == null ? void 0 : form.addEventListener("submit", () => {
575
+ });
576
+ }
577
+ /**
578
+ * The formResetCallback method is a built-in lifecycle callback that gets called when a form gets reset.
579
+ * This method is responsible for resetting the value of the custom input element to its default value.
580
+ * It also resets the form value and validity state in the form internals.
581
+ * @function
582
+ */
583
+ formResetCallback() {
584
+ this.value = this.defaultValue;
585
+ this.internals.setFormValue(this.defaultValue);
586
+ this.internals.setValidity({});
587
+ }
588
+ /**
589
+ * The formStateRestoreCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is restored.
590
+ * This method is responsible for restoring the value of the custom input element to its saved state.
591
+ * It also restores the form value and validity state in the form internals to their saved states.
592
+ * @param {object} state The saved state of the custom input element.
593
+ * @function
594
+ */
595
+ formStateRestoreCallback(state) {
596
+ this.value = state.value;
597
+ this.internals.setFormValue(state.value);
598
+ this.internals.setValidity({});
599
+ }
600
+ /**
601
+ * The formStateSaveCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is saved.
602
+ * This method is responsible for saving the value of the custom input element.
603
+ * @returns {object} The saved state of the custom input element.
604
+ * @function
605
+ */
606
+ formStateSaveCallback() {
607
+ return {
608
+ value: this.value
609
+ };
610
+ }
611
+ /**
612
+ * The formDisabledCallback method is a built-in lifecycle callback that gets called when the disabled state of a form-associated custom element changes.
613
+ * This method is not implemented yet.
614
+ * @param {boolean} disabled The new disabled state of the custom input element.
615
+ * @function
616
+ */
617
+ formDisabledCallback(disabled) {
618
+ console.warn("formDisabledCallback not implemented yet");
619
+ }
620
+ }
621
+ /**
622
+ * Whether the input is associated with a form.
623
+ * @type {boolean}
624
+ */
625
+ __publicField(Select, "formAssociated", true);
626
+ Select.define("wje-select", Select);
627
+ export {
628
+ Select as default
629
+ };
630
+ //# sourceMappingURL=wje-select.js.map