vue3-extended-multiselect 1.2.4 → 1.4.1

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