vue3-extended-multiselect 0.3.0 → 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.
Files changed (44) hide show
  1. package/.eslintrc.js +35 -29
  2. package/.github/workflows/publish.yml +41 -41
  3. package/CHANGELOG.md +91 -72
  4. package/LICENSE +21 -21
  5. package/README.md +261 -262
  6. package/babel.config.js +3 -2
  7. package/index.js +2 -2
  8. package/jest.config.js +57 -57
  9. package/package.json +47 -48
  10. package/src/assets/base-arrow.svg +70 -70
  11. package/src/assets/cancel.svg +34 -34
  12. package/src/assets/circle-arrow.svg +7 -7
  13. package/src/assets/double-arrow.svg +39 -39
  14. package/src/assets/inner-arrow.svg +8 -8
  15. package/src/assets/loader.svg +5 -5
  16. package/src/assets/triangle-arrow.svg +72 -72
  17. package/src/assets/triangle-circle-arrow.svg +38 -38
  18. package/src/assets/wide-arrow.svg +72 -72
  19. package/src/components/ExtendedMultiselectCancel.vue +148 -145
  20. package/src/components/ExtendedMultiselectInput.vue +617 -617
  21. package/src/components/ExtendedMultiselectLoader.vue +182 -176
  22. package/src/components/ExtendedMultiselectMultiple.vue +295 -291
  23. package/src/components/ExtendedMultiselectOptions.vue +1091 -1088
  24. package/src/components/ExtendedMultiselectToggle.vue +261 -261
  25. package/src/components/Vue3ExtendedMultiselect.vue +1661 -1661
  26. package/src/composition/cancel.js +33 -28
  27. package/src/composition/image-path.js +17 -0
  28. package/src/composition/labels.js +39 -39
  29. package/src/composition/preselected-options.js +66 -66
  30. package/src/composition/search-value.js +33 -33
  31. package/src/composition/sizes.js +42 -42
  32. package/src/composition/toggle.js +33 -31
  33. package/src/events/emitter.js +3 -0
  34. package/src/sets/sets.js +99 -99
  35. package/src/styles/animations.css +18 -18
  36. package/src/styles/main.css +432 -432
  37. package/src/styles/variables.css +47 -48
  38. package/tests/unit/events.spec.js +135 -135
  39. package/tests/unit/props.spec.js +1040 -1040
  40. package/tests/utils/mount.js +37 -37
  41. package/tests/utils/utils.js +20 -20
  42. package/typings/vue3-extended-multiselect.d.ts +42 -42
  43. package/.eslintignore +0 -2
  44. package/vite.config.js +0 -7
@@ -1,29 +1,34 @@
1
- import useSearchValue from './search-value';
2
-
3
- export default function useCancel(disabled, showSearchField, selectedOptions, emitter) {
4
- /**
5
- * Removes all selected options or single selected option
6
- * when "multiple" prop equals false
7
- * @function
8
- * @emits extended:skip-block-blur-zeroing
9
- * @emits extended:deselect-option
10
- * @emits extended:clean-options
11
- */
12
- const cancel = () => {
13
- const { setSearchValue, setSearchPattern } = useSearchValue();
14
-
15
- if (disabled.value) return;
16
-
17
- emitter.emit("extended:skip-block-blur-zeroing");
18
- emitter.emit("extended:deselect-option", null, true);
19
-
20
- if (!showSearchField.value) return;
21
-
22
- emitter.emit("extended:clean-options", selectedOptions.value);
23
-
24
- setSearchValue(null);
25
- setSearchPattern(null);
26
- };
27
-
28
- return { cancel };
1
+ import emitter from "../events/emitter";
2
+
3
+ import useSearchValue from './search-value';
4
+
5
+ export default function useCancel(disabled, showSearchField, selectedOptions) {
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");
20
+ emitter.emit("extended:deselect-option", {
21
+ index: null,
22
+ clearAll: true,
23
+ });
24
+
25
+ if (!showSearchField.value) return;
26
+
27
+ emitter.emit("extended:clean-options", selectedOptions.value);
28
+
29
+ setSearchValue(null);
30
+ setSearchPattern(null);
31
+ };
32
+
33
+ return { cancel };
29
34
  }
@@ -0,0 +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 };
17
+ }
@@ -1,40 +1,40 @@
1
- export default function useLabels(
2
- createCustomOptionLabel,
3
- emptyObjectsPlaceholder,
4
- ) {
5
- /**
6
- * Creates label of any kind of option
7
- * @function
8
- * @param {option} UnionPropType
9
- * @returns {string} label
10
- */
11
- const optionCreateLabel = (option) => {
12
- const isFunction = typeof option === "function";
13
-
14
- if (!option && isFunction) return "";
15
-
16
- const customOptionLabel = createCustomOptionLabel.value(option);
17
-
18
- if (customOptionLabel) return customOptionLabel;
19
-
20
- if (Array.isArray(option) && option.length > 0) {
21
- return option.join(", ");
22
- }
23
-
24
- if (typeof option !== "object") return option.toString();
25
-
26
- if (Object.keys(option).length === 0) {
27
- return emptyObjectsPlaceholder.value;
28
- }
29
-
30
- const hasLabel = Object.getOwnPropertyNames(option).includes("label");
31
-
32
- if (hasLabel) {
33
- return typeof option.label === "object" ? JSON.stringify(option.label) : option.label;
34
- }
35
-
36
- return "";
37
- };
38
-
39
- return { optionCreateLabel };
1
+ export default function useLabels(
2
+ createCustomOptionLabel,
3
+ emptyObjectsPlaceholder,
4
+ ) {
5
+ /**
6
+ * Creates label of any kind of option
7
+ * @function
8
+ * @param {option} UnionPropType
9
+ * @returns {string} label
10
+ */
11
+ const optionCreateLabel = (option) => {
12
+ const isFunction = typeof option === "function";
13
+
14
+ if (!option && isFunction) return "";
15
+
16
+ const customOptionLabel = createCustomOptionLabel.value(option);
17
+
18
+ if (customOptionLabel) return customOptionLabel;
19
+
20
+ if (Array.isArray(option) && option.length > 0) {
21
+ return option.join(", ");
22
+ }
23
+
24
+ if (typeof option !== "object") return option.toString();
25
+
26
+ if (Object.keys(option).length === 0) {
27
+ return emptyObjectsPlaceholder.value;
28
+ }
29
+
30
+ const hasLabel = Object.getOwnPropertyNames(option).includes("label");
31
+
32
+ if (hasLabel) {
33
+ return typeof option.label === "object" ? JSON.stringify(option.label) : option.label;
34
+ }
35
+
36
+ return "";
37
+ };
38
+
39
+ return { optionCreateLabel };
40
40
  }
@@ -1,67 +1,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 {boolean} isObjectOrArray - determines whether option is of type "object" or instance of Array
10
- * @param {UnionPropType} option - option which needs label
11
- * @returns {string} label
12
- */
13
- const createLabel = (isObjectOrArray, option) => {
14
- let createdLabel;
15
-
16
- if (isObjectOrArray) {
17
- if (Array.isArray(option) && option.length > 0) {
18
- createdLabel = option.join(", ");
19
- } else {
20
- createdLabel = typeof option[label.value] === "object"
21
- ? JSON.stringify(option[label.value])
22
- : option[label.value];
23
- }
24
-
25
- if (Object.keys(option).length === 0) {
26
- createdLabel = emptyObjectsPlaceholder.value;
27
- }
28
- } else {
29
- createdLabel = option.toString();
30
- }
31
-
32
- return createdLabel;
33
- };
34
-
35
- /**
36
- * Restricts wrong types of options in options list
37
- * @method
38
- * @param {UnionPropType} option - option to restrict
39
- * @returns {boolean} restriction
40
- */
41
- const optionTypeRestrictor = (option) => {
42
- if (!option) return false;
43
-
44
- const isObjectArrayInstance = Object.getPrototypeOf(option).constructor.name
45
- !== "Object"
46
- && Object.getPrototypeOf(option).constructor.name !== "Array";
47
- const isAnyInstance = typeof option === "object" && isObjectArrayInstance;
48
- const isSymbol = typeof option === "symbol";
49
-
50
- if (isSymbol && showInsertWarnings.value) {
51
- console.warn("vue-extended-multiselect: option can not be of type «symbol»");
52
- }
53
-
54
- if (isAnyInstance && showInsertWarnings.value) {
55
- console.warn("vue-extended-multiselect: option can not be an instance of any constructor function");
56
- }
57
-
58
- if (isSymbol || isAnyInstance) return false;
59
-
60
- return true;
61
- };
62
-
63
- return {
64
- createLabel,
65
- optionTypeRestrictor,
66
- };
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 {boolean} isObjectOrArray - determines whether option is of type "object" or instance of Array
10
+ * @param {UnionPropType} option - option which needs label
11
+ * @returns {string} label
12
+ */
13
+ const createLabel = (isObjectOrArray, option) => {
14
+ let createdLabel;
15
+
16
+ if (isObjectOrArray) {
17
+ if (Array.isArray(option) && option.length > 0) {
18
+ createdLabel = option.join(", ");
19
+ } else {
20
+ createdLabel = typeof option[label.value] === "object"
21
+ ? JSON.stringify(option[label.value])
22
+ : option[label.value];
23
+ }
24
+
25
+ if (Object.keys(option).length === 0) {
26
+ createdLabel = emptyObjectsPlaceholder.value;
27
+ }
28
+ } else {
29
+ createdLabel = option.toString();
30
+ }
31
+
32
+ return createdLabel;
33
+ };
34
+
35
+ /**
36
+ * Restricts wrong types of options in options list
37
+ * @method
38
+ * @param {UnionPropType} option - option to restrict
39
+ * @returns {boolean} restriction
40
+ */
41
+ const optionTypeRestrictor = (option) => {
42
+ if (!option) return false;
43
+
44
+ const isObjectArrayInstance = Object.getPrototypeOf(option).constructor.name
45
+ !== "Object"
46
+ && Object.getPrototypeOf(option).constructor.name !== "Array";
47
+ const isAnyInstance = typeof option === "object" && isObjectArrayInstance;
48
+ const isSymbol = typeof option === "symbol";
49
+
50
+ if (isSymbol && showInsertWarnings.value) {
51
+ console.warn("vue-extended-multiselect: option can not be of type «symbol»");
52
+ }
53
+
54
+ if (isAnyInstance && showInsertWarnings.value) {
55
+ console.warn("vue-extended-multiselect: option can not be an instance of any constructor function");
56
+ }
57
+
58
+ if (isSymbol || isAnyInstance) return false;
59
+
60
+ return true;
61
+ };
62
+
63
+ return {
64
+ createLabel,
65
+ optionTypeRestrictor,
66
+ };
67
67
  }
@@ -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,32 +1,34 @@
1
- import { computed, readonly } from "vue";
2
-
3
- export default function useToggle(loading, disabled, internalLoader, emitter) {
4
- /**
5
- * Toggles classes of slots if "loading"
6
- * or "disabled" props equals true
7
- * @function
8
- * @returns {string} class
9
- */
10
- const toggleSlotClass = computed(() => {
11
- return loading.value || disabled.value || (internalLoader && internalLoader.value)
12
- ? "extended__multiselect-toggle--disabled"
13
- : "extended__multiselect-toggle";
14
- });
15
-
16
- /**
17
- * Emits an event which listeners will toggle options list
18
- * @function
19
- * @emits extended:toggle-options
20
- * @param {MouseEvent|KeyboardEvent} event - MouseEvent or KeyboardEvent instance
21
- */
22
- const toggleOptionsList = (event) => {
23
- if (event && event.code === "Tab") return;
24
-
25
- emitter.emit("extended:toggle-options");
26
- };
27
-
28
- return {
29
- toggleSlotClass: readonly(toggleSlotClass),
30
- toggleOptionsList,
31
- };
1
+ import { computed, readonly } from "vue";
2
+
3
+ import emitter from "../events/emitter"
4
+
5
+ export default function useToggle(loading, disabled, internalLoader) {
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");
28
+ };
29
+
30
+ return {
31
+ toggleSlotClass: readonly(toggleSlotClass),
32
+ toggleOptionsList,
33
+ };
32
34
  }
@@ -0,0 +1,3 @@
1
+ import mitt from 'mitt';
2
+
3
+ export default mitt();