vue3-extended-multiselect 0.2.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +35 -29
- package/.github/workflows/publish.yml +41 -41
- package/CHANGELOG.md +91 -65
- package/LICENSE +21 -21
- package/README.md +261 -262
- package/babel.config.js +3 -2
- package/index.js +2 -2
- package/jest.config.js +57 -57
- package/package.json +47 -46
- package/src/assets/base-arrow.svg +70 -70
- package/src/assets/cancel.svg +34 -34
- package/src/assets/circle-arrow.svg +7 -7
- package/src/assets/double-arrow.svg +39 -39
- package/src/assets/inner-arrow.svg +8 -8
- package/src/assets/loader.svg +5 -5
- package/src/assets/triangle-arrow.svg +72 -72
- package/src/assets/triangle-circle-arrow.svg +38 -38
- package/src/assets/wide-arrow.svg +72 -72
- package/src/components/ExtendedMultiselectCancel.vue +148 -145
- package/src/components/ExtendedMultiselectInput.vue +617 -617
- package/src/components/ExtendedMultiselectLoader.vue +182 -176
- package/src/components/ExtendedMultiselectMultiple.vue +295 -291
- package/src/components/ExtendedMultiselectOptions.vue +1091 -1088
- package/src/components/ExtendedMultiselectToggle.vue +261 -261
- package/src/components/Vue3ExtendedMultiselect.vue +1661 -1661
- package/src/composition/cancel.js +33 -28
- package/src/composition/image-path.js +17 -0
- package/src/composition/labels.js +39 -39
- package/src/composition/preselected-options.js +66 -66
- package/src/composition/search-value.js +33 -33
- package/src/composition/sizes.js +42 -42
- package/src/composition/toggle.js +33 -31
- package/src/events/emitter.js +3 -0
- package/src/sets/sets.js +99 -99
- package/src/styles/animations.css +18 -18
- package/src/styles/main.css +432 -432
- package/src/styles/variables.css +47 -48
- package/tests/unit/events.spec.js +135 -135
- package/tests/unit/props.spec.js +1040 -1040
- package/tests/utils/mount.js +37 -37
- package/tests/utils/utils.js +20 -20
- package/typings/vue3-extended-multiselect.d.ts +42 -42
- package/.eslintignore +0 -2
|
@@ -1,292 +1,296 @@
|
|
|
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="
|
|
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 "
|
|
61
|
-
|
|
62
|
-
import
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
case "
|
|
191
|
-
return `${basicClassName}-
|
|
192
|
-
case "
|
|
193
|
-
return `${basicClassName}-
|
|
194
|
-
case "
|
|
195
|
-
return `${basicClassName}-
|
|
196
|
-
|
|
197
|
-
return `${basicClassName}-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
*
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
+
* Defines label for blocks with options of type "object"
|
|
87
|
+
* or Array instances which length/keys length equals 0
|
|
88
|
+
* @property {string} emptyObjectsPlaceholder
|
|
89
|
+
*/
|
|
90
|
+
emptyObjectsPlaceholder: {
|
|
91
|
+
type: String,
|
|
92
|
+
required: true,
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Limit of hidden options amount to be shown next
|
|
97
|
+
* @property {number} increaseDisplayBy
|
|
98
|
+
*/
|
|
99
|
+
increaseDisplayBy: {
|
|
100
|
+
type: Number,
|
|
101
|
+
required: true,
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Hides all deselect buttons if equals true
|
|
106
|
+
* @property {boolean} loading
|
|
107
|
+
*/
|
|
108
|
+
loading: {
|
|
109
|
+
type: Boolean,
|
|
110
|
+
required: true,
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Limit of option blocks amount
|
|
115
|
+
* @property {number} multipleBlocksLimit
|
|
116
|
+
*/
|
|
117
|
+
multipleBlocksLimit: {
|
|
118
|
+
type: Number,
|
|
119
|
+
default: null,
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Allows to increase limit of displayed selected option blocks
|
|
124
|
+
* @property {boolean} toggleMultipleBlocksLimit
|
|
125
|
+
*/
|
|
126
|
+
toggleMultipleBlocksLimit: {
|
|
127
|
+
type: Boolean,
|
|
128
|
+
required: true,
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Function that creates limit message for maximal of selected options
|
|
133
|
+
* @property {Function} multipleBlocksLimitMessage
|
|
134
|
+
*/
|
|
135
|
+
multipleBlocksLimitMessage: {
|
|
136
|
+
type: Function,
|
|
137
|
+
required: true,
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* List of selected options that will be shown as option blocks
|
|
142
|
+
* @property {Array} selectedOptions
|
|
143
|
+
*/
|
|
144
|
+
selectedOptions: {
|
|
145
|
+
type: Array,
|
|
146
|
+
required: true,
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Current theme of extended-multiselect
|
|
151
|
+
* used in class definition
|
|
152
|
+
* @property {string} themeType
|
|
153
|
+
*/
|
|
154
|
+
themeType: {
|
|
155
|
+
type: String,
|
|
156
|
+
required: true,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const {
|
|
161
|
+
createCustomOptionLabel,
|
|
162
|
+
disabled,
|
|
163
|
+
emptyObjectsPlaceholder,
|
|
164
|
+
increaseDisplayBy,
|
|
165
|
+
loading,
|
|
166
|
+
multipleBlocksLimit,
|
|
167
|
+
selectedOptions,
|
|
168
|
+
themeType,
|
|
169
|
+
toggleMultipleBlocksLimit,
|
|
170
|
+
} = toRefs(props);
|
|
171
|
+
|
|
172
|
+
const { createImagePath } = useImagePath();
|
|
173
|
+
|
|
174
|
+
const optionsLimitIncreaser = ref(null);
|
|
175
|
+
const increaserClass = ref("extended__multiselect-increaser");
|
|
176
|
+
const deselectImage = ref(createImagePath("cancel.svg"));
|
|
177
|
+
|
|
178
|
+
const { optionCreateLabel } = useLabels(createCustomOptionLabel, emptyObjectsPlaceholder);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Defines class for every selected option block
|
|
182
|
+
* depends on current theme of extended multiselect
|
|
183
|
+
* @function
|
|
184
|
+
* @returns {string} class
|
|
185
|
+
*/
|
|
186
|
+
const classes = computed(() => {
|
|
187
|
+
const basicClassName = "extended__multiselect--multiple";
|
|
188
|
+
|
|
189
|
+
switch(themeType.value) {
|
|
190
|
+
case "basic":
|
|
191
|
+
return `${basicClassName}-basic`;
|
|
192
|
+
case "slate-grey":
|
|
193
|
+
return `${basicClassName}-slate-grey`;
|
|
194
|
+
case "slate-blue":
|
|
195
|
+
return `${basicClassName}-slate-blue`;
|
|
196
|
+
case "teal":
|
|
197
|
+
return `${basicClassName}-teal`;
|
|
198
|
+
case "strict":
|
|
199
|
+
return `${basicClassName}-strict`;
|
|
200
|
+
default:
|
|
201
|
+
return `${basicClassName}-basic`;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Defines current limited amount of displayed option blocks
|
|
207
|
+
* @function
|
|
208
|
+
* @returns {Array} UnionPropType
|
|
209
|
+
*/
|
|
210
|
+
const limitRestriction = computed(() => {
|
|
211
|
+
if (!optionsLimitIncreaser.value) return selectedOptions.value;
|
|
212
|
+
|
|
213
|
+
return selectedOptions.value.filter((selectedOption, index) => {
|
|
214
|
+
const limit = typeof optionsLimitIncreaser.value === "number"
|
|
215
|
+
? optionsLimitIncreaser.value
|
|
216
|
+
: optionsLimitIncreaser.value.value;
|
|
217
|
+
|
|
218
|
+
return ++index <= limit;
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Determines whether user can increase limited amount of displayed option blocks
|
|
224
|
+
* @function
|
|
225
|
+
* @returns {boolean} possibility
|
|
226
|
+
*/
|
|
227
|
+
const optionIncreaserAvailable = computed(() => {
|
|
228
|
+
return toggleMultipleBlocksLimit.value && optionsLimitAchieved.value;
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Determines whether current limit of displayed option blocks amount
|
|
233
|
+
* was reached
|
|
234
|
+
* @function
|
|
235
|
+
* @returns {boolean} reaching
|
|
236
|
+
*/
|
|
237
|
+
const optionsLimitAchieved = computed(() => {
|
|
238
|
+
return optionsLimitIncreaser.value && selectedOptions.value.length > optionsLimitIncreaser.value;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Amount of selected options exceeding the limit
|
|
243
|
+
* determined by "multipleBlocksLimit" prop
|
|
244
|
+
* @function
|
|
245
|
+
* @returns {number|null} amount
|
|
246
|
+
*/
|
|
247
|
+
const overLimitOptionsCount = computed(() => {
|
|
248
|
+
if (selectedOptions.value.length <= multipleBlocksLimit.value) return null;
|
|
249
|
+
|
|
250
|
+
return selectedOptions.value.length - multipleBlocksLimit.value;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* If limit of selected options was achieved restricts further
|
|
255
|
+
* extension of options container if "multiple" prop equals true
|
|
256
|
+
* @function
|
|
257
|
+
* @param {Array} - array of selected options
|
|
258
|
+
*/
|
|
259
|
+
watch(selectedOptions, (value) => {
|
|
260
|
+
if (!value.length || value.length <= multipleBlocksLimit.value) {
|
|
261
|
+
optionsLimitIncreaser.value = multipleBlocksLimit.value;
|
|
262
|
+
}
|
|
263
|
+
}, { deep: true });
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Deselects option by users click on its element cancel icon
|
|
267
|
+
* if "multiple" prop equals true
|
|
268
|
+
* @function
|
|
269
|
+
* @emits extended:deselect-option
|
|
270
|
+
* @param {number} index - index of deselected option
|
|
271
|
+
*/
|
|
272
|
+
const deselectBlock = (index) => {
|
|
273
|
+
if (loading.value || disabled.value) return;
|
|
274
|
+
|
|
275
|
+
emitter.emit("extended:deselect-option", { index });
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Shows next hidden options
|
|
280
|
+
* This behavior restricts by "toggleMultipleBlocksLimit" prop
|
|
281
|
+
* if "multiple" prop equals true
|
|
282
|
+
* @function
|
|
283
|
+
* @emits extended:increase-display
|
|
284
|
+
*/
|
|
285
|
+
const showMoreOptions = () => {
|
|
286
|
+
optionsLimitIncreaser.value += increaseDisplayBy.value;
|
|
287
|
+
emitter.emit("extended:increase-display", optionsLimitIncreaser.value);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* "onBeforeMount" hook of ExtendedMultiselectMultiple component
|
|
292
|
+
*/
|
|
293
|
+
onBeforeMount(() => {
|
|
294
|
+
optionsLimitIncreaser.value = multipleBlocksLimit.value;
|
|
295
|
+
});
|
|
292
296
|
</script>
|