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,34 +1,39 @@
1
- import emitter from "../events/emitter";
2
-
3
- import useSearchValue from './search-value';
4
-
5
- export default function useCancel(disabled, showSearchField, selectedOptions, emitterUniqueId) {
6
- /**
7
- * Removes all selected options or single selected option
8
- * when "multiple" prop equals false
9
- * @function
10
- * @emits extended:skip-block-blur-zeroing
11
- * @emits extended:deselect-option
12
- * @emits extended:clean-options
13
- */
14
- const cancel = () => {
15
- const { setSearchValue, setSearchPattern } = useSearchValue();
16
-
17
- if (disabled.value) return;
18
-
19
- emitter.emit(`extended:skip-block-blur-zeroing-${emitterUniqueId.value}`);
20
- emitter.emit(`extended:deselect-option-${emitterUniqueId.value}`, {
21
- index: null,
22
- clearAll: true,
23
- });
24
-
25
- if (!showSearchField.value) return;
26
-
27
- emitter.emit(`extended:clean-options-${emitterUniqueId.value}`, selectedOptions.value);
28
-
29
- setSearchValue(null);
30
- setSearchPattern(null);
31
- };
32
-
33
- return { cancel };
1
+ import emitter from "../events/emitter";
2
+
3
+ import useSearchValue from './search-value';
4
+
5
+ export default function useCancel(
6
+ disabled,
7
+ showSearchField,
8
+ selectedOptions,
9
+ emitterUniqueId,
10
+ setSearchValue,
11
+ setSearchPattern,
12
+ ) {
13
+ /**
14
+ * Removes all selected options or single selected option
15
+ * when "multiple" prop equals false
16
+ * @function
17
+ * @emits extended:skip-block-blur-zeroing
18
+ * @emits extended:deselect-option
19
+ * @emits extended:clean-options
20
+ */
21
+ const cancel = () => {
22
+ if (disabled.value) return;
23
+
24
+ emitter.emit(`extended:skip-block-blur-zeroing-${emitterUniqueId.value}`);
25
+ emitter.emit(`extended:deselect-option-${emitterUniqueId.value}`, {
26
+ index: null,
27
+ clearAll: true,
28
+ });
29
+
30
+ if (!showSearchField.value) return;
31
+
32
+ emitter.emit(`extended:clean-options-${emitterUniqueId.value}`, selectedOptions.value);
33
+
34
+ setSearchValue(null);
35
+ setSearchPattern(null);
36
+ };
37
+
38
+ return { cancel };
34
39
  }
@@ -1,17 +1,17 @@
1
- export default function useImagePath() {
2
-
3
- const createImagePath = (image) => {
4
- const hasRequire = typeof require !== "undefined";
5
- if (hasRequire) {
6
- return require(`../assets/${image}`);
7
- } else {
8
- try {
9
- return new URL(`../assets/${image}`, import.meta.url).href;
10
- } catch(error) {
11
- throw new ReferenceError("import.meta.url is available in «esnext» libtype only");
12
- }
13
- }
14
- };
15
-
16
- return { createImagePath };
1
+ export default function useImagePath() {
2
+
3
+ const createImagePath = (image) => {
4
+ const hasRequire = typeof require !== "undefined";
5
+ if (hasRequire) {
6
+ return require(`../assets/${image}`);
7
+ } else {
8
+ try {
9
+ return new URL(`../assets/${image}`, import.meta.url).href;
10
+ } catch(error) {
11
+ throw new ReferenceError("import.meta.url is available in «esnext» libtype only");
12
+ }
13
+ }
14
+ };
15
+
16
+ return { createImagePath };
17
17
  }
@@ -1,42 +1,42 @@
1
- export default function useLabels(
2
- label,
3
- createCustomOptionLabel,
4
- emptyObjectsPlaceholder,
5
- ) {
6
- /**
7
- * Creates label of any kind of option
8
- * @function
9
- * @param {string} label - label field in options of type "object"
10
- * @param {option} UnionPropType
11
- * @returns {string} label
12
- */
13
- const optionCreateLabel = (option) => {
14
- const isFunction = typeof option === "function";
15
-
16
- if (!option && isFunction) return "";
17
-
18
- const customOptionLabel = createCustomOptionLabel.value(option);
19
-
20
- if (customOptionLabel) return customOptionLabel;
21
-
22
- if (Array.isArray(option) && option.length > 0) {
23
- return option.join(", ");
24
- }
25
-
26
- if (typeof option !== "object") return option.toString();
27
-
28
- if (Object.keys(option).length === 0) {
29
- return emptyObjectsPlaceholder.value;
30
- }
31
-
32
- const hasLabel = Object.getOwnPropertyNames(option).includes(label.value);
33
-
34
- if (hasLabel) {
35
- return typeof option[label.value] === "object" ? JSON.stringify(option[label.value]) : option[label.value];
36
- }
37
-
38
- return "";
39
- };
40
-
41
- return { optionCreateLabel };
1
+ export default function useLabels(
2
+ label,
3
+ createCustomOptionLabel,
4
+ emptyObjectsPlaceholder,
5
+ ) {
6
+ /**
7
+ * Creates label of any kind of option
8
+ * @function
9
+ * @param {string} label - label field in options of type "object"
10
+ * @param {option} UnionPropType
11
+ * @returns {string} label
12
+ */
13
+ const optionCreateLabel = (option) => {
14
+ const isFunction = typeof option === "function";
15
+
16
+ if (!option && isFunction) return "";
17
+
18
+ const customOptionLabel = createCustomOptionLabel.value(option);
19
+
20
+ if (customOptionLabel) return customOptionLabel;
21
+
22
+ if (Array.isArray(option) && option.length > 0) {
23
+ return option.join(", ");
24
+ }
25
+
26
+ if (typeof option !== "object") return option.toString();
27
+
28
+ if (Object.keys(option).length === 0) {
29
+ return emptyObjectsPlaceholder.value;
30
+ }
31
+
32
+ const hasLabel = Object.getOwnPropertyNames(option).includes(label.value);
33
+
34
+ if (hasLabel) {
35
+ return typeof option[label.value] === "object" ? JSON.stringify(option[label.value]) : option[label.value];
36
+ }
37
+
38
+ return "";
39
+ };
40
+
41
+ return { optionCreateLabel };
42
42
  }
@@ -1,68 +1,68 @@
1
- export default function usePreselectedOptions(
2
- label,
3
- emptyObjectsPlaceholder,
4
- showInsertWarnings,
5
- ) {
6
- /**
7
- * Creates string label for any kind of option
8
- * @function
9
- * @param {string} label - label field in options of type "object"
10
- * @param {boolean} isObjectOrArray - determines whether option is of type "object" or instance of Array
11
- * @param {UnionPropType} option - option which needs label
12
- * @returns {string} label
13
- */
14
- const createLabel = (isObjectOrArray, option) => {
15
- let createdLabel;
16
-
17
- if (isObjectOrArray) {
18
- if (Array.isArray(option) && option.length > 0) {
19
- createdLabel = option.join(", ");
20
- } else {
21
- createdLabel = typeof option[label.value] === "object"
22
- ? JSON.stringify(option[label.value])
23
- : option[label.value];
24
- }
25
-
26
- if (Object.keys(option).length === 0) {
27
- createdLabel = emptyObjectsPlaceholder.value;
28
- }
29
- } else {
30
- createdLabel = option.toString();
31
- }
32
-
33
- return createdLabel;
34
- };
35
-
36
- /**
37
- * Restricts wrong types of options in options list
38
- * @method
39
- * @param {UnionPropType} option - option to restrict
40
- * @returns {boolean} restriction
41
- */
42
- const optionTypeRestrictor = (option) => {
43
- if (!option) return false;
44
-
45
- const isObjectArrayInstance = Object.getPrototypeOf(option).constructor.name
46
- !== "Object"
47
- && Object.getPrototypeOf(option).constructor.name !== "Array";
48
- const isAnyInstance = typeof option === "object" && isObjectArrayInstance;
49
- const isSymbol = typeof option === "symbol";
50
-
51
- if (isSymbol && showInsertWarnings.value) {
52
- console.warn("vue-extended-multiselect: option can not be of type «symbol»");
53
- }
54
-
55
- if (isAnyInstance && showInsertWarnings.value) {
56
- console.warn("vue-extended-multiselect: option can not be an instance of any constructor function");
57
- }
58
-
59
- if (isSymbol || isAnyInstance) return false;
60
-
61
- return true;
62
- };
63
-
64
- return {
65
- createLabel,
66
- optionTypeRestrictor,
67
- };
1
+ export default function usePreselectedOptions(
2
+ label,
3
+ emptyObjectsPlaceholder,
4
+ showInsertWarnings,
5
+ ) {
6
+ /**
7
+ * Creates string label for any kind of option
8
+ * @function
9
+ * @param {string} label - label field in options of type "object"
10
+ * @param {boolean} isObjectOrArray - determines whether option is of type "object" or instance of Array
11
+ * @param {UnionPropType} option - option which needs label
12
+ * @returns {string} label
13
+ */
14
+ const createLabel = (isObjectOrArray, option) => {
15
+ let createdLabel;
16
+
17
+ if (isObjectOrArray) {
18
+ if (Array.isArray(option) && option.length > 0) {
19
+ createdLabel = option.join(", ");
20
+ } else {
21
+ createdLabel = typeof option[label.value] === "object"
22
+ ? JSON.stringify(option[label.value])
23
+ : option[label.value];
24
+ }
25
+
26
+ if (Object.keys(option).length === 0) {
27
+ createdLabel = emptyObjectsPlaceholder.value;
28
+ }
29
+ } else {
30
+ createdLabel = option.toString();
31
+ }
32
+
33
+ return createdLabel;
34
+ };
35
+
36
+ /**
37
+ * Restricts wrong types of options in options list
38
+ * @method
39
+ * @param {UnionPropType} option - option to restrict
40
+ * @returns {boolean} restriction
41
+ */
42
+ const optionTypeRestrictor = (option) => {
43
+ if (!option) return false;
44
+
45
+ const isObjectArrayInstance = Object.getPrototypeOf(option).constructor.name
46
+ !== "Object"
47
+ && Object.getPrototypeOf(option).constructor.name !== "Array";
48
+ const isAnyInstance = typeof option === "object" && isObjectArrayInstance;
49
+ const isSymbol = typeof option === "symbol";
50
+
51
+ if (isSymbol && showInsertWarnings.value) {
52
+ console.warn("vue-extended-multiselect: option can not be of type «symbol»");
53
+ }
54
+
55
+ if (isAnyInstance && showInsertWarnings.value) {
56
+ console.warn("vue-extended-multiselect: option can not be an instance of any constructor function");
57
+ }
58
+
59
+ if (isSymbol || isAnyInstance) return false;
60
+
61
+ return true;
62
+ };
63
+
64
+ return {
65
+ createLabel,
66
+ optionTypeRestrictor,
67
+ };
68
68
  }
@@ -1,34 +1,34 @@
1
- import { reactive, readonly } from "vue";
2
-
3
- export default function useSearchValue() {
4
- /**
5
- * @property {string|null} searchValue - value of search field
6
- * @property {string|null} searchPattern - pattern of inner search for available options
7
- */
8
- const searchState = reactive({
9
- searchValue: null,
10
- searchPattern: null,
11
- });
12
-
13
- /**
14
- * @function setSearchValue
15
- * @param {string|null} value - new value of search field
16
- */
17
- const setSearchValue = (value) => {
18
- searchState.searchValue = value;
19
- };
20
-
21
- /**
22
- * @function setSearchPattern
23
- * @param {string|null} pattern - new pattern of inner search for available options
24
- */
25
- const setSearchPattern = (pattern) => {
26
- searchState.searchPattern = pattern;
27
- };
28
-
29
- return {
30
- searchState: readonly(searchState),
31
- setSearchValue,
32
- setSearchPattern,
33
- };
1
+ import { reactive, readonly } from "vue";
2
+
3
+ export default function useSearchValue() {
4
+ /**
5
+ * @property {string|null} searchValue - value of search field
6
+ * @property {string|null} searchPattern - pattern of inner search for available options
7
+ */
8
+ const searchState = reactive({
9
+ searchValue: null,
10
+ searchPattern: null,
11
+ });
12
+
13
+ /**
14
+ * @function setSearchValue
15
+ * @param {string|null} value - new value of search field
16
+ */
17
+ const setSearchValue = (value) => {
18
+ searchState.searchValue = value;
19
+ };
20
+
21
+ /**
22
+ * @function setSearchPattern
23
+ * @param {string|null} pattern - new pattern of inner search for available options
24
+ */
25
+ const setSearchPattern = (pattern) => {
26
+ searchState.searchPattern = pattern;
27
+ };
28
+
29
+ return {
30
+ searchState: readonly(searchState),
31
+ setSearchValue,
32
+ setSearchPattern,
33
+ };
34
34
  }
@@ -1,43 +1,43 @@
1
- import {
2
- computed,
3
- getCurrentInstance,
4
- readonly,
5
- } from "vue";
6
-
7
- export default function useSizes(iconSize) {
8
- /**
9
- * Defines classes for each kind of icon
10
- * @function
11
- * @returns {string} class
12
- */
13
- const iconSizeClass = computed(() => {
14
- let basicIconSize = "extended__multiselect";
15
-
16
- switch(getCurrentInstance().type.__name) {
17
- case "ExtendedMultiselectLoader":
18
- basicIconSize += "-loader_icon";
19
- break;
20
- case "ExtendedMultiselectToggle":
21
- basicIconSize += "-toggle_icon";
22
- break;
23
- case "ExtendedMultiselectCancel":
24
- basicIconSize += "-cancel_icon";
25
- break;
26
- default:
27
- basicIconSize += "-toggle_icon";
28
- }
29
-
30
- switch(iconSize.value) {
31
- case "large":
32
- return `${basicIconSize}-large`;
33
- case "medium":
34
- return `${basicIconSize}-medium`;
35
- case "small":
36
- return `${basicIconSize}-small`;
37
- default:
38
- return `${basicIconSize}-large`;
39
- }
40
- });
41
-
42
- return { iconSizeClass: readonly(iconSizeClass) };
1
+ import {
2
+ computed,
3
+ getCurrentInstance,
4
+ readonly,
5
+ } from "vue";
6
+
7
+ export default function useSizes(iconSize) {
8
+ /**
9
+ * Defines classes for each kind of icon
10
+ * @function
11
+ * @returns {string} class
12
+ */
13
+ const iconSizeClass = computed(() => {
14
+ let basicIconSize = "extended__multiselect";
15
+
16
+ switch(getCurrentInstance().type.__name) {
17
+ case "ExtendedMultiselectLoader":
18
+ basicIconSize += "-loader_icon";
19
+ break;
20
+ case "ExtendedMultiselectToggle":
21
+ basicIconSize += "-toggle_icon";
22
+ break;
23
+ case "ExtendedMultiselectCancel":
24
+ basicIconSize += "-cancel_icon";
25
+ break;
26
+ default:
27
+ basicIconSize += "-toggle_icon";
28
+ }
29
+
30
+ switch(iconSize.value) {
31
+ case "large":
32
+ return `${basicIconSize}-large`;
33
+ case "medium":
34
+ return `${basicIconSize}-medium`;
35
+ case "small":
36
+ return `${basicIconSize}-small`;
37
+ default:
38
+ return `${basicIconSize}-large`;
39
+ }
40
+ });
41
+
42
+ return { iconSizeClass: readonly(iconSizeClass) };
43
43
  }
@@ -1,34 +1,34 @@
1
- import { computed, readonly } from "vue";
2
-
3
- import emitter from "../events/emitter"
4
-
5
- export default function useToggle(loading, disabled, internalLoader, emitterUniqueId) {
6
- /**
7
- * Toggles classes of slots if "loading"
8
- * or "disabled" props equals true
9
- * @function
10
- * @returns {string} class
11
- */
12
- const toggleSlotClass = computed(() => {
13
- return loading.value || disabled.value || (internalLoader && internalLoader.value)
14
- ? "extended__multiselect-toggle--disabled"
15
- : "extended__multiselect-toggle";
16
- });
17
-
18
- /**
19
- * Emits an event which listeners will toggle options list
20
- * @function
21
- * @emits extended:toggle-options
22
- * @param {MouseEvent|KeyboardEvent} event - MouseEvent or KeyboardEvent instance
23
- */
24
- const toggleOptionsList = (event) => {
25
- if (event && event.code === "Tab") return;
26
-
27
- emitter.emit(`extended:toggle-options-${emitterUniqueId.value}`);
28
- };
29
-
30
- return {
31
- toggleSlotClass: readonly(toggleSlotClass),
32
- toggleOptionsList,
33
- };
1
+ import { computed, readonly } from "vue";
2
+
3
+ import emitter from "../events/emitter"
4
+
5
+ export default function useToggle(loading, disabled, internalLoader, emitterUniqueId) {
6
+ /**
7
+ * Toggles classes of slots if "loading"
8
+ * or "disabled" props equals true
9
+ * @function
10
+ * @returns {string} class
11
+ */
12
+ const toggleSlotClass = computed(() => {
13
+ return loading.value || disabled.value || (internalLoader && internalLoader.value)
14
+ ? "extended__multiselect-toggle--disabled"
15
+ : "extended__multiselect-toggle";
16
+ });
17
+
18
+ /**
19
+ * Emits an event which listeners will toggle options list
20
+ * @function
21
+ * @emits extended:toggle-options
22
+ * @param {MouseEvent|KeyboardEvent} event - MouseEvent or KeyboardEvent instance
23
+ */
24
+ const toggleOptionsList = (event) => {
25
+ if (event && event.code === "Tab") return;
26
+
27
+ emitter.emit(`extended:toggle-options-${emitterUniqueId.value}`);
28
+ };
29
+
30
+ return {
31
+ toggleSlotClass: readonly(toggleSlotClass),
32
+ toggleOptionsList,
33
+ };
34
34
  }
@@ -0,0 +1,32 @@
1
+ class LocalEmitter {
2
+
3
+ _eventsStack = {
4
+ payload: null,
5
+ };
6
+ _eventsRegistered = [];
7
+
8
+ emit(eventName, payload = null) {
9
+ const proxies = this._eventsRegistered.filter(event => event.eventName === eventName);
10
+
11
+ if (!proxies.length) return;
12
+
13
+ proxies.forEach((proxy) => {
14
+ this._eventsStack.payload = payload;
15
+ proxy.proxy.payload = payload;
16
+ });
17
+ }
18
+
19
+ on(eventName, callback) {
20
+ this._eventsRegistered.push({
21
+ eventName,
22
+ proxy: new Proxy(this._eventsStack, {
23
+ set(target) {
24
+ callback(target.payload);
25
+ return target;
26
+ },
27
+ }),
28
+ });
29
+ }
30
+ }
31
+
32
+ export default LocalEmitter;
@@ -1,3 +1,3 @@
1
- import mitt from 'mitt';
2
-
3
- export default mitt();
1
+ import LocalEmitter from "./LocalEmitter";
2
+
3
+ export default new LocalEmitter();