vue3-extended-multiselect 0.1.2 → 0.1.3

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 (40) hide show
  1. package/.eslintrc.js +29 -29
  2. package/.github/workflows/publish.yml +41 -0
  3. package/.nvmrc +0 -0
  4. package/CHANGELOG.md +47 -43
  5. package/LICENSE +21 -21
  6. package/README.md +116 -116
  7. package/index.js +2 -2
  8. package/jest.config.js +57 -57
  9. package/package.json +46 -46
  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 +142 -142
  20. package/src/components/ExtendedMultiselectInput.vue +618 -618
  21. package/src/components/ExtendedMultiselectLoader.vue +176 -176
  22. package/src/components/ExtendedMultiselectMultiple.vue +291 -291
  23. package/src/components/ExtendedMultiselectOptions.vue +1087 -1087
  24. package/src/components/ExtendedMultiselectToggle.vue +254 -254
  25. package/src/components/Vue3ExtendedMultiselect.vue +1651 -1651
  26. package/src/composition/cancel.js +30 -30
  27. package/src/composition/labels.js +39 -39
  28. package/src/composition/preselected-options.js +66 -66
  29. package/src/composition/search-value.js +33 -33
  30. package/src/composition/sizes.js +42 -42
  31. package/src/composition/toggle.js +33 -33
  32. package/src/sets/sets.js +99 -99
  33. package/src/styles/animations.css +19 -19
  34. package/src/styles/main.css +433 -433
  35. package/src/styles/variables.css +41 -41
  36. package/tests/unit/events.spec.js +135 -135
  37. package/tests/unit/props.spec.js +1040 -1040
  38. package/tests/utils/mount.js +37 -37
  39. package/tests/utils/utils.js +20 -20
  40. package/typings/vue3-extended-multiselect.d.ts +33 -33
@@ -1,31 +1,31 @@
1
- import emitter from 'tiny-emitter/instance';
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", null, true);
21
-
22
- if (!showSearchField.value) return;
23
-
24
- emitter.emit("extended:clean-options", selectedOptions.value);
25
-
26
- setSearchValue(null);
27
- setSearchPattern(null);
28
- };
29
-
30
- return { cancel };
1
+ import emitter from 'tiny-emitter/instance';
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", null, true);
21
+
22
+ if (!showSearchField.value) return;
23
+
24
+ emitter.emit("extended:clean-options", selectedOptions.value);
25
+
26
+ setSearchValue(null);
27
+ setSearchPattern(null);
28
+ };
29
+
30
+ return { cancel };
31
31
  }
@@ -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,34 +1,34 @@
1
- import { computed, readonly } from "vue";
2
-
3
- import emitter from 'tiny-emitter/instance';
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
- };
1
+ import { computed, readonly } from "vue";
2
+
3
+ import emitter from 'tiny-emitter/instance';
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
+ };
34
34
  }