@avakhula/ui 0.0.10

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 (194) hide show
  1. package/.babelrc.json +14 -0
  2. package/.eslintrc.cjs +15 -0
  3. package/.nvmrc +1 -0
  4. package/.prettierrc.json +1 -0
  5. package/.storybook/intelliboardTheme.js +10 -0
  6. package/.storybook/main.js +25 -0
  7. package/.storybook/manager.js +7 -0
  8. package/.storybook/preview-head.html +11 -0
  9. package/.storybook/preview.js +24 -0
  10. package/.storybook/scss-loader.scss +6 -0
  11. package/.storybook/withSource.js +97 -0
  12. package/README.md +35 -0
  13. package/dist/favicon.ico +0 -0
  14. package/dist/index.mjs +19366 -0
  15. package/dist/index.umd.js +209 -0
  16. package/dist/style.css +1 -0
  17. package/index.html +21 -0
  18. package/package.json +63 -0
  19. package/public/favicon.ico +0 -0
  20. package/src/App.vue +37 -0
  21. package/src/EventEmmiter.js +19 -0
  22. package/src/assets/scss/mixins/dropdown-list-item.scss +45 -0
  23. package/src/assets/scss/mixins/tooltip-position.scss +147 -0
  24. package/src/assets/scss/mixins.scss +21 -0
  25. package/src/assets/scss/reset.scss +12 -0
  26. package/src/assets/scss/style.scss +73 -0
  27. package/src/assets/scss/typography.scss +155 -0
  28. package/src/assets/scss/variables/colors.scss +115 -0
  29. package/src/assets/scss/variables/shadows.scss +17 -0
  30. package/src/components/Accordion/Accordion.scss +94 -0
  31. package/src/components/Accordion/Accordion.stories.js +41 -0
  32. package/src/components/Accordion/Accordion.vue +104 -0
  33. package/src/components/Accordion/readme.mdx +38 -0
  34. package/src/components/Alert/Alert.stories.js +69 -0
  35. package/src/components/Alert/Alert.vue +131 -0
  36. package/src/components/Alert/alert.scss +166 -0
  37. package/src/components/Alert/constants.js +6 -0
  38. package/src/components/Alert/readme.mdx +63 -0
  39. package/src/components/Badge/Badge.stories.js +53 -0
  40. package/src/components/Badge/Badge.vue +58 -0
  41. package/src/components/Badge/readme.mdx +38 -0
  42. package/src/components/Breadcrumbs/Breadcrumbs.vue +98 -0
  43. package/src/components/Breadcrumbs/breadcrumbs.scss +77 -0
  44. package/src/components/Breadcrumbs/breadcrumbs.stories.js +37 -0
  45. package/src/components/Button/Button.stories.js +124 -0
  46. package/src/components/Button/Button.vue +165 -0
  47. package/src/components/Button/button.scss +217 -0
  48. package/src/components/Button/constants.js +8 -0
  49. package/src/components/Button/readme.mdx +118 -0
  50. package/src/components/ButtonGroup/ButtonGroup.stories.js +27 -0
  51. package/src/components/ButtonGroup/ButtonGroup.vue +24 -0
  52. package/src/components/ButtonGroup/readme.mdx +10 -0
  53. package/src/components/Dropdown/Dropdown.spec.js +90 -0
  54. package/src/components/Dropdown/Dropdown.stories.js +48 -0
  55. package/src/components/Dropdown/Dropdown.vue +313 -0
  56. package/src/components/Dropdown/DropdownDivider.vue +15 -0
  57. package/src/components/Dropdown/DropdownItem.vue +59 -0
  58. package/src/components/Dropdown/DropdownList.stories.js +174 -0
  59. package/src/components/Dropdown/DropdownList.vue +93 -0
  60. package/src/components/Dropdown/constants.js +10 -0
  61. package/src/components/Dropdown/readme.mdx +88 -0
  62. package/src/components/Form/CharactersCount.vue +55 -0
  63. package/src/components/Form/Checkbox/Checkbox.scss +226 -0
  64. package/src/components/Form/Checkbox/Checkbox.stories.js +63 -0
  65. package/src/components/Form/Checkbox/Checkbox.vue +128 -0
  66. package/src/components/Form/Checkbox/readme.mdx +69 -0
  67. package/src/components/Form/CheckboxGroup/CheckboxGroup.stories.js +64 -0
  68. package/src/components/Form/CheckboxGroup/CheckboxGroup.vue +87 -0
  69. package/src/components/Form/CheckboxGroup/readme.mdx +56 -0
  70. package/src/components/Form/DatePicker/DatePicker.scss +479 -0
  71. package/src/components/Form/DatePicker/DatePicker.stories.js +78 -0
  72. package/src/components/Form/DatePicker/DatePicker.vue +284 -0
  73. package/src/components/Form/DatePicker/Icons/chevron-back.js +5 -0
  74. package/src/components/Form/DatePicker/Icons/chevron-forward.js +5 -0
  75. package/src/components/Form/DatePicker/readme.mdx +115 -0
  76. package/src/components/Form/FormGroup/FormGroup.stories.js +48 -0
  77. package/src/components/Form/FormGroup/FormGroup.vue +61 -0
  78. package/src/components/Form/FormGroup/FormGroupSet.stories.js +32 -0
  79. package/src/components/Form/FormGroup/FormGroupSet.vue +75 -0
  80. package/src/components/Form/Input/Input.stories.js +137 -0
  81. package/src/components/Form/Input/Input.vue +231 -0
  82. package/src/components/Form/Input/constants.js +5 -0
  83. package/src/components/Form/Input/input.scss +133 -0
  84. package/src/components/Form/Input/readme.mdx +68 -0
  85. package/src/components/Form/Label/Label.stories.js +29 -0
  86. package/src/components/Form/Label/Label.vue +87 -0
  87. package/src/components/Form/Label/readme.mdx +25 -0
  88. package/src/components/Form/PhoneInput/PhoneInput.stories.js +43 -0
  89. package/src/components/Form/PhoneInput/PhoneInput.vue +105 -0
  90. package/src/components/Form/PhoneInput/phoneInput.scss +197 -0
  91. package/src/components/Form/PhoneInput/readme.mdx +37 -0
  92. package/src/components/Form/Radio/Radio.stories.js +34 -0
  93. package/src/components/Form/Radio/Radio.vue +109 -0
  94. package/src/components/Form/Radio/radio.scss +187 -0
  95. package/src/components/Form/Radio/readme.mdx +48 -0
  96. package/src/components/Form/TextEditor/TextEditor.stories.js +58 -0
  97. package/src/components/Form/TextEditor/TextEditor.vue +305 -0
  98. package/src/components/Form/TextEditor/icons/svg/chevron-down.svg +3 -0
  99. package/src/components/Form/TextEditor/icons/toolbarIcons.js +111 -0
  100. package/src/components/Form/TextEditor/plugins/alphabetList.js +43 -0
  101. package/src/components/Form/TextEditor/readme.mdx +59 -0
  102. package/src/components/Form/TextEditor/textEditor.scss +684 -0
  103. package/src/components/Form/Textarea/Textarea.spec.js +107 -0
  104. package/src/components/Form/Textarea/Textarea.stories.js +68 -0
  105. package/src/components/Form/Textarea/Textarea.vue +102 -0
  106. package/src/components/Form/Textarea/readme.mdx +45 -0
  107. package/src/components/Form/Textarea/textarea.scss +84 -0
  108. package/src/components/Form/Toggle/Toggle.stories.js +44 -0
  109. package/src/components/Form/Toggle/Toggle.vue +122 -0
  110. package/src/components/Form/Toggle/readme.mdx +39 -0
  111. package/src/components/Form/Toggle/toggle.scss +166 -0
  112. package/src/components/Icon.vue +41 -0
  113. package/src/components/IconButton/IconButton.scss +91 -0
  114. package/src/components/IconButton/IconButton.stories.js +115 -0
  115. package/src/components/IconButton/IconButton.vue +100 -0
  116. package/src/components/IconButton/constants.js +14 -0
  117. package/src/components/IconButton/readme.mdx +66 -0
  118. package/src/components/List.vue +150 -0
  119. package/src/components/Modal/Modal.stories.js +48 -0
  120. package/src/components/Modal/Modal.vue +231 -0
  121. package/src/components/Modal/readme.mdx +76 -0
  122. package/src/components/Pagination/LimitSelector.vue +73 -0
  123. package/src/components/Pagination/Pagination.stories.js +54 -0
  124. package/src/components/Pagination/Pagination.vue +227 -0
  125. package/src/components/Pagination/pagination.scss +189 -0
  126. package/src/components/Popover/Popover.stories.js +46 -0
  127. package/src/components/Popover/Popover.vue +81 -0
  128. package/src/components/Popover/constants.js +14 -0
  129. package/src/components/Popover/popover.scss +26 -0
  130. package/src/components/Popover/readme.mdx +42 -0
  131. package/src/components/ProgressBar/ProgressBar.stories.js +90 -0
  132. package/src/components/ProgressBar/ProgressBar.vue +58 -0
  133. package/src/components/ProgressBar/constants.js +6 -0
  134. package/src/components/ProgressBar/progressBar.scss +116 -0
  135. package/src/components/ProgressBar/readme.mdx +67 -0
  136. package/src/components/Sorting/Sorting.stories.js +35 -0
  137. package/src/components/Sorting/Sorting.vue +128 -0
  138. package/src/components/Sorting/constants.js +10 -0
  139. package/src/components/Sorting/sorting.scss +87 -0
  140. package/src/components/SplitButton/SplitButton.stories.js +39 -0
  141. package/src/components/SplitButton/SplitButton.vue +132 -0
  142. package/src/components/SplitButton/SplitButtonItem.vue +34 -0
  143. package/src/components/SplitButton/constants.js +4 -0
  144. package/src/components/SplitButton/readme.mdx +77 -0
  145. package/src/components/SplitButton/splitButton.scss +161 -0
  146. package/src/components/StatusIndicator/StatusIndicator.stories.js +40 -0
  147. package/src/components/StatusIndicator/StatusIndicator.vue +52 -0
  148. package/src/components/StatusIndicator/constants.js +10 -0
  149. package/src/components/StatusIndicator/icons.js +48 -0
  150. package/src/components/StatusIndicator/readme.mdx +21 -0
  151. package/src/components/Table/Cells/Cell.vue +71 -0
  152. package/src/components/Table/Cells/CheckboxCell.vue +48 -0
  153. package/src/components/Table/Row.vue +26 -0
  154. package/src/components/Table/Table.stories.js +59 -0
  155. package/src/components/Table/Table.vue +36 -0
  156. package/src/components/Tabs/Tab.vue +37 -0
  157. package/src/components/Tabs/TabDropdown.vue +93 -0
  158. package/src/components/Tabs/Tabs.stories.js +57 -0
  159. package/src/components/Tabs/Tabs.vue +94 -0
  160. package/src/components/Tabs/tabs.scss +157 -0
  161. package/src/components/TagPill/TagPill.stories.js +30 -0
  162. package/src/components/TagPill/TagPill.vue +133 -0
  163. package/src/components/TagPill/constants.js +9 -0
  164. package/src/components/TagPill/readme.mdx +37 -0
  165. package/src/components/ToggleTip/ToggleTip.stories.js +98 -0
  166. package/src/components/ToggleTip/ToggleTip.vue +112 -0
  167. package/src/components/ToggleTip/constants.js +14 -0
  168. package/src/components/ToggleTip/readme.mdx +46 -0
  169. package/src/components/ToggleTip/toggleTip.scss +55 -0
  170. package/src/components/Tooltip/Tooltip.stories.js +56 -0
  171. package/src/components/Tooltip/Tooltip.vue +49 -0
  172. package/src/components/Tooltip/readme.mdx +43 -0
  173. package/src/components/TreeSelect/Option.vue +325 -0
  174. package/src/components/TreeSelect/Select.stories.js +349 -0
  175. package/src/components/TreeSelect/Select.vue +909 -0
  176. package/src/components/TreeSelect/TreeSelect.stories.js +270 -0
  177. package/src/components/TreeSelect/scss/option.scss +204 -0
  178. package/src/components/TreeSelect/scss/select.scss +166 -0
  179. package/src/constants/events.js +2 -0
  180. package/src/constants/keyCodes.js +8 -0
  181. package/src/directives/outside/outside.js +81 -0
  182. package/src/directives/outside/outside.stories.js +29 -0
  183. package/src/directives/outside/readme.mdx +24 -0
  184. package/src/helpers/generateUID.js +3 -0
  185. package/src/helpers/getHrefFromID.js +3 -0
  186. package/src/helpers/multiLineOverflows.js +3 -0
  187. package/src/helpers/removeEvents.js +9 -0
  188. package/src/index.js +49 -0
  189. package/src/main.js +12 -0
  190. package/src/stories/link.readme.mdx +57 -0
  191. package/src/stories/link.stories.js +59 -0
  192. package/static/Logo.svg +25 -0
  193. package/static/docks/button.pdf +147566 -0
  194. package/vite.config.js +47 -0
@@ -0,0 +1,909 @@
1
+ <template>
2
+ <div class="tree-select">
3
+ <ib-dropdown
4
+ :disabled="isLoading"
5
+ :is-resizable="isResizable"
6
+ :vertical="vertical"
7
+ ref="dropdown"
8
+ >
9
+ <template v-if="hasTrigger" v-slot:trigger>
10
+ <slot v-bind:selected-count="selectedKeys.length" name="trigger"></slot>
11
+ </template>
12
+
13
+ <template v-else v-slot:trigger="{ isOpened }">
14
+ <div
15
+ role="combobox"
16
+ tabindex="0"
17
+ class="tree-choice"
18
+ @click.prevent
19
+ :aria-label="ariaLabel"
20
+ :aria-expanded="isOpened"
21
+ :class="{
22
+ 'tree-choice-opened': isOpened,
23
+ 'has-clear-button': !showClearButton,
24
+ }"
25
+ >
26
+ <template v-if="htmlOptionTitle">
27
+ <span
28
+ :class="{ placeholder: !selectStatus }"
29
+ v-html="selectStatus || placeholder"
30
+ ></span>
31
+ </template>
32
+ <template v-else>
33
+ <span :class="{ placeholder: !selectStatus }">
34
+ {{ selectStatus || placeholder }}
35
+ </span>
36
+ </template>
37
+ </div>
38
+ <ib-icon-button
39
+ v-if="showClearButton"
40
+ kind="ghost"
41
+ class="button-clear"
42
+ @click.prevent="clearValue"
43
+ :help-text="clearButtonMessage"
44
+ v-show="Object.keys(selected).length"
45
+ >
46
+ <ib-icon name="close-outline"></ib-icon>
47
+ </ib-icon-button>
48
+
49
+ <ib-icon
50
+ :name="isOpened ? 'chevron-up-outline' : 'chevron-down-outline'"
51
+ :classes="'tree-select-caret'"
52
+ />
53
+ </template>
54
+
55
+ <template v-slot:body>
56
+ <div
57
+ class="tree-drop"
58
+ :class="{ 'not-tree-child': !hasTreeChildren }"
59
+ :style="{
60
+ width: 'auto',
61
+ position: 'absolute',
62
+ left: -size.left + 'px',
63
+ right: -size.right + 'px',
64
+ }"
65
+ >
66
+ <div
67
+ v-if="isResizable"
68
+ class="ib-dropdown-resizer ib-dropdown-resizer-left"
69
+ @mousedown="startResizing('left')"
70
+ ></div>
71
+ <div
72
+ v-if="isResizable"
73
+ class="ib-dropdown-resizer ib-dropdown-resizer-right"
74
+ @mousedown="startResizing('right')"
75
+ ></div>
76
+ <list
77
+ :class="{ 'has-hierarchy': hasHierarchy }"
78
+ v-if="Object.keys(actualBookmarkedOptions).length > 0"
79
+ >
80
+ <select-option
81
+ :key="'bookmark' + option.id"
82
+ v-for="option in actualBookmarkedOptions"
83
+ :option="option"
84
+ :parent-auto-check="false"
85
+ :is-multiple="isMultiple"
86
+ :is-bookmarkable="true"
87
+ :is-bookmarked="true"
88
+ @check="registerCheck"
89
+ @toggle-bookmark="toggleBookmark"
90
+ :uid="uid"
91
+ :only-end-nodes="onlyEndNodes"
92
+ :html-title="htmlOptionTitle"
93
+ :show-input="showInputs"
94
+ ></select-option>
95
+ </list>
96
+
97
+ <ib-input
98
+ class="tree-search"
99
+ v-if="showSearch"
100
+ :show-icon="true"
101
+ :value="filterString"
102
+ :placeholder="
103
+ searchPlaceholderText
104
+ ? searchPlaceholderText
105
+ : actualStrings.searchPlaceholder
106
+ "
107
+ @input="filter($event, actualOptions)"
108
+ ></ib-input>
109
+
110
+ <list
111
+ ref="list"
112
+ :class="{ 'tree-select-list': true, 'has-hierarchy': hasHierarchy }"
113
+ >
114
+ <div
115
+ v-if="!requiredDependencyNotFilled && !countVisibleChildren"
116
+ class="tree-select-empty"
117
+ >
118
+ {{ actualStrings.emptyTitle }}
119
+ </div>
120
+ <div v-show="requiredDependencyNotFilled" class="tree-select-empty">
121
+ {{ actualStrings.requiredDependencyNotFilled }}
122
+ </div>
123
+
124
+ <template
125
+ v-if="!isMultiple && !isRequired && actualOptions.length > 0"
126
+ >
127
+ <select-option
128
+ :option="{
129
+ title: lang('none', 'select'),
130
+ id: null,
131
+ checked: isEmpty,
132
+ }"
133
+ :name="actualName"
134
+ :parent-auto-check="parentAutoCheck"
135
+ :is-multiple="isMultiple"
136
+ @check="registerCheck"
137
+ @toggle-bookmark="toggleBookmark"
138
+ :uid="uid"
139
+ :only-end-nodes="onlyEndNodes"
140
+ :show-input="showInputs"
141
+ ></select-option>
142
+ </template>
143
+
144
+ <template v-if="!requiredDependencyNotFilled">
145
+ <template
146
+ v-if="
147
+ allOptions &&
148
+ isMultiple &&
149
+ countVisibleChildren &&
150
+ !requiredDependencyNotFilled
151
+ "
152
+ >
153
+ <select-option
154
+ :option="{
155
+ title: actualStrings.selectAllOptions,
156
+ id: '!all!',
157
+ initiallyVisible: true,
158
+ visible: true,
159
+ isDisabled: visibleOptionsCount < optionsCount,
160
+ checked: allOptionsIsChecked,
161
+ isIndeterminate: Object.keys(selected).length
162
+ ? true
163
+ : false,
164
+ }"
165
+ :is-toggle="isToggle"
166
+ :name="actualName"
167
+ :parent-auto-check="false"
168
+ :is-multiple="isMultiple"
169
+ :is-bookmarkable="false"
170
+ @check="manageAll"
171
+ :uid="uid"
172
+ :only-end-nodes="onlyEndNodes"
173
+ :show-input="showInputs"
174
+ ></select-option>
175
+ </template>
176
+
177
+ <template v-for="option in actualOptions" :key="option.value">
178
+ <slot
179
+ :option="option"
180
+ :name="actualName"
181
+ :parent-auto-check="parentAutoCheck"
182
+ :is-multiple="isMultiple"
183
+ :uid="uid"
184
+ :only-end-nodes="onlyEndNodes"
185
+ :html-title="htmlOptionTitle"
186
+ :show-input="showInputs"
187
+ >
188
+ <select-option
189
+ v-show="option.visible"
190
+ :option="option"
191
+ :is-toggle="isToggle"
192
+ :name="actualName"
193
+ :parent-auto-check="parentAutoCheck"
194
+ :is-multiple="isMultiple"
195
+ :is-bookmarkable="isBookmarkable"
196
+ @check="registerCheck"
197
+ @toggle-bookmark="toggleBookmark"
198
+ :uid="uid"
199
+ :only-end-nodes="onlyEndNodes"
200
+ :html-title="htmlOptionTitle"
201
+ :show-input="showInputs"
202
+ ></select-option>
203
+ </slot>
204
+ </template>
205
+ </template>
206
+ </list>
207
+ </div>
208
+ </template>
209
+ </ib-dropdown>
210
+ </div>
211
+ </template>
212
+
213
+ <script>
214
+ import IbInput from "../Form/Input/Input.vue";
215
+ import Option from "./Option.vue";
216
+ import Mark from "mark.js/dist/mark.es6.min";
217
+ import generateUID from "../../helpers/generateUID";
218
+ import IbDropdown from "../Dropdown/Dropdown.vue";
219
+ import IbIcon from "../Icon.vue";
220
+ import IbIconButton from "../IconButton/IconButton.vue";
221
+ import List from "../List.vue";
222
+
223
+ export default {
224
+ name: "IbTreeSelect",
225
+ props: {
226
+ placeholder: {
227
+ type: String,
228
+ default: "",
229
+ },
230
+ searchPlaceholderText: {
231
+ type: String,
232
+ default: "",
233
+ },
234
+ clearButtonMessage: {
235
+ type: String,
236
+ default: "",
237
+ },
238
+ showClearButton: {
239
+ type: Boolean,
240
+ default: true,
241
+ },
242
+ isResizable: {
243
+ type: Boolean,
244
+ default: false,
245
+ },
246
+ initialSize: {
247
+ left: 0,
248
+ right: 0,
249
+ },
250
+ ariaLabel: {
251
+ type: String,
252
+ default: "",
253
+ },
254
+ name: String,
255
+ id: {
256
+ type: String,
257
+ default() {
258
+ return generateUID();
259
+ },
260
+ },
261
+ options: {
262
+ default() {
263
+ return [];
264
+ },
265
+ },
266
+ value: {
267
+ type: [Number, String, Array],
268
+ default() {
269
+ return [];
270
+ },
271
+ },
272
+ maxSelectedNames: {
273
+ type: Number,
274
+ default: 2,
275
+ },
276
+ isMultiple: {
277
+ type: Boolean,
278
+ default: true,
279
+ },
280
+ parentAutoCheck: {
281
+ type: Boolean,
282
+ default: true,
283
+ },
284
+ strings: {
285
+ type: Object,
286
+ default() {
287
+ return {};
288
+ },
289
+ },
290
+ onlyEndNodes: {
291
+ type: Boolean,
292
+ default: false,
293
+ },
294
+ isRequired: {
295
+ type: Boolean,
296
+ default: true,
297
+ },
298
+ htmlOptionTitle: {
299
+ type: Boolean,
300
+ default: false,
301
+ },
302
+ isBookmarkable: {
303
+ type: Boolean,
304
+ default: false,
305
+ },
306
+ initBookmarks: {
307
+ type: Array,
308
+ default: () => [],
309
+ },
310
+ showInputs: {
311
+ type: Boolean,
312
+ default(props) {
313
+ return props.isMultiple;
314
+ },
315
+ },
316
+ dependency: {
317
+ type: String,
318
+ },
319
+ filterId: {
320
+ type: String,
321
+ default() {
322
+ return generateUID();
323
+ },
324
+ },
325
+ staticPlaceholder: {
326
+ type: Boolean,
327
+ default: false,
328
+ },
329
+ useSearch: {
330
+ type: Boolean,
331
+ default: false,
332
+ },
333
+ isWatching: {
334
+ type: Boolean,
335
+ default: false,
336
+ },
337
+ vertical: {
338
+ type: String,
339
+ },
340
+ emptyMessage: {
341
+ type: String,
342
+ default: "",
343
+ },
344
+ allOptions: {
345
+ type: Boolean,
346
+ default: true,
347
+ },
348
+ watchClearValue: {
349
+ type: Boolean,
350
+ default: false,
351
+ },
352
+ isToggle: {
353
+ type: Boolean,
354
+ default: false,
355
+ },
356
+ },
357
+ watch: {
358
+ value(value) {
359
+ if (
360
+ this.watchClearValue &&
361
+ (!value || (Array.isArray(value) && !value.length))
362
+ ) {
363
+ this.setPreparedValues(this.actualOptions).then(() => {
364
+ const values = Object.keys(this.selected);
365
+ this.$globalEvents.$emit("select-" + this.filterId + ":update", {
366
+ values,
367
+ filter: this.filterId,
368
+ });
369
+ });
370
+ }
371
+ },
372
+ options() {
373
+ let isOptionsEqual = true;
374
+
375
+ if (typeof this.options === "function") {
376
+ isOptionsEqual = false;
377
+ } else {
378
+ const result = [];
379
+
380
+ const options = this.options;
381
+ Array.prototype.forEach.call(options, (option) => {
382
+ if (option.id !== undefined) result.push(option.id);
383
+ });
384
+
385
+ isOptionsEqual =
386
+ JSON.stringify(result) === JSON.stringify(this.optionsIdsWatch);
387
+ this.optionsIdsWatch = result;
388
+ }
389
+
390
+ if ((this.isInitialized && !isOptionsEqual) || this.isWatching) {
391
+ this.setPreparedValues().then(() => {
392
+ const values = Object.keys(this.selected);
393
+ this.$globalEvents.$emit("select-" + this.filterId + ":update", {
394
+ values,
395
+ filter: this.filterId,
396
+ });
397
+ });
398
+ }
399
+ },
400
+ dependency(newVal, oldVal) {
401
+ this.$nextTick(() => {
402
+ this.registerDependency(oldVal);
403
+ });
404
+ },
405
+ initBookmarks() {
406
+ this.actualBookmarkedOptions = {};
407
+ this.setBookmarkedOptions(this.actualOptions);
408
+ },
409
+ },
410
+ mounted() {
411
+ this.marker = new Mark(this.$refs.list.$el);
412
+
413
+ this.registerDependency();
414
+
415
+ this.$globalEvents.$on("select:refresh", () => {
416
+ this.setPreparedValues();
417
+ });
418
+
419
+ document.addEventListener("mousemove", this.onResize);
420
+ document.addEventListener("mouseup", this.endResizing);
421
+ },
422
+ data() {
423
+ this.defaultFilter = (options) => {
424
+ this.marker.unmark();
425
+ const filterString = this.filterString.toLowerCase().trim();
426
+ this.countVisibleChildren = this.filterFunc.call(
427
+ this,
428
+ options,
429
+ filterString
430
+ );
431
+
432
+ if (filterString) {
433
+ this.marker.mark(filterString);
434
+ }
435
+ };
436
+
437
+ return {
438
+ size: {
439
+ left: (this.initialSize && this.initialSize.left) || 0,
440
+ right: (this.initialSize && this.initialSize.right) || 0,
441
+ },
442
+ resizingProp: null,
443
+ isInitialized: false,
444
+ optionsIdsWatch: [],
445
+ isLoading: false,
446
+ actualName: this.isMultiple ? this.name + "[]" : this.name,
447
+ filterString: "",
448
+ actualOptions: [],
449
+ actualBookmarkedOptions: {},
450
+ selected: [],
451
+ allOptionsIsChecked: true,
452
+ countVisibleChildren: 0,
453
+ hasTreeChildren: false,
454
+ uid: `f${(~~(Math.random() * 1e8)).toString(16)}`,
455
+ actualStrings: {
456
+ ...{
457
+ searchPlaceholder: "Search placeholder",
458
+ // this.lang(
459
+ // this.searchPlaceholderText.length
460
+ // ? this.searchPlaceholderText
461
+ // : "search_placeholder",
462
+ // LANG_COMPONENTS.COMPONENT_SELECT
463
+ // ),
464
+ emptyTitle: "Empty title",
465
+ // this.lang(
466
+ // "empty_title",
467
+ // LANG_COMPONENTS.COMPONENT_SELECT
468
+ // ),
469
+ selectAllOptions: "All Options",
470
+ // this.lang(
471
+ // "all_options",
472
+ // LANG_COMPONENTS.COMPONENT_SELECT
473
+ // ),
474
+ allSelected: "All selected",
475
+ // this.lang(
476
+ // "all_selected",
477
+ // LANG_COMPONENTS.COMPONENT_SELECT
478
+ // ),
479
+ loading: "loading",
480
+ // this.lang("loading", LANG_COMPONENTS.COMPONENT_SELECT) + "...",
481
+ selectedCount: "Selected {selected} of {all} items",
482
+ // this.lang(
483
+ // "selected_count",
484
+ // LANG_COMPONENTS.COMPONENT_SELECT
485
+ // ),
486
+ buttonTitle: "Button title",
487
+ // this.buttonTitle ||
488
+ // this.lang("button_title", LANG_COMPONENTS.COMPONENT_SELECT),
489
+ requiredDependencyNotFilled: "Required dependency are not filled",
490
+ // // eslint-disable-next-line vue/no-computed-properties-in-data
491
+ // this.requiredDependencyNotFilled ||
492
+ // this.lang(
493
+ // "required_dependency_are_not_filled",
494
+ // LANG_COMPONENTS.COMPONENT_SELECT
495
+ // ),
496
+ },
497
+ ...this.strings,
498
+ },
499
+ dependencyValue: null,
500
+ };
501
+ },
502
+ methods: {
503
+ startResizing(prop) {
504
+ this.resizingProp = prop;
505
+ },
506
+ endResizing() {
507
+ if (this.resizingProp) {
508
+ this.resizingProp = null;
509
+ this.$emit("resize", this.size);
510
+ }
511
+ },
512
+ onResize(event) {
513
+ switch (this.resizingProp) {
514
+ case "left":
515
+ this.size.left = Math.max(this.size.left - event.movementX, 0);
516
+ break;
517
+ case "right":
518
+ this.size.right = Math.max(this.size.right + event.movementX, 0);
519
+ break;
520
+ }
521
+ },
522
+ registerDependency(oldDependency) {
523
+ if (this.dependency) {
524
+ this.$globalEvents.$on(
525
+ "select-" + this.dependency + ":update",
526
+ (dependencyValue) => {
527
+ this.clear();
528
+ this.dependencyValue = dependencyValue;
529
+
530
+ if (
531
+ this.dependencyValue &&
532
+ this.dependencyValue.values &&
533
+ (!Array.isArray(this.dependencyValue.values) ||
534
+ this.dependencyValue.values.length)
535
+ ) {
536
+ this.setPreparedValues();
537
+ }
538
+ }
539
+ );
540
+ this.isLoading = false;
541
+ } else {
542
+ this.$globalEvents.$off("select-" + oldDependency + ":update");
543
+ this.setPreparedValues().then(() => {
544
+ const values = Object.keys(this.selected);
545
+ this.$globalEvents.$emit("select-" + this.filterId + ":update", {
546
+ values,
547
+ filter: this.filterId,
548
+ });
549
+ });
550
+ }
551
+ },
552
+ filter(filterString, options) {
553
+ this.filterString = filterString;
554
+ this.$emit("search", { search: this.filterString });
555
+ this.defaultFilter(options);
556
+ },
557
+ setPreparedValues(options) {
558
+ return this.prepare(options || this.options).then(
559
+ ([options, selected]) => {
560
+ this.actualOptions = options;
561
+ this.allOptionsIsChecked = this.checkIfOptionsChecked(options);
562
+ this.countVisibleChildren = options.length;
563
+ this.isInitialized = true;
564
+ this.selected = selected;
565
+ this.setBookmarkedOptions(options);
566
+ }
567
+ );
568
+ },
569
+ clear() {
570
+ this.actualOptions = [];
571
+ this.allOptionsIsChecked = false;
572
+ this.countVisibleChildren = 0;
573
+ this.selected = [];
574
+ },
575
+ clearValue() {
576
+ this.clear();
577
+ this.setPreparedValues();
578
+ },
579
+ prepare(options) {
580
+ return new Promise((res) => {
581
+ const selected = {},
582
+ promises = [];
583
+
584
+ let chain = Promise.resolve();
585
+
586
+ if (typeof options === "function") {
587
+ this.isLoading = true;
588
+
589
+ if (this.dependency) {
590
+ options = options.bind(null, this.dependencyValue);
591
+ }
592
+
593
+ chain = chain.then(options);
594
+ } else {
595
+ chain = chain.then(() => options);
596
+ }
597
+
598
+ chain
599
+ .then((options) => {
600
+ this.isLoading = false;
601
+
602
+ options.forEach((option) => {
603
+ option.initiallyVisible =
604
+ typeof option.visible === "undefined" ? true : option.visible;
605
+ option.visible = option.initiallyVisible;
606
+ option.isDisabled = false;
607
+
608
+ option.checked = this.isMultiple
609
+ ? this.value !== null &&
610
+ this.value.findIndex((el) => option.id == el) > -1
611
+ : this.value !== null && this.value == option.id;
612
+
613
+ if (option.checked) {
614
+ if (!this.onlyEndNodes || !option.children) {
615
+ selected[option.id] = option;
616
+ }
617
+ }
618
+
619
+ if (option.children) {
620
+ this.hasTreeChildren = true; //here
621
+ option.isChildrenVisible = false;
622
+ }
623
+
624
+ promises.push(
625
+ new Promise((res) => {
626
+ if (option.children) {
627
+ this.prepare(option.children).then(
628
+ ([preparedChildren, selectedChildren]) => {
629
+ option.children = preparedChildren;
630
+ Object.assign(selected, selectedChildren);
631
+ res(option);
632
+ }
633
+ );
634
+ } else {
635
+ res(option);
636
+ }
637
+ })
638
+ );
639
+ });
640
+
641
+ return Promise.all(promises).then((options) => {
642
+ res([options, selected]);
643
+ });
644
+ })
645
+ .catch((err) => {
646
+ this.isLoading = false;
647
+ throw err;
648
+ });
649
+ });
650
+ },
651
+ filterFunc(options, filterString) {
652
+ let visibleOptionsCount = 0;
653
+
654
+ options.forEach((option) => {
655
+ let isVisible =
656
+ option.initiallyVisible &&
657
+ option.title.toString().toLowerCase().includes(filterString) &&
658
+ !this.actualBookmarkedOptions[option.id];
659
+
660
+ if (option.children && option.children.length) {
661
+ let visibleChildrenCount = this.filterFunc(
662
+ option.children,
663
+ filterString
664
+ );
665
+ visibleOptionsCount += visibleChildrenCount;
666
+
667
+ if (visibleChildrenCount) {
668
+ option.isChildrenVisible =
669
+ !!filterString ||
670
+ Boolean(Object.keys(this.actualBookmarkedOptions).length);
671
+ option.isDisabled =
672
+ visibleChildrenCount < option.children.length &&
673
+ !this.isBookmarkable;
674
+ }
675
+
676
+ if (!isVisible) {
677
+ isVisible = !!visibleChildrenCount;
678
+ } else if (!visibleChildrenCount) {
679
+ isVisible = false;
680
+ }
681
+ }
682
+
683
+ option.visible = isVisible;
684
+
685
+ if (isVisible) {
686
+ visibleOptionsCount++;
687
+ }
688
+ });
689
+
690
+ return visibleOptionsCount;
691
+ },
692
+ submit() {
693
+ this.change();
694
+ const values = Object.keys(this.selected);
695
+ this.$globalEvents.$emit("select-" + this.filterId + ":submit", {
696
+ values,
697
+ filter: this.filterId,
698
+ });
699
+ this.$emit("submit");
700
+ },
701
+ change() {
702
+ const values = Object.keys(this.selected);
703
+ if (this.isMultiple) {
704
+ this.$emit("input", values);
705
+ } else {
706
+ this.$emit("input", values[0]);
707
+ }
708
+ this.$globalEvents.$emit("select-" + this.filterId + ":update", {
709
+ values,
710
+ filter: this.filterId,
711
+ });
712
+ this.$refs.dropdown.close();
713
+ },
714
+ checkIfOptionsChecked(options) {
715
+ return options.every((option) => option.checked);
716
+ },
717
+ registerCheck(option, isChecked, isDirectChild) {
718
+ if (isChecked) {
719
+ option.checked = true;
720
+ if (this.isMultiple) {
721
+ if (
722
+ !(this.onlyEndNodes && option.children && option.children.length)
723
+ ) {
724
+ this.selected[option.id] = option;
725
+ this.$emit("input", Object.keys(this.selected));
726
+ }
727
+ } else {
728
+ const selectedOptionKey = Object.keys(this.selected)[0];
729
+
730
+ if (selectedOptionKey) {
731
+ this.selected[selectedOptionKey].checked = false;
732
+ }
733
+
734
+ this.selected = { [option.id]: option };
735
+ this.change();
736
+ }
737
+ } else {
738
+ delete this.selected[option.id];
739
+ option.checked = false;
740
+ this.$emit("input", Object.keys(this.selected));
741
+ }
742
+
743
+ this.toggleDuplicateOptions(this.actualOptions, option.id, isChecked);
744
+ if (isDirectChild) {
745
+ this.allOptionsIsChecked = this.checkIfOptionsChecked(
746
+ this.actualOptions
747
+ );
748
+ }
749
+ },
750
+ toggleDuplicateOptions(options, optionId, checked) {
751
+ for (let opt of options) {
752
+ if (opt.id === optionId) {
753
+ opt.checked = checked;
754
+ }
755
+ if (opt.children) {
756
+ this.toggleDuplicateOptions(opt.children, optionId, checked);
757
+ }
758
+ }
759
+ },
760
+ manageAll() {
761
+ this.allOptionsIsChecked = !this.allOptionsIsChecked;
762
+ this.traverseTree(this.actualOptions, (option) => {
763
+ this.registerCheck(option, this.allOptionsIsChecked, false);
764
+ });
765
+ },
766
+ traverseTree(tree, callback) {
767
+ tree.forEach((option) => {
768
+ callback(option);
769
+
770
+ if (option.children && option.children.length) {
771
+ this.traverseTree(option.children, callback);
772
+ }
773
+ });
774
+ },
775
+ getArrayOptions(options) {
776
+ let allOptions = [];
777
+ for (let option of options) {
778
+ allOptions.push(option);
779
+ if (option.children) {
780
+ allOptions = allOptions.concat(this.getArrayOptions(option.children));
781
+ }
782
+ }
783
+ return allOptions;
784
+ },
785
+ toggleBookmark(option) {
786
+ if (this.actualBookmarkedOptions[option.id]) {
787
+ delete this.actualBookmarkedOptions[option.id];
788
+ } else {
789
+ this.actualBookmarkedOptions[option.id] = option;
790
+ }
791
+
792
+ this.$emit("toggle-bookmarked-option", option.id);
793
+ this.filter(this.filterString, this.actualOptions);
794
+ },
795
+ setBookmarkedOptions(options) {
796
+ options.forEach((option) => {
797
+ if (option.children && option.children.length) {
798
+ this.setBookmarkedOptions(option.children);
799
+ } else {
800
+ if (this.initBookmarks.includes(option.id)) {
801
+ this.actualBookmarkedOptions[option.id] = option;
802
+ }
803
+ }
804
+ });
805
+ this.filter(this.filterString, options);
806
+ },
807
+ },
808
+ computed: {
809
+ hasTrigger() {
810
+ return !!this.$slots.trigger;
811
+ },
812
+ hasHierarchy() {
813
+ return this.actualOptions.some((option) => {
814
+ return option.children;
815
+ });
816
+ },
817
+ selectedKeys() {
818
+ return Object.keys(this.selected).filter((elem) => {
819
+ if (!this.onlyEndNodes || !this.selected[elem].children) {
820
+ return true;
821
+ }
822
+ });
823
+ },
824
+ selectStatus() {
825
+ if (this.staticPlaceholder) {
826
+ return this.placeholder;
827
+ } else if (this.isLoading) {
828
+ return this.actualStrings.loading;
829
+ } else if (!this.selectedKeys.length) {
830
+ return this.emptyMessage;
831
+ } else if (this.selectedKeys.length < this.maxSelectedNames) {
832
+ return this.selectedKeys
833
+ .map((key) => this.selected[key].title)
834
+ .join(",");
835
+ } else if (this.selectedKeys.length < this.optionsCount) {
836
+ return this.actualStrings.selectedCount
837
+ .replace("{selected}", this.selectedKeys.length)
838
+ .replace("{all}", this.optionsCount);
839
+ } else {
840
+ return this.actualStrings.allSelected;
841
+ }
842
+ },
843
+ isEmpty() {
844
+ return Array.isArray(this.value) ? !this.value.length : !this.value;
845
+ },
846
+ requiredDependencyNotFilled() {
847
+ return (
848
+ this.dependency &&
849
+ (!this.dependencyValue ||
850
+ !this.dependencyValue.values ||
851
+ !this.dependencyValue.values.length)
852
+ );
853
+ },
854
+ showSearch() {
855
+ return this.useSearch || this.optionsCount > 10;
856
+ },
857
+ arrayOfOptions() {
858
+ return this.getArrayOptions(this.actualOptions);
859
+ },
860
+ optionsCount() {
861
+ let ids = [];
862
+ for (let option of this.arrayOfOptions) {
863
+ if (
864
+ (!this.onlyEndNodes || !option.children) &&
865
+ !ids.includes(option.id)
866
+ ) {
867
+ ids.push(option.id);
868
+ }
869
+ }
870
+ return ids.length;
871
+ },
872
+ visibleOptionsCount() {
873
+ let ids = [];
874
+
875
+ this.traverseTree(this.actualOptions, (option) => {
876
+ if (
877
+ (!this.onlyEndNodes || !option.children) &&
878
+ !ids.includes(option.id) &&
879
+ option.visible
880
+ ) {
881
+ ids.push(option.id);
882
+ }
883
+ });
884
+
885
+ return (
886
+ ids.length +
887
+ (this.isBookmarkable
888
+ ? Object.keys(this.actualBookmarkedOptions).length
889
+ : 0)
890
+ );
891
+ },
892
+ },
893
+ components: {
894
+ IbIconButton,
895
+ IbIcon,
896
+ IbDropdown,
897
+ IbInput,
898
+ List,
899
+ "select-option": Option,
900
+ },
901
+ beforeUnmount() {
902
+ document.removeEventListener("mousemove", this.onResize);
903
+ document.removeEventListener("mouseup", this.endResizing);
904
+ },
905
+ };
906
+ </script>
907
+ <style lang="scss">
908
+ @import "./scss/select.scss";
909
+ </style>