selectic 3.1.2 → 3.1.4
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/dist/selectic.common.js +129 -61
- package/dist/selectic.esm.js +129 -61
- package/doc/list.md +2 -1
- package/package.json +2 -1
- package/src/ExtendedList.tsx +40 -42
- package/src/MainInput.tsx +27 -4
- package/src/Store.tsx +64 -13
- package/src/css/selectic.css +3 -0
- package/src/index.tsx +21 -10
- package/test/Store/Store_creation.spec.js +74 -0
- package/test/Store/selectItem.spec.js +108 -22
- package/types/ExtendedList.d.ts +1 -1
- package/types/MainInput.d.ts +2 -1
- package/types/index.d.ts +1 -1
package/dist/selectic.common.js
CHANGED
|
@@ -32,7 +32,7 @@ function styleInject(css, ref) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
var css_248z = "/* {{{ Variables */\n\n:root {\n --selectic-font-size: 14px;\n --selectic-cursor-disabled: not-allowed;\n\n /* The main element */\n --selectic-color: #555555;\n --selectic-bg: #ffffff;\n\n /* The main element (when disabled) */\n --selectic-color-disabled: #787878;\n --selectic-bg-disabled: #eeeeee;\n\n /* The list */\n --selectic-panel-bg: #f0f0f0;\n --selectic-separator-bordercolor: #cccccc;\n /* --selectic-item-color: var(--selectic-color); /* Can be set in any CSS configuration */\n\n /* The current selected item */\n --selectic-selected-item-color: #428bca;\n\n /* When mouse is over items or by selecting with key arrows */\n --selectic-active-item-color: #ffffff;\n --selectic-active-item-bg: #66afe9;\n\n /* Selected values in main element */\n --selectic-value-bg: #f0f0f0;\n /* --selectic-more-items-bg: var(--selectic-info-bg); /* can be set in any CSS configuration */\n /* --selectic-more-items-color: var(--selectic-info-color); /* can be set in any CSS configuration */\n --selectic-more-items-bg-disabled: #cccccc;\n\n /* Information message */\n --selectic-info-bg: #5bc0de;\n --selectic-info-color: #ffffff;\n\n /* Error message */\n --selectic-error-bg: #b72c29;\n --selectic-error-color: #ffffff;\n\n /* XXX: Currently it is important to keep this size for a correct scroll\n * height estimation */\n --selectic-input-height: 30px;\n}\n\n/* }}} */\n/* {{{ Bootstrap equivalent style */\n\n.selectic .form-control {\n display: block;\n width: 100%;\n height: calc(var(--selectic-input-height) - 2px);\n font-size: var(--selectic-font-size);\n line-height: 1.42857143;\n color: var(--selectic-color);\n background-color: var(--selectic-bg);\n background-image: none;\n border: 1px solid var(--selectic-separator-bordercolor); /* should use a better variable */\n border-radius: 4px;\n box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);\n transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;\n}\n.selectic .has-feedback {\n position: relative;\n}\n.selectic .has-feedback .form-control {\n padding-right: calc(var(--selectic-input-height) + 4px);\n}\n\n.selectic .form-control-feedback.fa,\n.selectic .form-control-feedback {\n position: absolute;\n top: 0;\n right: 0;\n z-index: 2;\n display: block;\n width: calc(var(--selectic-input-height) + 4px);\n height: calc(var(--selectic-input-height) + 4px);\n line-height: var(--selectic-input-height);\n text-align: center;\n pointer-events: none;\n}\n\n.selectic .alert-info {\n background-color: var(--selectic-info-bg);\n color: var(--selectic-info-color);\n}\n\n.selectic .alert-danger {\n background-color: var(--selectic-error-bg);\n color: var(--selectic-error-color);\n}\n\n/* }}} */\n\n.selectic * {\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n}\n\n.selectic.form-control {\n display: inline-block;\n padding: 0;\n cursor: pointer;\n border: unset;\n}\n\n.has-feedback .selectic__icon-container.form-control-feedback {\n right: 0;\n}\n\n/* The input which contains the selected value\n * XXX: This input should stay hidden behind other elements, but is \"visible\"\n * (in term of DOM point of view) in order to get and to trigger the `focus`\n * DOM event. */\n.selectic__input-value {\n position: fixed;\n opacity: 0;\n z-index: -1000;\n top: -100px;\n}\n\n/* XXX: .form-control has been added to this selector to improve priority and\n * override some rules of the original .form-control */\n.selectic-input.form-control {\n display: inline-flex;\n justify-content: space-between;\n overflow: hidden;\n width: 100%;\n min-height: var(--selectic-input-height);\n padding-top: 0;\n padding-bottom: 0;\n padding-left: 5px;\n line-height: calc(var(--selectic-input-height) - 4px);\n color: var(--selectic-color);\n}\n\n.selectic-input__reverse-icon {\n align-self: center;\n margin-right: 3px;\n cursor: default;\n}\n.selectic-input__clear-icon {\n align-self: center;\n margin-left: 3px;\n cursor: pointer;\n}\n.selectic-input__clear-icon:hover {\n color: var(--selectic-selected-item-color);\n}\n\n.selectic-input.focused {\n border-bottom-left-radius: 0px;\n border-bottom-right-radius: 0px;\n}\n\n.selectic-input.disabled {\n cursor: var(--selectic-cursor-disabled);\n background-color: var(--selectic-bg-disabled);\n}\n.selectic-input.disabled .more-items {\n\tbackground-color: var(--selectic-more-items-bg-disabled);\n}\n\n.selectic-input__selected-items {\n display: inline-flex;\n flex-wrap: nowrap;\n align-items: center;\n white-space: nowrap;\n}\n\n.selectic-input__selected-items__placeholder {\n font-style: italic;\n opacity: 0.7;\n white-space: nowrap;\n}\n\n.selectic-icon {\n color: var(--selectic-color);\n text-align: center;\n vertical-align: middle;\n}\n\n.selectic__extended-list {\n position: fixed;\n top: var(--top-position, 0);\n z-index: 2000;\n height: auto;\n max-height: var(--availableSpace);\n background-color: var(--selectic-bg, #ffffff);\n box-shadow: 2px 5px 12px 0px #888888;\n border-radius: 0 0 4px 4px;\n padding: 0;\n width: var(--list-width, 200px);\n min-width: 200px;\n display: grid;\n grid-template-rows: minmax(0, max-content) 1fr;\n}\n.selectic__extended-list.selectic-position-top {\n box-shadow: 2px -3px 12px 0px #888888;\n}\n.selectic__extended-list__list-container{\n overflow: auto;\n}\n.selectic__extended-list__list-items {\n max-height: calc(var(--selectic-input-height) * 10);\n min-width: max-content;\n padding-left: 0;\n}\n\n.selectic-item {\n display: block;\n position: relative;\n box-sizing: border-box;\n padding: 2px 8px;\n color: var(--selectic-item-color, var(--selectic-color));\n min-height: calc(var(--selectic-input-height) - 3px);\n list-style-type: none;\n white-space: nowrap;\n cursor: pointer;\n}\n\n.selectic-item_text {\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.selectic-item:not(.selected) .selectic-item_icon {\n opacity: 0;\n}\n\n.selectic-item_text {\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.selectic-item__active {\n background-color: var(--selectic-active-item-bg);\n color: var(--selectic-active-item-color);\n}\n.selectic-item__active:not(.selected) .selectic-item_icon {\n opacity: 0.2;\n}\n\n.selectic-item__disabled {\n color: var(--selectic-color-disabled);\n background-color: var(--selectic-bg-disabled);\n}\n\n.selectic-item__is-in-group {\n padding-left: 2em;\n}\n\n.selectic-item__is-group {\n font-weight: bold;\n cursor: default;\n}\n\n.selectic-item__is-group.selectable {\n cursor: pointer;\n}\n\n.selectic-item.selected {\n color: var(--selectic-selected-item-color);\n}\n.selectic-search-scope {\n color: #e0e0e0;\n left: auto;\n right: 10px;\n}\n.selectic .form-control-feedback.fa.selectic-search-scope {\n width: calc(var(--selectic-input-height) * 0.75);\n height: calc(var(--selectic-input-height) * 0.75);\n line-height: calc(var(--selectic-input-height) * 0.75);\n}\n\n.selectic__message {\n text-align: center;\n padding: 3px;\n}\n\n.selectic .filter-panel {\n padding: 3px;\n margin-left: 0px;\n margin-right: 0px;\n background-color: var(--selectic-panel-bg);\n border-bottom: 1px solid var(--selectic-separator-bordercolor);\n}\n\n.selectic .panelclosed {\n max-height: 0px;\n transition: max-height 0.3s ease-out;\n overflow: hidden;\n}\n\n.panelopened {\n max-height: 200px;\n transition: max-height 0.3s ease-in;\n overflow: hidden;\n}\n\n.selectic .filter-panel__input {\n padding-left: 0px;\n padding-right: 0px;\n padding-bottom: 10px;\n margin-bottom: 0px;\n}\n.selectic .filter-input {\n height: calc(var(--selectic-input-height) * 0.75);\n}\n\n.selectic .checkbox-filter {\n padding: 5px;\n text-align: center;\n}\n\n.selectic .curtain-handler {\n text-align: center;\n}\n\n.selectic .toggle-selectic {\n margin: 5px;\n padding-left: 0px;\n padding-right: 0px;\n}\n\n.selectic .toggle-boolean-select-all-toggle {\n display: inline;\n margin-right: 15px;\n}\n\n.selectic .toggle-boolean-excluding-toggle {\n display: inline;\n margin-right: 15px;\n}\n\n.selectic .single-value {\n display: grid;\n grid-template: \"value icon\" 1fr / max-content max-content;\n\n padding: 2px;\n padding-left: 5px;\n margin-left: 0;\n margin-right: 5px;\n /* margin top/bottom are mainly to create a gutter in multilines */\n margin-top: 2px;\n margin-bottom: 2px;\n\n border-radius: 3px;\n background-color: var(--selectic-value-bg);\n max-height: calc(var(--selectic-input-height) - 10px);\n max-width: 100%;\n min-width: 30px;\n\n overflow: hidden;\n white-space: nowrap;\n line-height: initial;\n vertical-align: middle;\n}\n\n.selectic .more-items {\n display: inline-block;\n\n padding-left: 5px;\n padding-right: 5px;\n border-radius: 10px;\n\n background-color: var(--selectic-more-items-bg, var(--selectic-info-bg));\n color: var(--selectic-more-items-color, var(--selectic-info-color));\n cursor: help;\n}\n.selectic-input__selected-items__value {\n grid-area: value;\n align-self: center;\n justify-self: normal;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n}\n\n.selectic-input__selected-items__icon {\n grid-area: icon;\n align-self: center;\n justify-self: center;\n margin-left: 5px;\n}\n.selectic-input__selected-items__icon:hover {\n color: var(--selectic-selected-item-color);\n}\n\n.selectic__label-disabled {\n opacity: 0.5;\n transition: opacity 400ms;\n}\n\n/* XXX: override padding of bootstrap input-sm.\n * This padding introduce a line shift. */\n.selectic.input-sm {\n padding: 0;\n}\n\n/* {{{ overflow multiline */\n\n.selectic--overflow-multiline,\n.selectic--overflow-multiline.form-control,\n.selectic--overflow-multiline .form-control {\n height: unset;\n}\n\n.selectic--overflow-multiline .selectic-input {\n overflow: unset;\n}\n\n.selectic--overflow-multiline .selectic-input__selected-items {\n flex-wrap: wrap;\n}\n\n/* {{{ icons */\n\n@keyframes selectic-animation-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(359deg);\n }\n}\n\n.selectic__icon {\n height: 1em;\n fill: currentColor;\n}\n\n.selectic-spin {\n animation: selectic-animation-spin 2s infinite linear;\n}\n\n/* }}} */\n";
|
|
35
|
+
var css_248z = "/* {{{ Variables */\n\n:root {\n --selectic-font-size: 14px;\n --selectic-cursor-disabled: not-allowed;\n\n /* The main element */\n --selectic-color: #555555;\n --selectic-bg: #ffffff;\n\n /* The main element (when disabled) */\n --selectic-color-disabled: #787878;\n --selectic-bg-disabled: #eeeeee;\n\n /* The list */\n --selectic-panel-bg: #f0f0f0;\n --selectic-separator-bordercolor: #cccccc;\n /* --selectic-item-color: var(--selectic-color); /* Can be set in any CSS configuration */\n\n /* The current selected item */\n --selectic-selected-item-color: #428bca;\n\n /* When mouse is over items or by selecting with key arrows */\n --selectic-active-item-color: #ffffff;\n --selectic-active-item-bg: #66afe9;\n\n /* Selected values in main element */\n --selectic-value-bg: #f0f0f0;\n /* --selectic-more-items-bg: var(--selectic-info-bg); /* can be set in any CSS configuration */\n /* --selectic-more-items-color: var(--selectic-info-color); /* can be set in any CSS configuration */\n --selectic-more-items-bg-disabled: #cccccc;\n\n /* Information message */\n --selectic-info-bg: #5bc0de;\n --selectic-info-color: #ffffff;\n\n /* Error message */\n --selectic-error-bg: #b72c29;\n --selectic-error-color: #ffffff;\n\n /* XXX: Currently it is important to keep this size for a correct scroll\n * height estimation */\n --selectic-input-height: 30px;\n}\n\n/* }}} */\n/* {{{ Bootstrap equivalent style */\n\n.selectic .form-control {\n display: block;\n width: 100%;\n height: calc(var(--selectic-input-height) - 2px);\n font-size: var(--selectic-font-size);\n line-height: 1.42857143;\n color: var(--selectic-color);\n background-color: var(--selectic-bg);\n background-image: none;\n border: 1px solid var(--selectic-separator-bordercolor); /* should use a better variable */\n border-radius: 4px;\n box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);\n transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;\n}\n.selectic .has-feedback {\n position: relative;\n}\n.selectic .has-feedback .form-control {\n padding-right: calc(var(--selectic-input-height) + 4px);\n}\n\n.selectic .form-control-feedback.fa,\n.selectic .form-control-feedback {\n position: absolute;\n top: 0;\n right: 0;\n z-index: 2;\n display: block;\n width: calc(var(--selectic-input-height) + 4px);\n height: calc(var(--selectic-input-height) + 4px);\n line-height: var(--selectic-input-height);\n text-align: center;\n pointer-events: none;\n}\n\n.selectic .alert-info {\n background-color: var(--selectic-info-bg);\n color: var(--selectic-info-color);\n}\n\n.selectic .alert-danger {\n background-color: var(--selectic-error-bg);\n color: var(--selectic-error-color);\n}\n\n/* }}} */\n\n.selectic * {\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n}\n\n.selectic.form-control {\n display: inline-block;\n padding: 0;\n cursor: pointer;\n border: unset;\n}\n\n.has-feedback .selectic__icon-container.form-control-feedback {\n right: 0;\n}\n\n/* The input which contains the selected value\n * XXX: This input should stay hidden behind other elements, but is \"visible\"\n * (in term of DOM point of view) in order to get and to trigger the `focus`\n * DOM event. */\n.selectic__input-value {\n position: fixed;\n opacity: 0;\n z-index: -1000;\n top: -100px;\n}\n\n/* XXX: .form-control has been added to this selector to improve priority and\n * override some rules of the original .form-control */\n.selectic-input.form-control {\n display: inline-flex;\n justify-content: space-between;\n overflow: hidden;\n width: 100%;\n min-height: var(--selectic-input-height);\n padding-top: 0;\n padding-bottom: 0;\n padding-left: 5px;\n line-height: calc(var(--selectic-input-height) - 4px);\n color: var(--selectic-color);\n}\n\n.selectic-input__reverse-icon {\n align-self: center;\n margin-right: 3px;\n cursor: default;\n}\n.selectic-input__clear-icon {\n align-self: center;\n margin-left: 3px;\n cursor: pointer;\n}\n.selectic-input__clear-icon:hover {\n color: var(--selectic-selected-item-color);\n}\n\n.selectic-input.focused {\n border-bottom-left-radius: 0px;\n border-bottom-right-radius: 0px;\n}\n\n.selectic-input.disabled {\n cursor: var(--selectic-cursor-disabled);\n background-color: var(--selectic-bg-disabled);\n}\n.selectic-input.disabled .more-items {\n\tbackground-color: var(--selectic-more-items-bg-disabled);\n}\n\n.selectic-input__selected-items {\n display: inline-flex;\n flex-wrap: nowrap;\n align-items: center;\n white-space: nowrap;\n}\n\n.selectic-input__selected-items__placeholder {\n font-style: italic;\n opacity: 0.7;\n white-space: nowrap;\n}\n\n.selectic-icon {\n color: var(--selectic-color);\n text-align: center;\n vertical-align: middle;\n}\n\n.selectic__extended-list {\n position: fixed;\n top: var(--top-position, 0);\n z-index: 2000;\n height: auto;\n max-height: var(--availableSpace);\n background-color: var(--selectic-bg, #ffffff);\n box-shadow: 2px 5px 12px 0px #888888;\n border-radius: 0 0 4px 4px;\n padding: 0;\n width: var(--list-width, 200px);\n min-width: 200px;\n display: grid;\n grid-template-rows: minmax(0, max-content) 1fr;\n}\n.selectic__extended-list.selectic-position-top {\n box-shadow: 2px -3px 12px 0px #888888;\n}\n.selectic__extended-list__list-container{\n overflow: auto;\n}\n.selectic__extended-list__list-items {\n max-height: calc(var(--selectic-input-height) * 10);\n min-width: max-content;\n padding-left: 0;\n}\n\n.selectic-item {\n display: block;\n position: relative;\n box-sizing: border-box;\n padding: 2px 8px;\n color: var(--selectic-item-color, var(--selectic-color));\n min-height: calc(var(--selectic-input-height) - 3px);\n list-style-type: none;\n white-space: nowrap;\n cursor: pointer;\n}\n\n.selectic-item_text {\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.selectic-item:not(.selected) .selectic-item_icon {\n opacity: 0;\n}\n\n.selectic-item_text {\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.selectic-item__active {\n background-color: var(--selectic-active-item-bg);\n color: var(--selectic-active-item-color);\n}\n.selectic-item__active:not(.selected) .selectic-item_icon {\n opacity: 0.2;\n}\n.selectic-item__active.selectic-item__disabled:not(.selected) .selectic-item_icon {\n opacity: 0;\n}\n\n.selectic-item__disabled {\n color: var(--selectic-color-disabled);\n background-color: var(--selectic-bg-disabled);\n}\n\n.selectic-item__is-in-group {\n padding-left: 2em;\n}\n\n.selectic-item__is-group {\n font-weight: bold;\n cursor: default;\n}\n\n.selectic-item__is-group.selectable {\n cursor: pointer;\n}\n\n.selectic-item.selected {\n color: var(--selectic-selected-item-color);\n}\n.selectic-search-scope {\n color: #e0e0e0;\n left: auto;\n right: 10px;\n}\n.selectic .form-control-feedback.fa.selectic-search-scope {\n width: calc(var(--selectic-input-height) * 0.75);\n height: calc(var(--selectic-input-height) * 0.75);\n line-height: calc(var(--selectic-input-height) * 0.75);\n}\n\n.selectic__message {\n text-align: center;\n padding: 3px;\n}\n\n.selectic .filter-panel {\n padding: 3px;\n margin-left: 0px;\n margin-right: 0px;\n background-color: var(--selectic-panel-bg);\n border-bottom: 1px solid var(--selectic-separator-bordercolor);\n}\n\n.selectic .panelclosed {\n max-height: 0px;\n transition: max-height 0.3s ease-out;\n overflow: hidden;\n}\n\n.panelopened {\n max-height: 200px;\n transition: max-height 0.3s ease-in;\n overflow: hidden;\n}\n\n.selectic .filter-panel__input {\n padding-left: 0px;\n padding-right: 0px;\n padding-bottom: 10px;\n margin-bottom: 0px;\n}\n.selectic .filter-input {\n height: calc(var(--selectic-input-height) * 0.75);\n}\n\n.selectic .checkbox-filter {\n padding: 5px;\n text-align: center;\n}\n\n.selectic .curtain-handler {\n text-align: center;\n}\n\n.selectic .toggle-selectic {\n margin: 5px;\n padding-left: 0px;\n padding-right: 0px;\n}\n\n.selectic .toggle-boolean-select-all-toggle {\n display: inline;\n margin-right: 15px;\n}\n\n.selectic .toggle-boolean-excluding-toggle {\n display: inline;\n margin-right: 15px;\n}\n\n.selectic .single-value {\n display: grid;\n grid-template: \"value icon\" 1fr / max-content max-content;\n\n padding: 2px;\n padding-left: 5px;\n margin-left: 0;\n margin-right: 5px;\n /* margin top/bottom are mainly to create a gutter in multilines */\n margin-top: 2px;\n margin-bottom: 2px;\n\n border-radius: 3px;\n background-color: var(--selectic-value-bg);\n max-height: calc(var(--selectic-input-height) - 10px);\n max-width: 100%;\n min-width: 30px;\n\n overflow: hidden;\n white-space: nowrap;\n line-height: initial;\n vertical-align: middle;\n}\n\n.selectic .more-items {\n display: inline-block;\n\n padding-left: 5px;\n padding-right: 5px;\n border-radius: 10px;\n\n background-color: var(--selectic-more-items-bg, var(--selectic-info-bg));\n color: var(--selectic-more-items-color, var(--selectic-info-color));\n cursor: help;\n}\n.selectic-input__selected-items__value {\n grid-area: value;\n align-self: center;\n justify-self: normal;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n}\n\n.selectic-input__selected-items__icon {\n grid-area: icon;\n align-self: center;\n justify-self: center;\n margin-left: 5px;\n}\n.selectic-input__selected-items__icon:hover {\n color: var(--selectic-selected-item-color);\n}\n\n.selectic__label-disabled {\n opacity: 0.5;\n transition: opacity 400ms;\n}\n\n/* XXX: override padding of bootstrap input-sm.\n * This padding introduce a line shift. */\n.selectic.input-sm {\n padding: 0;\n}\n\n/* {{{ overflow multiline */\n\n.selectic--overflow-multiline,\n.selectic--overflow-multiline.form-control,\n.selectic--overflow-multiline .form-control {\n height: unset;\n}\n\n.selectic--overflow-multiline .selectic-input {\n overflow: unset;\n}\n\n.selectic--overflow-multiline .selectic-input__selected-items {\n flex-wrap: wrap;\n}\n\n/* {{{ icons */\n\n@keyframes selectic-animation-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(359deg);\n }\n}\n\n.selectic__icon {\n height: 1em;\n fill: currentColor;\n}\n\n.selectic-spin {\n animation: selectic-animation-spin 2s infinite linear;\n}\n\n/* }}} */\n";
|
|
36
36
|
styleInject(css_248z);
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -558,25 +558,54 @@ class SelecticStore {
|
|
|
558
558
|
if (selected === undefined) {
|
|
559
559
|
selected = !isAlreadySelected;
|
|
560
560
|
}
|
|
561
|
+
const selectedOptions = Array.isArray(state.selectedOptions)
|
|
562
|
+
? state.selectedOptions
|
|
563
|
+
: [];
|
|
561
564
|
if (id === null) {
|
|
562
|
-
|
|
563
|
-
|
|
565
|
+
/* Keep disabled items: we cannot removed them because they
|
|
566
|
+
* are disabled */
|
|
567
|
+
const newSelection = selectedOptions.reduce((list, item) => {
|
|
568
|
+
if (item.disabled && item.id) {
|
|
569
|
+
list.push(item.id);
|
|
570
|
+
}
|
|
571
|
+
return list;
|
|
572
|
+
}, []);
|
|
573
|
+
state.internalValue = newSelection;
|
|
574
|
+
hasChanged = internalValue.length > newSelection.length;
|
|
564
575
|
}
|
|
565
576
|
else if (selected && !isAlreadySelected) {
|
|
577
|
+
let addItem = true;
|
|
566
578
|
if (item === null || item === void 0 ? void 0 : item.exclusive) {
|
|
567
|
-
|
|
568
|
-
|
|
579
|
+
const hasDisabledSelected = selectedOptions.some((opt) => {
|
|
580
|
+
return opt.disabled;
|
|
581
|
+
});
|
|
582
|
+
if (hasDisabledSelected) {
|
|
583
|
+
/* do not remove disabled item from selection */
|
|
584
|
+
addItem = false;
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
/* clear the current selection because the item is exclusive */
|
|
588
|
+
internalValue.splice(0, Infinity);
|
|
589
|
+
}
|
|
569
590
|
}
|
|
570
591
|
else if (internalValue.length === 1) {
|
|
571
592
|
const selectedId = internalValue[0];
|
|
572
593
|
const selectedItem = state.allOptions.find((opt) => opt.id === selectedId);
|
|
573
594
|
if (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.exclusive) {
|
|
574
|
-
|
|
575
|
-
|
|
595
|
+
if (selectedItem.disabled) {
|
|
596
|
+
/* If selected item is disabled and exclusive do not change the selection */
|
|
597
|
+
addItem = false;
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
/* clear the current selection because the old item was exclusive */
|
|
601
|
+
internalValue.pop();
|
|
602
|
+
}
|
|
576
603
|
}
|
|
577
604
|
}
|
|
578
|
-
|
|
579
|
-
|
|
605
|
+
if (addItem) {
|
|
606
|
+
internalValue.push(id);
|
|
607
|
+
hasChanged = true;
|
|
608
|
+
}
|
|
580
609
|
}
|
|
581
610
|
else if (!selected && isAlreadySelected) {
|
|
582
611
|
internalValue.splice(internalValue.indexOf(id), 1);
|
|
@@ -599,6 +628,11 @@ class SelecticStore {
|
|
|
599
628
|
if (id !== oldValue) {
|
|
600
629
|
return hasChanged;
|
|
601
630
|
}
|
|
631
|
+
const oldOption = state.selectedOptions;
|
|
632
|
+
if (oldOption === null || oldOption === void 0 ? void 0 : oldOption.disabled) {
|
|
633
|
+
/* old selection is disabled so do not unselect it */
|
|
634
|
+
return hasChanged;
|
|
635
|
+
}
|
|
602
636
|
id = null;
|
|
603
637
|
}
|
|
604
638
|
else if (id === oldValue) {
|
|
@@ -1368,15 +1402,23 @@ class SelecticStore {
|
|
|
1368
1402
|
if (doNotCheck || !hasFetchedAllItems) {
|
|
1369
1403
|
return;
|
|
1370
1404
|
}
|
|
1405
|
+
const selectedOptions = state.selectedOptions;
|
|
1371
1406
|
const enabledOptions = state.allOptions.filter((opt) => !opt.disabled);
|
|
1372
|
-
const
|
|
1407
|
+
const nbEnabled = enabledOptions.length;
|
|
1373
1408
|
const value = state.internalValue;
|
|
1374
1409
|
const hasValue = Array.isArray(value) ? value.length > 0 : value !== null;
|
|
1375
|
-
const
|
|
1410
|
+
const hasDisabledSelected = Array.isArray(selectedOptions)
|
|
1411
|
+
? selectedOptions.some((opt) => opt.disabled)
|
|
1412
|
+
: false;
|
|
1413
|
+
const hasOnlyValidValue = hasValue && !hasDisabledSelected && (Array.isArray(value) ? value.every((val) => this.hasValue(val)) :
|
|
1376
1414
|
this.hasValue(value));
|
|
1377
|
-
const isEmpty =
|
|
1378
|
-
const hasOnlyOneOption =
|
|
1379
|
-
|
|
1415
|
+
const isEmpty = nbEnabled === 0;
|
|
1416
|
+
const hasOnlyOneOption = nbEnabled === 1 && hasOnlyValidValue && !state.allowClearSelection;
|
|
1417
|
+
const isExclusiveDisabledItem = Array.isArray(selectedOptions) /* which means "multiple" mode */
|
|
1418
|
+
&& selectedOptions.length === 1
|
|
1419
|
+
&& selectedOptions[0].exclusive
|
|
1420
|
+
&& selectedOptions[0].disabled;
|
|
1421
|
+
if (hasOnlyOneOption || isEmpty || isExclusiveDisabledItem) {
|
|
1380
1422
|
if (state.isOpen) {
|
|
1381
1423
|
this.setAutomaticClose();
|
|
1382
1424
|
this.commit('isOpen', false);
|
|
@@ -1796,6 +1838,18 @@ let MainInput = class MainInput extends vtyx.Vue {
|
|
|
1796
1838
|
? Array.isArray(value) && value.length > 0
|
|
1797
1839
|
: value !== null;
|
|
1798
1840
|
}
|
|
1841
|
+
get disabledList() {
|
|
1842
|
+
const state = this.store.state;
|
|
1843
|
+
const isMultiple = state.multiple;
|
|
1844
|
+
const value = state.selectedOptions;
|
|
1845
|
+
if (!isMultiple || !value) {
|
|
1846
|
+
return [];
|
|
1847
|
+
}
|
|
1848
|
+
const disabledValues = value.filter((option) => {
|
|
1849
|
+
return option.disabled;
|
|
1850
|
+
});
|
|
1851
|
+
return disabledValues;
|
|
1852
|
+
}
|
|
1799
1853
|
get displayPlaceholder() {
|
|
1800
1854
|
const placeholder = this.store.state.placeholder;
|
|
1801
1855
|
const hasValue = this.hasValue;
|
|
@@ -1814,10 +1868,12 @@ let MainInput = class MainInput extends vtyx.Vue {
|
|
|
1814
1868
|
const state = this.store.state;
|
|
1815
1869
|
const isMultiple = state.multiple;
|
|
1816
1870
|
const value = state.internalValue;
|
|
1817
|
-
const
|
|
1871
|
+
const nbSelection = (Array.isArray(value) && value.length) || 0;
|
|
1872
|
+
const hasOnlyOneValue = nbSelection === 1;
|
|
1873
|
+
const hasOnlyDisabled = nbSelection <= this.disabledList.length;
|
|
1818
1874
|
/* Should not display the clear action if there is only one selected
|
|
1819
1875
|
* item in multiple (as this item has already its remove icon) */
|
|
1820
|
-
return !isMultiple || !hasOnlyOneValue;
|
|
1876
|
+
return !isMultiple || !hasOnlyOneValue || !hasOnlyDisabled;
|
|
1821
1877
|
}
|
|
1822
1878
|
get clearedLabel() {
|
|
1823
1879
|
const isMultiple = this.store.state.multiple;
|
|
@@ -1935,6 +1991,9 @@ let MainInput = class MainInput extends vtyx.Vue {
|
|
|
1935
1991
|
/* Check if there is enough space to display items like there are
|
|
1936
1992
|
* currently shown */
|
|
1937
1993
|
const el = this.$refs.selectedItems;
|
|
1994
|
+
if (!el) {
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
1938
1997
|
const parentEl = el.parentElement;
|
|
1939
1998
|
if (!document.contains(parentEl)) {
|
|
1940
1999
|
/* The element is currently not in DOM */
|
|
@@ -2033,7 +2092,7 @@ let MainInput = class MainInput extends vtyx.Vue {
|
|
|
2033
2092
|
click: () => this.$emit('item:click', item.id),
|
|
2034
2093
|
} },
|
|
2035
2094
|
vtyx.h("span", { class: "selectic-input__selected-items__value" }, item.text),
|
|
2036
|
-
!this.isDisabled && (vtyx.h(Icon$1, { icon: "times", class: "selectic-input__selected-items__icon", store: this.store, on: {
|
|
2095
|
+
!this.isDisabled && !item.disabled && (vtyx.h(Icon$1, { icon: "times", class: "selectic-input__selected-items__icon", store: this.store, on: {
|
|
2037
2096
|
'click.prevent.stop': () => this.selectItem(item.id),
|
|
2038
2097
|
} }))))),
|
|
2039
2098
|
this.moreSelectedNb && (vtyx.h("div", { class: "single-value more-items", title: this.moreSelectedTitle }, this.moreSelectedNb)))),
|
|
@@ -2507,42 +2566,6 @@ let ExtendedList = class ExtendedList extends vtyx.Vue {
|
|
|
2507
2566
|
}
|
|
2508
2567
|
return '';
|
|
2509
2568
|
}
|
|
2510
|
-
get onKeyDown() {
|
|
2511
|
-
return (evt) => {
|
|
2512
|
-
const key = evt.key;
|
|
2513
|
-
if (key === 'Escape') {
|
|
2514
|
-
this.store.commit('isOpen', false);
|
|
2515
|
-
}
|
|
2516
|
-
else if (key === 'Enter') {
|
|
2517
|
-
const index = this.store.state.activeItemIdx;
|
|
2518
|
-
if (index !== -1) {
|
|
2519
|
-
const item = this.store.state.filteredOptions[index];
|
|
2520
|
-
if (!item.disabled && !item.isGroup) {
|
|
2521
|
-
this.store.selectItem(item.id);
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
evt.stopPropagation();
|
|
2525
|
-
evt.preventDefault();
|
|
2526
|
-
}
|
|
2527
|
-
else if (key === 'ArrowUp') {
|
|
2528
|
-
const index = this.store.state.activeItemIdx;
|
|
2529
|
-
if (index > 0) {
|
|
2530
|
-
this.store.commit('activeItemIdx', index - 1);
|
|
2531
|
-
}
|
|
2532
|
-
evt.stopPropagation();
|
|
2533
|
-
evt.preventDefault();
|
|
2534
|
-
}
|
|
2535
|
-
else if (key === 'ArrowDown') {
|
|
2536
|
-
const index = this.store.state.activeItemIdx;
|
|
2537
|
-
const max = this.store.state.totalFilteredOptions - 1;
|
|
2538
|
-
if (index < max) {
|
|
2539
|
-
this.store.commit('activeItemIdx', index + 1);
|
|
2540
|
-
}
|
|
2541
|
-
evt.stopPropagation();
|
|
2542
|
-
evt.preventDefault();
|
|
2543
|
-
}
|
|
2544
|
-
};
|
|
2545
|
-
}
|
|
2546
2569
|
get bestPosition() {
|
|
2547
2570
|
const windowHeight = window.innerHeight;
|
|
2548
2571
|
const isFullyEstimated = this.isFullyEstimated;
|
|
@@ -2658,6 +2681,40 @@ let ExtendedList = class ExtendedList extends vtyx.Vue {
|
|
|
2658
2681
|
clickHeaderGroup() {
|
|
2659
2682
|
this.store.selectGroup(this.topGroupId, !this.topGroupSelected);
|
|
2660
2683
|
}
|
|
2684
|
+
onKeyDown(evt) {
|
|
2685
|
+
const key = evt.key;
|
|
2686
|
+
if (key === 'Escape') {
|
|
2687
|
+
this.store.commit('isOpen', false);
|
|
2688
|
+
}
|
|
2689
|
+
else if (key === 'Enter') {
|
|
2690
|
+
const index = this.store.state.activeItemIdx;
|
|
2691
|
+
if (index !== -1) {
|
|
2692
|
+
const item = this.store.state.filteredOptions[index];
|
|
2693
|
+
if (!item.disabled && !item.isGroup) {
|
|
2694
|
+
this.store.selectItem(item.id);
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
evt.stopPropagation();
|
|
2698
|
+
evt.preventDefault();
|
|
2699
|
+
}
|
|
2700
|
+
else if (key === 'ArrowUp') {
|
|
2701
|
+
const index = this.store.state.activeItemIdx;
|
|
2702
|
+
if (index > 0) {
|
|
2703
|
+
this.store.commit('activeItemIdx', index - 1);
|
|
2704
|
+
}
|
|
2705
|
+
evt.stopPropagation();
|
|
2706
|
+
evt.preventDefault();
|
|
2707
|
+
}
|
|
2708
|
+
else if (key === 'ArrowDown') {
|
|
2709
|
+
const index = this.store.state.activeItemIdx;
|
|
2710
|
+
const max = this.store.state.totalFilteredOptions - 1;
|
|
2711
|
+
if (index < max) {
|
|
2712
|
+
this.store.commit('activeItemIdx', index + 1);
|
|
2713
|
+
}
|
|
2714
|
+
evt.stopPropagation();
|
|
2715
|
+
evt.preventDefault();
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2661
2718
|
/* }}} */
|
|
2662
2719
|
/* {{{ Life cycles */
|
|
2663
2720
|
mounted() {
|
|
@@ -2787,7 +2844,8 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2787
2844
|
const store = this.store;
|
|
2788
2845
|
const keepOpenWithOtherSelectic = this.params.keepOpenWithOtherSelectic;
|
|
2789
2846
|
const extendedList = this.$refs.extendedList;
|
|
2790
|
-
|
|
2847
|
+
const extendedListEl = extendedList === null || extendedList === void 0 ? void 0 : extendedList.$el;
|
|
2848
|
+
if (!extendedListEl) {
|
|
2791
2849
|
/* this component is not focused anymore */
|
|
2792
2850
|
if (!keepOpenWithOtherSelectic) {
|
|
2793
2851
|
this.removeListeners();
|
|
@@ -2796,7 +2854,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2796
2854
|
return;
|
|
2797
2855
|
}
|
|
2798
2856
|
const target = evt.target;
|
|
2799
|
-
if (!
|
|
2857
|
+
if (!extendedListEl.contains(target) && !this.$el.contains(target)) {
|
|
2800
2858
|
store.commit('isOpen', false);
|
|
2801
2859
|
}
|
|
2802
2860
|
};
|
|
@@ -2889,14 +2947,23 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2889
2947
|
/* }}} */
|
|
2890
2948
|
/* {{{ private methods */
|
|
2891
2949
|
computeWidth() {
|
|
2892
|
-
|
|
2893
|
-
|
|
2950
|
+
var _a;
|
|
2951
|
+
const mainInput = (_a = this.$refs) === null || _a === void 0 ? void 0 : _a.mainInput;
|
|
2952
|
+
const mainEl = mainInput === null || mainInput === void 0 ? void 0 : mainInput.$el;
|
|
2953
|
+
if (!mainEl) {
|
|
2954
|
+
/* This method has been called too soon (before render function)
|
|
2955
|
+
* or too late (after unmount) */
|
|
2956
|
+
return;
|
|
2957
|
+
}
|
|
2958
|
+
this.width = mainEl.offsetWidth;
|
|
2894
2959
|
}
|
|
2895
2960
|
computeOffset(doNotAddListener = false) {
|
|
2896
|
-
|
|
2961
|
+
var _a;
|
|
2962
|
+
const mainInput = (_a = this.$refs) === null || _a === void 0 ? void 0 : _a.mainInput;
|
|
2897
2963
|
const mainEl = mainInput === null || mainInput === void 0 ? void 0 : mainInput.$el;
|
|
2898
2964
|
if (!mainEl) {
|
|
2899
|
-
/* This method has been called too soon (before render function)
|
|
2965
|
+
/* This method has been called too soon (before render function)
|
|
2966
|
+
* or too late (after unmount) */
|
|
2900
2967
|
return;
|
|
2901
2968
|
}
|
|
2902
2969
|
const _elementsListeners = this._elementsListeners;
|
|
@@ -3030,13 +3097,14 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
3030
3097
|
checkFocus() {
|
|
3031
3098
|
/* Await that focused element becomes active */
|
|
3032
3099
|
setTimeout(() => {
|
|
3100
|
+
var _a;
|
|
3033
3101
|
const focusedEl = document.activeElement;
|
|
3034
|
-
const extendedList = this.$refs.extendedList;
|
|
3102
|
+
const extendedList = (_a = this.$refs) === null || _a === void 0 ? void 0 : _a.extendedList;
|
|
3035
3103
|
/* check if there is a focused element (if none the body is
|
|
3036
3104
|
* selected) and if it is inside current Selectic */
|
|
3037
3105
|
if (focusedEl === document.body
|
|
3038
3106
|
|| this.$el.contains(focusedEl)
|
|
3039
|
-
|| (extendedList
|
|
3107
|
+
|| (extendedList === null || extendedList === void 0 ? void 0 : extendedList.$el.contains(focusedEl))) {
|
|
3040
3108
|
return;
|
|
3041
3109
|
}
|
|
3042
3110
|
this.store.commit('isOpen', false);
|