vue3-extended-multiselect 1.7.0 → 1.7.2

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 (46) hide show
  1. package/.browserslistrc +2 -2
  2. package/.eslintrc.js +34 -34
  3. package/.github/workflows/publish.yml +41 -41
  4. package/CHANGELOG.md +284 -275
  5. package/LICENSE +21 -21
  6. package/README.md +267 -267
  7. package/babel.config.js +9 -9
  8. package/index.js +2 -2
  9. package/jest.config.js +61 -61
  10. package/package.json +46 -46
  11. package/src/assets/base-arrow.svg +70 -70
  12. package/src/assets/cancel.svg +34 -34
  13. package/src/assets/circle-arrow.svg +7 -7
  14. package/src/assets/double-arrow.svg +39 -39
  15. package/src/assets/inner-arrow.svg +8 -8
  16. package/src/assets/loader.svg +5 -5
  17. package/src/assets/triangle-arrow.svg +72 -72
  18. package/src/assets/triangle-circle-arrow.svg +38 -38
  19. package/src/assets/wide-arrow.svg +72 -72
  20. package/src/components/ExtendedMultiselectCancel.vue +165 -165
  21. package/src/components/ExtendedMultiselectInput.vue +705 -705
  22. package/src/components/ExtendedMultiselectLoader.vue +182 -182
  23. package/src/components/ExtendedMultiselectMultiple.vue +365 -365
  24. package/src/components/ExtendedMultiselectOptions.vue +1168 -1168
  25. package/src/components/ExtendedMultiselectToggle.vue +271 -271
  26. package/src/components/Vue3ExtendedMultiselect.vue +1803 -1783
  27. package/src/composition/cancel.js +36 -36
  28. package/src/composition/click-outside.js +8 -8
  29. package/src/composition/emitter.js +8 -8
  30. package/src/composition/image-path.js +16 -16
  31. package/src/composition/labels.js +41 -41
  32. package/src/composition/preselected-options.js +67 -67
  33. package/src/composition/search-value.js +33 -33
  34. package/src/composition/sizes.js +44 -44
  35. package/src/composition/toggle.js +31 -31
  36. package/src/events/LocalEmitter.js +31 -31
  37. package/src/events/instance.js +3 -0
  38. package/src/sets/sets.js +99 -99
  39. package/src/styles/animations.css +18 -18
  40. package/src/styles/main.css +454 -454
  41. package/src/styles/variables.css +49 -49
  42. package/tests/unit/events.spec.js +136 -136
  43. package/tests/unit/props.spec.js +1128 -1128
  44. package/tests/utils/mount.js +37 -37
  45. package/tests/utils/utils.js +20 -20
  46. package/typings/vue3-extended-multiselect.d.ts +43 -43
@@ -1,366 +1,366 @@
1
- <template>
2
- <div class="extended__multiselect-block extended__multiselect-block--multiple">
3
- <div
4
- v-for="(option, index) in limitRestriction"
5
- :key="index"
6
- >
7
- <slot
8
- name="optionBlock"
9
- :label="optionCreateLabel(option)"
10
- :index="index"
11
- :deselect-block="deselectBlock"
12
- >
13
- <div :class="classes">
14
- <span>{{ optionCreateLabel(option) }}</span>
15
- <div :class="deselectClasses">
16
- <img
17
- alt=""
18
- class="extended__multiselect_deselect-block-icon"
19
- v-if="!showLoaderIcon"
20
- :src="deselectImage"
21
- @click.stop="deselectBlock(index)"
22
- />
23
- <extended-multiselect-loader
24
- v-else
25
- :icon-filter="iconFilter"
26
- icon-size="deselect"
27
- />
28
- </div>
29
- </div>
30
- </slot>
31
- </div>
32
- <slot
33
- name="maxElements"
34
- v-if="optionsLimitAchieved && !toggleMultipleBlocksLimit"
35
- >
36
- {{ multipleBlocksLimitMessage(overLimitOptionsCount) }}
37
- </slot>
38
- <slot
39
- name="showMore"
40
- v-if="optionIncreaserAvailable"
41
- :show-more-options="showMoreOptions"
42
- >
43
- <div
44
- :class="[classes, increaserClass]"
45
- @click.stop="showMoreOptions"
46
- >
47
- Show more options
48
- </div>
49
- </slot>
50
- </div>
51
- </template>
52
-
53
- <script setup>
54
- import {
55
- computed,
56
- defineProps,
57
- onBeforeMount,
58
- ref,
59
- toRefs,
60
- watch,
61
- } from "vue";
62
-
63
- import useImagePath from "../composition/image-path";
64
- import useLabels from "../composition/labels";
65
-
66
- import ExtendedMultiselectLoader from "./ExtendedMultiselectLoader.vue";
67
-
68
- const props = defineProps({
69
- /**
70
- * Function that creates custom label for
71
- * block with selected option
72
- * @property {Function} createCustomOptionLabel
73
- */
74
- createCustomOptionLabel: {
75
- type: Function,
76
- required: true,
77
- },
78
-
79
- /**
80
- * Blocks deselect block button
81
- * @property {boolean} disabled
82
- */
83
- disabled: {
84
- type: Boolean,
85
- required: true,
86
- },
87
-
88
- /**
89
- * Defines label for blocks with options of type "object"
90
- * or Array instances which length/keys length equals 0
91
- * @property {string} emptyObjectsPlaceholder
92
- */
93
- emptyObjectsPlaceholder: {
94
- type: String,
95
- required: true,
96
- },
97
-
98
- /**
99
- * Determines field of option which will be displayed as label
100
- * @property {string} label
101
- */
102
- label: {
103
- type: String,
104
- required: true,
105
- },
106
-
107
- /**
108
- * Limit of hidden options amount to be shown next
109
- * @property {number} increaseDisplayBy
110
- */
111
- increaseDisplayBy: {
112
- type: Number,
113
- required: true,
114
- },
115
-
116
- /**
117
- * Hides all deselect buttons if equals true
118
- * @property {boolean} loading
119
- */
120
- loading: {
121
- type: Boolean,
122
- required: true,
123
- },
124
-
125
- /**
126
- * Limit of option blocks amount
127
- * @property {number} multipleBlocksLimit
128
- */
129
- multipleBlocksLimit: {
130
- type: Number,
131
- default: null,
132
- },
133
-
134
- /**
135
- * Determines whether to show loader icon in multiple
136
- * options block if "loading" prop equals true
137
- * @default true
138
- * @property {boolean} showDeselectIconLoader
139
- */
140
- showDeselectIconLoader: {
141
- type: Boolean,
142
- default: true,
143
- },
144
-
145
- /**
146
- * Allows to increase limit of displayed selected option blocks
147
- * @property {boolean} toggleMultipleBlocksLimit
148
- */
149
- toggleMultipleBlocksLimit: {
150
- type: Boolean,
151
- required: true,
152
- },
153
-
154
- /**
155
- * Defines a svg-filter for icons
156
- * @property {string} iconFilter
157
- */
158
- iconFilter: {
159
- type: String,
160
- required: true,
161
- },
162
-
163
- /**
164
- * Function that creates limit message for maximal of selected options
165
- * @property {Function} multipleBlocksLimitMessage
166
- */
167
- multipleBlocksLimitMessage: {
168
- type: Function,
169
- required: true,
170
- },
171
-
172
- /**
173
- * List of selected options that will be shown as option blocks
174
- * @property {Array} selectedOptions
175
- */
176
- selectedOptions: {
177
- type: Array,
178
- required: true,
179
- },
180
-
181
- /**
182
- * Reactive instance of LocalEmitter class
183
- * @property {object} emitter
184
- */
185
- emitter: {
186
- type: Object,
187
- required: true,
188
- },
189
-
190
- /**
191
- * Current theme of extended-multiselect
192
- * used in class definition
193
- * @property {string} themeType
194
- */
195
- themeType: {
196
- type: String,
197
- required: true,
198
- },
199
- });
200
-
201
- const {
202
- createCustomOptionLabel,
203
- disabled,
204
- emitter,
205
- emptyObjectsPlaceholder,
206
- label,
207
- increaseDisplayBy,
208
- loading,
209
- showDeselectIconLoader,
210
- multipleBlocksLimit,
211
- selectedOptions,
212
- themeType,
213
- toggleMultipleBlocksLimit,
214
- } = toRefs(props);
215
-
216
- const { createImagePath } = useImagePath();
217
-
218
- const optionsLimitIncreaser = ref(null);
219
- const increaserClass = ref("extended__multiselect-increaser");
220
- const deselectImage = ref(createImagePath("cancel.svg"));
221
-
222
- const { optionCreateLabel } = useLabels(
223
- label,
224
- createCustomOptionLabel,
225
- emptyObjectsPlaceholder,
226
- );
227
-
228
- /**
229
- * Defines class for every selected option block
230
- * depends on current theme of extended multiselect
231
- * @function
232
- * @returns {string} class
233
- */
234
- const classes = computed(() => {
235
- const basicClassName = "extended__multiselect--multiple";
236
-
237
- switch(themeType.value) {
238
- case "basic":
239
- return `${basicClassName}-basic`;
240
- case "slate-grey":
241
- return `${basicClassName}-slate-grey`;
242
- case "slate-blue":
243
- return `${basicClassName}-slate-blue`;
244
- case "teal":
245
- return `${basicClassName}-teal`;
246
- case "strict":
247
- return `${basicClassName}-strict`;
248
- default:
249
- return `${basicClassName}-basic`;
250
- }
251
- });
252
-
253
- /**
254
- * Defines class for every deselect/loader icon in multiple
255
- * option blocks depends on "loading" prop
256
- * @function
257
- * @returns {string} class
258
- */
259
- const deselectClasses = computed(() => {
260
- return loading.value
261
- ? "extended__multiselect-block_cancel-wrapper--loading"
262
- : "extended__multiselect-block_cancel-wrapper";
263
- });
264
-
265
- /**
266
- * Defines current limited amount of displayed option blocks
267
- * @function
268
- * @returns {Array} UnionPropType
269
- */
270
- const limitRestriction = computed(() => {
271
- if (!optionsLimitIncreaser.value) return selectedOptions.value;
272
-
273
- return selectedOptions.value.filter((selectedOption, index) => {
274
- const limit = typeof optionsLimitIncreaser.value === "number"
275
- ? optionsLimitIncreaser.value
276
- : optionsLimitIncreaser.value.value;
277
-
278
- return ++index <= limit;
279
- });
280
- });
281
-
282
- /**
283
- * Determines whether user can increase limited amount of displayed option blocks
284
- * @function
285
- * @returns {boolean} possibility
286
- */
287
- const optionIncreaserAvailable = computed(() => {
288
- return toggleMultipleBlocksLimit.value && optionsLimitAchieved.value;
289
- });
290
-
291
- /**
292
- * Determines whether current limit of displayed option blocks amount
293
- * was reached
294
- * @function
295
- * @returns {boolean} reaching
296
- */
297
- const optionsLimitAchieved = computed(() => {
298
- return optionsLimitIncreaser.value && selectedOptions.value.length > optionsLimitIncreaser.value;
299
- });
300
-
301
- /**
302
- * Amount of selected options exceeding the limit
303
- * determined by "multipleBlocksLimit" prop
304
- * @function
305
- * @returns {number|null} amount
306
- */
307
- const overLimitOptionsCount = computed(() => {
308
- if (selectedOptions.value.length <= multipleBlocksLimit.value) return null;
309
-
310
- return selectedOptions.value.length - multipleBlocksLimit.value;
311
- });
312
-
313
- /**
314
- * Determines whether to show loader icon if "loading" prop equals true
315
- * or show multiple option blocks as usual
316
- * @function
317
- * @returns {boolean} restriction
318
- */
319
- const showLoaderIcon = computed(() => {
320
- return showDeselectIconLoader.value ? loading.value : false;
321
- });
322
-
323
- /**
324
- * If limit of selected options was achieved restricts further
325
- * extension of options container if "multiple" prop equals true
326
- * @function
327
- * @param {Array} - array of selected options
328
- */
329
- watch(selectedOptions, (value) => {
330
- if (!value.length || value.length <= multipleBlocksLimit.value) {
331
- optionsLimitIncreaser.value = multipleBlocksLimit.value;
332
- }
333
- }, { deep: true });
334
-
335
- /**
336
- * Deselects option by users click on its element cancel icon
337
- * if "multiple" prop equals true
338
- * @function
339
- * @emits extended:deselect-option
340
- * @param {number} index - index of deselected option
341
- */
342
- const deselectBlock = (index) => {
343
- if (loading.value || disabled.value) return;
344
-
345
- emitter.value.emit("extended:deselect-option", { index });
346
- };
347
-
348
- /**
349
- * Shows next hidden options
350
- * This behavior restricts by "toggleMultipleBlocksLimit" prop
351
- * if "multiple" prop equals true
352
- * @function
353
- * @emits extended:increase-display
354
- */
355
- const showMoreOptions = () => {
356
- optionsLimitIncreaser.value += increaseDisplayBy.value;
357
- emitter.value.emit("extended:increase-display", optionsLimitIncreaser.value);
358
- };
359
-
360
- /**
361
- * "onBeforeMount" hook of ExtendedMultiselectMultiple component
362
- */
363
- onBeforeMount(() => {
364
- optionsLimitIncreaser.value = multipleBlocksLimit.value;
365
- });
1
+ <template>
2
+ <div class="extended__multiselect-block extended__multiselect-block--multiple">
3
+ <div
4
+ v-for="(option, index) in limitRestriction"
5
+ :key="index"
6
+ >
7
+ <slot
8
+ name="optionBlock"
9
+ :label="optionCreateLabel(option)"
10
+ :index="index"
11
+ :deselect-block="deselectBlock"
12
+ >
13
+ <div :class="classes">
14
+ <span>{{ optionCreateLabel(option) }}</span>
15
+ <div :class="deselectClasses">
16
+ <img
17
+ alt=""
18
+ class="extended__multiselect_deselect-block-icon"
19
+ v-if="!showLoaderIcon"
20
+ :src="deselectImage"
21
+ @click.stop="deselectBlock(index)"
22
+ />
23
+ <extended-multiselect-loader
24
+ v-else
25
+ :icon-filter="iconFilter"
26
+ icon-size="deselect"
27
+ />
28
+ </div>
29
+ </div>
30
+ </slot>
31
+ </div>
32
+ <slot
33
+ name="maxElements"
34
+ v-if="optionsLimitAchieved && !toggleMultipleBlocksLimit"
35
+ >
36
+ {{ multipleBlocksLimitMessage(overLimitOptionsCount) }}
37
+ </slot>
38
+ <slot
39
+ name="showMore"
40
+ v-if="optionIncreaserAvailable"
41
+ :show-more-options="showMoreOptions"
42
+ >
43
+ <div
44
+ :class="[classes, increaserClass]"
45
+ @click.stop="showMoreOptions"
46
+ >
47
+ Show more options
48
+ </div>
49
+ </slot>
50
+ </div>
51
+ </template>
52
+
53
+ <script setup>
54
+ import {
55
+ computed,
56
+ defineProps,
57
+ onBeforeMount,
58
+ ref,
59
+ toRefs,
60
+ watch,
61
+ } from "vue";
62
+
63
+ import useImagePath from "../composition/image-path";
64
+ import useLabels from "../composition/labels";
65
+
66
+ import ExtendedMultiselectLoader from "./ExtendedMultiselectLoader.vue";
67
+
68
+ const props = defineProps({
69
+ /**
70
+ * Function that creates custom label for
71
+ * block with selected option
72
+ * @property {Function} createCustomOptionLabel
73
+ */
74
+ createCustomOptionLabel: {
75
+ type: Function,
76
+ required: true,
77
+ },
78
+
79
+ /**
80
+ * Blocks deselect block button
81
+ * @property {boolean} disabled
82
+ */
83
+ disabled: {
84
+ type: Boolean,
85
+ required: true,
86
+ },
87
+
88
+ /**
89
+ * Defines label for blocks with options of type "object"
90
+ * or Array instances which length/keys length equals 0
91
+ * @property {string} emptyObjectsPlaceholder
92
+ */
93
+ emptyObjectsPlaceholder: {
94
+ type: String,
95
+ required: true,
96
+ },
97
+
98
+ /**
99
+ * Determines field of option which will be displayed as label
100
+ * @property {string} label
101
+ */
102
+ label: {
103
+ type: String,
104
+ required: true,
105
+ },
106
+
107
+ /**
108
+ * Limit of hidden options amount to be shown next
109
+ * @property {number} increaseDisplayBy
110
+ */
111
+ increaseDisplayBy: {
112
+ type: Number,
113
+ required: true,
114
+ },
115
+
116
+ /**
117
+ * Hides all deselect buttons if equals true
118
+ * @property {boolean} loading
119
+ */
120
+ loading: {
121
+ type: Boolean,
122
+ required: true,
123
+ },
124
+
125
+ /**
126
+ * Limit of option blocks amount
127
+ * @property {number} multipleBlocksLimit
128
+ */
129
+ multipleBlocksLimit: {
130
+ type: Number,
131
+ default: null,
132
+ },
133
+
134
+ /**
135
+ * Determines whether to show loader icon in multiple
136
+ * options block if "loading" prop equals true
137
+ * @default true
138
+ * @property {boolean} showDeselectIconLoader
139
+ */
140
+ showDeselectIconLoader: {
141
+ type: Boolean,
142
+ default: true,
143
+ },
144
+
145
+ /**
146
+ * Allows to increase limit of displayed selected option blocks
147
+ * @property {boolean} toggleMultipleBlocksLimit
148
+ */
149
+ toggleMultipleBlocksLimit: {
150
+ type: Boolean,
151
+ required: true,
152
+ },
153
+
154
+ /**
155
+ * Defines a svg-filter for icons
156
+ * @property {string} iconFilter
157
+ */
158
+ iconFilter: {
159
+ type: String,
160
+ required: true,
161
+ },
162
+
163
+ /**
164
+ * Function that creates limit message for maximal of selected options
165
+ * @property {Function} multipleBlocksLimitMessage
166
+ */
167
+ multipleBlocksLimitMessage: {
168
+ type: Function,
169
+ required: true,
170
+ },
171
+
172
+ /**
173
+ * List of selected options that will be shown as option blocks
174
+ * @property {Array} selectedOptions
175
+ */
176
+ selectedOptions: {
177
+ type: Array,
178
+ required: true,
179
+ },
180
+
181
+ /**
182
+ * Reactive instance of LocalEmitter class
183
+ * @property {object} emitter
184
+ */
185
+ emitter: {
186
+ type: Object,
187
+ required: true,
188
+ },
189
+
190
+ /**
191
+ * Current theme of extended-multiselect
192
+ * used in class definition
193
+ * @property {string} themeType
194
+ */
195
+ themeType: {
196
+ type: String,
197
+ required: true,
198
+ },
199
+ });
200
+
201
+ const {
202
+ createCustomOptionLabel,
203
+ disabled,
204
+ emitter,
205
+ emptyObjectsPlaceholder,
206
+ label,
207
+ increaseDisplayBy,
208
+ loading,
209
+ showDeselectIconLoader,
210
+ multipleBlocksLimit,
211
+ selectedOptions,
212
+ themeType,
213
+ toggleMultipleBlocksLimit,
214
+ } = toRefs(props);
215
+
216
+ const { createImagePath } = useImagePath();
217
+
218
+ const optionsLimitIncreaser = ref(null);
219
+ const increaserClass = ref("extended__multiselect-increaser");
220
+ const deselectImage = ref(createImagePath("cancel.svg"));
221
+
222
+ const { optionCreateLabel } = useLabels(
223
+ label,
224
+ createCustomOptionLabel,
225
+ emptyObjectsPlaceholder,
226
+ );
227
+
228
+ /**
229
+ * Defines class for every selected option block
230
+ * depends on current theme of extended multiselect
231
+ * @function
232
+ * @returns {string} class
233
+ */
234
+ const classes = computed(() => {
235
+ const basicClassName = "extended__multiselect--multiple";
236
+
237
+ switch(themeType.value) {
238
+ case "basic":
239
+ return `${basicClassName}-basic`;
240
+ case "slate-grey":
241
+ return `${basicClassName}-slate-grey`;
242
+ case "slate-blue":
243
+ return `${basicClassName}-slate-blue`;
244
+ case "teal":
245
+ return `${basicClassName}-teal`;
246
+ case "strict":
247
+ return `${basicClassName}-strict`;
248
+ default:
249
+ return `${basicClassName}-basic`;
250
+ }
251
+ });
252
+
253
+ /**
254
+ * Defines class for every deselect/loader icon in multiple
255
+ * option blocks depends on "loading" prop
256
+ * @function
257
+ * @returns {string} class
258
+ */
259
+ const deselectClasses = computed(() => {
260
+ return loading.value
261
+ ? "extended__multiselect-block_cancel-wrapper--loading"
262
+ : "extended__multiselect-block_cancel-wrapper";
263
+ });
264
+
265
+ /**
266
+ * Defines current limited amount of displayed option blocks
267
+ * @function
268
+ * @returns {Array} UnionPropType
269
+ */
270
+ const limitRestriction = computed(() => {
271
+ if (!optionsLimitIncreaser.value) return selectedOptions.value;
272
+
273
+ return selectedOptions.value.filter((selectedOption, index) => {
274
+ const limit = typeof optionsLimitIncreaser.value === "number"
275
+ ? optionsLimitIncreaser.value
276
+ : optionsLimitIncreaser.value.value;
277
+
278
+ return ++index <= limit;
279
+ });
280
+ });
281
+
282
+ /**
283
+ * Determines whether user can increase limited amount of displayed option blocks
284
+ * @function
285
+ * @returns {boolean} possibility
286
+ */
287
+ const optionIncreaserAvailable = computed(() => {
288
+ return toggleMultipleBlocksLimit.value && optionsLimitAchieved.value;
289
+ });
290
+
291
+ /**
292
+ * Determines whether current limit of displayed option blocks amount
293
+ * was reached
294
+ * @function
295
+ * @returns {boolean} reaching
296
+ */
297
+ const optionsLimitAchieved = computed(() => {
298
+ return optionsLimitIncreaser.value && selectedOptions.value.length > optionsLimitIncreaser.value;
299
+ });
300
+
301
+ /**
302
+ * Amount of selected options exceeding the limit
303
+ * determined by "multipleBlocksLimit" prop
304
+ * @function
305
+ * @returns {number|null} amount
306
+ */
307
+ const overLimitOptionsCount = computed(() => {
308
+ if (selectedOptions.value.length <= multipleBlocksLimit.value) return null;
309
+
310
+ return selectedOptions.value.length - multipleBlocksLimit.value;
311
+ });
312
+
313
+ /**
314
+ * Determines whether to show loader icon if "loading" prop equals true
315
+ * or show multiple option blocks as usual
316
+ * @function
317
+ * @returns {boolean} restriction
318
+ */
319
+ const showLoaderIcon = computed(() => {
320
+ return showDeselectIconLoader.value ? loading.value : false;
321
+ });
322
+
323
+ /**
324
+ * If limit of selected options was achieved restricts further
325
+ * extension of options container if "multiple" prop equals true
326
+ * @function
327
+ * @param {Array} - array of selected options
328
+ */
329
+ watch(selectedOptions, (value) => {
330
+ if (!value.length || value.length <= multipleBlocksLimit.value) {
331
+ optionsLimitIncreaser.value = multipleBlocksLimit.value;
332
+ }
333
+ }, { deep: true });
334
+
335
+ /**
336
+ * Deselects option by users click on its element cancel icon
337
+ * if "multiple" prop equals true
338
+ * @function
339
+ * @emits extended:deselect-option
340
+ * @param {number} index - index of deselected option
341
+ */
342
+ const deselectBlock = (index) => {
343
+ if (loading.value || disabled.value) return;
344
+
345
+ emitter.value.emit("extended:deselect-option", { index });
346
+ };
347
+
348
+ /**
349
+ * Shows next hidden options
350
+ * This behavior restricts by "toggleMultipleBlocksLimit" prop
351
+ * if "multiple" prop equals true
352
+ * @function
353
+ * @emits extended:increase-display
354
+ */
355
+ const showMoreOptions = () => {
356
+ optionsLimitIncreaser.value += increaseDisplayBy.value;
357
+ emitter.value.emit("extended:increase-display", optionsLimitIncreaser.value);
358
+ };
359
+
360
+ /**
361
+ * "onBeforeMount" hook of ExtendedMultiselectMultiple component
362
+ */
363
+ onBeforeMount(() => {
364
+ optionsLimitIncreaser.value = multipleBlocksLimit.value;
365
+ });
366
366
  </script>