slim-select 2.2.1 → 2.2.2
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/helpers.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/select.d.ts +1 -1
- package/dist/slimselect.cjs.js +57 -39
- package/dist/slimselect.es.js +57 -39
- package/dist/slimselect.global.js +57 -39
- package/dist/slimselect.js +57 -39
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.umd.js +57 -39
- package/dist/slimselect.umd.min.js +1 -1
- package/package.json +1 -1
- package/src/slim-select/helpers.ts +4 -0
- package/src/slim-select/index.ts +26 -2
- package/src/slim-select/render.ts +0 -1
- package/src/slim-select/select.ts +12 -3
- package/src/vue/dist/slim-select/helpers.d.ts +1 -0
- package/src/vue/dist/slim-select/index.d.ts +1 -1
- package/src/vue/dist/slim-select/select.d.ts +1 -1
- package/src/vue/dist/slimselectvue.es.js +109 -42
- package/src/vue/dist/slimselectvue.global.js +109 -42
- package/src/vue/dist/slimselectvue.ssr.js +109 -42
- package/src/vue/dist/vue/slimselect.vue.d.ts +50 -27
- package/src/vue/package.json +1 -1
- package/src/vue/rollup.config.mjs +3 -3
- package/src/vue/slimselect.vue +66 -2
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/code/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/a8a4a8a1b06b6c8069e965f4a30a4b42013b830a +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/semanticDiagnostics/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/a8a4a8a1b06b6c8069e965f4a30a4b42013b830a +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/syntacticDiagnostics/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/068e7904209e205518dbc9726d632bbaf28bfc55 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/06b75ecfe63fda3fcfaa42593fa1f22167f3a9f8 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/2aa9d56fc4a9661ee8e3de277da5ee3f960713de +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/2c58b356be1a9572c64469d50a7a25c46f94aaeb +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/36d3fb579feb4cad7a15b7a2f509f338caf72fa0 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/388b297c3f73fcba25b8174fda975235e5d12b5a +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/40e43895ec63e1e25aa7e278ca1e8c3adefc815d +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/645e188194be07518ebbb0a5b4304f5170fee599 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/65515bf3a44aaf1306f589073f1c8b98be747f5f +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/6a357fe7542e07f7919ea9b22401027dd1e8a0c1 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/72087cac150d02ed6d19e37d6f1436566d5ac798 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/9ff120b6426a4c7a03236428f26a92772586c3e5 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/a6917de673fc74a6cfca5133913982e54e58a7fb +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/aa4aee440d13b06b4bb05c36eee326513aa6c040 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/b02a4d0c40fac4c7f9ea7acd7944ee8844afcedf +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/b21a02b948881426bc4dcff649fc4fba07ca34d2 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/c10c11f9c426095ab3f504dd8b7622ad7ba7c8ed +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_1e8d68e0803222688213218fda500c83f6c6476e/types/cache/dc186595636217ded2d4a4cfbb789d68ea485b6b +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/code/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/a8a4a8a1b06b6c8069e965f4a30a4b42013b830a +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/semanticDiagnostics/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/a8a4a8a1b06b6c8069e965f4a30a4b42013b830a +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/syntacticDiagnostics/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/068e7904209e205518dbc9726d632bbaf28bfc55 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/06b75ecfe63fda3fcfaa42593fa1f22167f3a9f8 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/2aa9d56fc4a9661ee8e3de277da5ee3f960713de +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/2c58b356be1a9572c64469d50a7a25c46f94aaeb +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/36d3fb579feb4cad7a15b7a2f509f338caf72fa0 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/388b297c3f73fcba25b8174fda975235e5d12b5a +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/40e43895ec63e1e25aa7e278ca1e8c3adefc815d +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/645e188194be07518ebbb0a5b4304f5170fee599 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/65515bf3a44aaf1306f589073f1c8b98be747f5f +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/6a357fe7542e07f7919ea9b22401027dd1e8a0c1 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/72087cac150d02ed6d19e37d6f1436566d5ac798 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/9ff120b6426a4c7a03236428f26a92772586c3e5 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/a6917de673fc74a6cfca5133913982e54e58a7fb +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/aa4aee440d13b06b4bb05c36eee326513aa6c040 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/b02a4d0c40fac4c7f9ea7acd7944ee8844afcedf +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/b21a02b948881426bc4dcff649fc4fba07ca34d2 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/c10c11f9c426095ab3f504dd8b7622ad7ba7c8ed +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_2e1b3e4caed5e16ec3a087e96a7fe6e4f5ea8a82/types/cache/dc186595636217ded2d4a4cfbb789d68ea485b6b +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/code/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/a8a4a8a1b06b6c8069e965f4a30a4b42013b830a +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/semanticDiagnostics/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/05b27cf262de47962f4beeba3d4b4f67616bdf24 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/26c90bc22e366b540ff134ba7de2ab3715155a20 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/7a2b654bed9256f52421aec7d04cd8553486335b +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/80fdd1aafff88316e6a7f63509fb7304c94ae6d3 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/88c6c8bf5346a961efcdff848fba6e3f2d24b26c +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/a8a4a8a1b06b6c8069e965f4a30a4b42013b830a +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/b2f217f16a7744eb13543dc90442443538b724b8 +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/syntacticDiagnostics/cache/be60813c21c2fbc627fcf99127ca2a96a3065fba +0 -1
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/068e7904209e205518dbc9726d632bbaf28bfc55 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/06b75ecfe63fda3fcfaa42593fa1f22167f3a9f8 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/2aa9d56fc4a9661ee8e3de277da5ee3f960713de +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/2c58b356be1a9572c64469d50a7a25c46f94aaeb +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/36d3fb579feb4cad7a15b7a2f509f338caf72fa0 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/388b297c3f73fcba25b8174fda975235e5d12b5a +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/40e43895ec63e1e25aa7e278ca1e8c3adefc815d +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/645e188194be07518ebbb0a5b4304f5170fee599 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/65515bf3a44aaf1306f589073f1c8b98be747f5f +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/6a357fe7542e07f7919ea9b22401027dd1e8a0c1 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/72087cac150d02ed6d19e37d6f1436566d5ac798 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/9ff120b6426a4c7a03236428f26a92772586c3e5 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/a6917de673fc74a6cfca5133913982e54e58a7fb +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/aa4aee440d13b06b4bb05c36eee326513aa6c040 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/b02a4d0c40fac4c7f9ea7acd7944ee8844afcedf +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/b21a02b948881426bc4dcff649fc4fba07ca34d2 +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/c10c11f9c426095ab3f504dd8b7622ad7ba7c8ed +0 -0
- package/src/vue/node_modules/.cache/rollup-plugin-typescript2/rpt2_6eed9deea87cc005768ee2b80168901d42458ef9/types/cache/dc186595636217ded2d4a4cfbb789d68ea485b6b +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SlimSelect=t()}(this,(function(){"use strict";function e(){return Math.random().toString(36).substring(2,10)}function t(e,t=50,s=!1){let i;return function(...n){const l=self,a=s&&!i;clearTimeout(i),i=setTimeout((()=>{i=null,s||e.apply(l,n)}),t),a&&e.apply(l,n)}}class s{constructor(t){if(this.id=t.id&&""!==t.id?t.id:e(),this.label=t.label||"",this.selectAll=void 0!==t.selectAll&&t.selectAll,this.closable=t.closable||"off",this.options=[],t.options)for(const e of t.options)this.options.push(new i(e))}}class i{constructor(t){this.id=t.id&&""!==t.id?t.id:e(),this.value=void 0===t.value?t.text:t.value,this.text=t.text||"",this.html=t.html||"",this.selected=void 0!==t.selected&&t.selected,this.display=void 0===t.display||t.display,this.disabled=void 0!==t.disabled&&t.disabled,this.mandatory=void 0!==t.mandatory&&t.mandatory,this.placeholder=void 0!==t.placeholder&&t.placeholder,this.class=t.class||"",this.style=t.style||"",this.data=t.data||{}}}class n{constructor(e,t){this.selectType="single",this.data=[],this.selectType=e,this.setData(t)}validateDataArray(e){if(!Array.isArray(e))return new Error("Data must be an array");for(let t of e){if(!(t instanceof s||"label"in t))return t instanceof i||"text"in t?this.validateOption(t):new Error("Data object must be a valid optgroup or option");if(!("label"in t))return new Error("Optgroup must have a label");if("options"in t&&t.options)for(let e of t.options)return this.validateOption(e)}return null}validateOption(e){return"text"in e?null:new Error("Option must have a text")}partialToFullData(e){let t=[];return e.forEach((e=>{if(e instanceof s||"label"in e){let n=[];"options"in e&&e.options&&e.options.forEach((e=>{n.push(new i(e))})),n.length>0&&t.push(new s(e))}(e instanceof i||"text"in e)&&t.push(new i(e))})),t}setData(e){this.data=this.partialToFullData(e),"single"===this.selectType&&this.setSelectedBy("value",this.getSelected())}getData(){return this.filter(null,!0)}getDataOptions(){return this.filter(null,!1)}addOption(e){this.setData(this.getData().concat(new i(e)))}setSelectedBy(e,t){let n=null,l=!1;for(let a of this.data){if(a instanceof s)for(let s of a.options)n||(n=s),s.selected=!l&&t.includes(s[e]),s.selected&&"single"===this.selectType&&(l=!0);a instanceof i&&(n||(n=a),a.selected=!l&&t.includes(a[e]),a.selected&&"single"===this.selectType&&(l=!0))}"single"===this.selectType&&n&&!l&&(n.selected=!0)}getSelected(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.value)})),t}getSelectedOptions(){return this.filter((e=>e.selected),!1)}getSelectedIDs(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.id)})),t}getOptgroupByID(e){for(let t of this.data)if(t instanceof s&&t.id===e)return t;return null}getOptionByID(e){let t=this.filter((t=>t.id===e),!1);return t.length?t[0]:null}search(e,t){return""===(e=e.trim())?this.getData():this.filter((s=>t(s,e)),!0)}filter(e,t){const n=[];return this.data.forEach((l=>{if(l instanceof s)if(t){let t=[];l.options.forEach((s=>{e&&!e(s)||t.push(new i(s))})),t.length>0&&n.push(new s(l))}else l.options.forEach((t=>{e&&e(t)&&n.push(t)}));l instanceof i&&(e&&!e(l)||n.push(new i(l)))})),n}}class l{constructor(e,t,s){this.classes={main:"ss-main",placeholder:"ss-placeholder",values:"ss-values",single:"ss-single",value:"ss-value",valueText:"ss-value-text",valueDelete:"ss-value-delete",valueOut:"ss-value-out",deselect:"ss-deselect",deselectPath:"M10,10 L90,90 M10,90 L90,10",arrow:"ss-arrow",arrowClose:"M10,30 L50,70 L90,30",arrowOpen:"M10,70 L50,30 L90,70",content:"ss-content",openAbove:"ss-open-above",openBelow:"ss-open-below",search:"ss-search",searchHighlighter:"ss-search-highlight",searching:"ss-searching",addable:"ss-addable",addablePath:"M50,10 L50,90 M10,50 L90,50",list:"ss-list",optgroup:"ss-optgroup",optgroupLabel:"ss-optgroup-label",optgroupLabelText:"ss-optgroup-label-text",optgroupActions:"ss-optgroup-actions",optgroupSelectAll:"ss-selectall",optgroupSelectAllBox:"M60,10 L10,10 L10,90 L90,90 L90,50",optgroupSelectAllCheck:"M30,45 L50,70 L90,10",optgroupClosable:"ss-closable",option:"ss-option",optionDelete:"M10,10 L90,90 M10,90 L90,10",highlighted:"ss-highlighted",open:"ss-open",close:"ss-close",selected:"ss-selected",error:"ss-error",disabled:"ss-disabled",hide:"ss-hide"},this.store=t,this.settings=e,this.callbacks=s,this.main=this.mainDiv(),this.content=this.contentDiv(),this.settings.contentLocation.appendChild(this.content.main)}enable(){this.main.main.classList.remove(this.classes.disabled),this.content.search.input.disabled=!1}disable(){this.main.main.classList.add(this.classes.disabled),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute("d",this.classes.arrowOpen),this.main.main.classList.add("up"===this.settings.openPosition?this.classes.openAbove:this.classes.openBelow),this.moveContent(),this.renderOptions(this.store.getData()),"relative"===this.settings.contentPosition?this.moveContentBelow():"up"===this.settings.openPosition.toLowerCase()?this.moveContentAbove():"down"===this.settings.openPosition.toLowerCase()?this.moveContentBelow():"up"===this.putContent(this.content.main,this.settings.isOpen)?this.moveContentAbove():this.moveContentBelow();const e=this.store.getSelectedOptions();if(e.length){const t=e[e.length-1].id,s=this.content.list.querySelector('[data-id="'+t+'"]');s&&this.ensureElementInView(this.content.list,s)}}close(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.remove(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.main.arrow.path.setAttribute("d",this.classes.arrowClose)}mainDiv(){const e=document.createElement("div");if(e.tabIndex=0,e.style.cssText=""!==this.settings.style?this.settings.style:"",e.className="",e.classList.add(this.settings.id),e.classList.add(this.classes.main),this.settings.class)for(const t of this.settings.class)""!==t.trim()&&e.classList.add(t.trim());e.onfocus=()=>{this.settings.triggerFocus&&this.callbacks.open()},e.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Enter":const t=this.content.list.querySelector("."+this.classes.highlighted);return t&&t.click(),!1;case"Escape":return this.callbacks.close(),!1}},e.onclick=e=>{this.settings.isEnabled&&(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};const t=document.createElement("div");t.classList.add(this.classes.values),e.appendChild(t);const s=document.createElement("div");s.classList.add(this.classes.deselect),this.settings.allowDeselect&&!this.settings.isMultiple||s.classList.add(this.classes.hide),s.onclick=e=>{if(e.stopPropagation(),!this.settings.isEnabled)return;let t=!0;const s=this.store.getSelectedOptions(),i=[];this.callbacks.beforeChange&&(t=!0===this.callbacks.beforeChange(i,s)),t&&(this.callbacks.setSelected([""]),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(i))};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",this.classes.deselectPath),i.appendChild(n),s.appendChild(i),e.appendChild(s);const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.classList.add(this.classes.arrow),l.setAttribute("viewBox","0 0 100 100");const a=document.createElementNS("http://www.w3.org/2000/svg","path");return a.setAttribute("d",this.classes.arrowClose),this.settings.alwaysOpen&&l.classList.add(this.classes.hide),l.appendChild(a),e.appendChild(l),{main:e,values:t,deselect:{main:s,svg:i,path:n},arrow:{main:l,path:a}}}mainFocus(e){e||(this.settings.triggerFocus=!1),this.main.main.focus({preventScroll:!0}),this.settings.triggerFocus=!0}placeholder(){const e=this.store.filter((e=>e.placeholder),!1);let t=this.settings.placeholderText;e.length&&(""!==e[0].html?t=e[0].html:""!==e[0].text&&(t=e[0].text));const s=document.createElement("div");return s.classList.add(this.classes.placeholder),s.innerHTML=t,s}renderValues(){this.settings.isMultiple?this.renderMultipleValues():this.renderSingleValue()}renderSingleValue(){const e=this.store.filter((e=>e.selected&&!e.placeholder),!1),t=e.length>0?e[0]:null;if(t){const e=document.createElement("div");e.classList.add(this.classes.single),e.innerHTML=t.html?t.html:t.text,this.main.values.innerHTML=e.outerHTML}else this.main.values.innerHTML=this.placeholder().outerHTML;this.settings.allowDeselect&&e.length?this.main.deselect.main.classList.remove(this.classes.hide):this.main.deselect.main.classList.add(this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter((e=>e.selected&&e.display),!1);if(0===t.length)return void(this.main.values.innerHTML=this.placeholder().outerHTML);{const e=this.main.values.querySelector("."+this.classes.placeholder);e&&e.remove()}let s=[];for(let i=0;i<e.length;i++){const n=e[i],l=n.getAttribute("data-id");if(l){t.filter((e=>e.id===l),!1).length||s.push(n)}}for(const e of s)e.classList.add(this.classes.valueOut),setTimeout((()=>{this.main.values.removeChild(e)}),100);e=this.main.values.childNodes;for(let s=0;s<t.length;s++){let i=!0;for(let n=0;n<e.length;n++)t[s].id===String(e[n].dataset.id)&&(i=!1);i&&(0===e.length?this.main.values.appendChild(this.multipleValue(t[s])):0===s?this.main.values.insertBefore(this.multipleValue(t[s]),e[s]):e[s-1].insertAdjacentElement("afterend",this.multipleValue(t[s])))}}multipleValue(e){const t=document.createElement("div");t.classList.add(this.classes.value),t.dataset.id=e.id;const n=document.createElement("div");if(n.classList.add(this.classes.valueText),n.innerHTML=e.text,t.appendChild(n),!e.mandatory){const n=document.createElement("div");n.classList.add(this.classes.valueDelete),n.onclick=t=>{t.preventDefault(),t.stopPropagation();let n=!0;const l=this.store.getSelectedOptions(),a=l.filter((t=>t.selected&&t.id!==e.id),!0);if(!(this.settings.minSelected&&a.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(n=!0===this.callbacks.beforeChange(a,l)),n)){let e=[];for(const t of a){if(t instanceof s)for(const s of t.options)e.push(s.value);t instanceof i&&e.push(t.value)}this.callbacks.setSelected(e),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(a)}};const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("viewBox","0 0 100 100");const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",this.classes.optionDelete),l.appendChild(a),n.appendChild(l),t.appendChild(n)}return t}contentDiv(){const e=document.createElement("div");if(e.classList.add(this.classes.content),e.dataset.id=this.settings.id,""!==this.settings.style&&(e.style.cssText=this.settings.style),"relative"===this.settings.contentPosition&&e.classList.add("ss-"+this.settings.contentPosition),this.settings.class.length)for(const t of this.settings.class)""!==t.trim()&&e.classList.add(t.trim());const t=this.searchDiv();e.appendChild(t.main);const s=this.listDiv();return e.appendChild(s),{main:e,search:t,list:s}}moveContent(){if("relative"===this.settings.contentPosition)return;const e=this.main.main.getBoundingClientRect();this.content.main.style.top=e.top+e.height+window.scrollY+"px",this.content.main.style.left=e.left+window.scrollX+"px",this.content.main.style.width=e.width+"px"}searchDiv(){const e=document.createElement("div"),s=document.createElement("input"),n=document.createElement("div");e.classList.add(this.classes.search);const l={main:e,input:s};if(this.settings.showSearch||(e.classList.add(this.classes.hide),s.readOnly=!0),s.type="search",s.placeholder=this.settings.searchPlaceholder,s.tabIndex=-1,s.setAttribute("aria-label",this.settings.searchPlaceholder),s.setAttribute("autocapitalize","off"),s.setAttribute("autocomplete","off"),s.setAttribute("autocorrect","off"),s.oninput=t((e=>{this.callbacks.search(e.target.value)}),100),s.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Escape":return this.callbacks.close(),!1;case"Enter":if(this.callbacks.addable&&e.ctrlKey)n.click();else{const e=this.content.list.querySelector("."+this.classes.highlighted);e&&e.click()}return!1}},s.onfocus=()=>{this.settings.isOpen||this.callbacks.open()},e.appendChild(s),this.callbacks.addable){n.classList.add(this.classes.addable);const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 100 100");const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",this.classes.addablePath),t.appendChild(s),n.appendChild(t),n.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;const t=this.content.search.input.value.trim();if(""===t)return void this.content.search.input.focus();const s=e=>{let t=new i(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.value),this.callbacks.setSelected(e)}else this.callbacks.setSelected([t.value]);this.callbacks.search(""),this.settings.closeOnSelect&&setTimeout((()=>{this.callbacks.close()}),100)},n=this.callbacks.addable(t);n instanceof Promise?n.then((e=>{s("string"==typeof e?{text:e,value:e}:e)})):s("string"==typeof n?{text:n,value:n}:n)},e.appendChild(n),l.addable={main:n,svg:t,path:s}}return l}searchFocus(e){e||(this.settings.triggerFocus=!1),this.content.search.input.focus(),this.settings.triggerFocus=!0}getOptions(e=!1,t=!1,s=!1){let i="."+this.classes.option;return e&&(i+=":not(."+this.classes.placeholder+")"),t&&(i+=":not(."+this.classes.disabled+")"),s&&(i+=":not(."+this.classes.hide+")"),Array.from(this.content.list.querySelectorAll(i))}highlight(e){const t=this.getOptions(!0,!0,!0);if(0!==t.length)if(1!==t.length||t[0].classList.contains(this.classes.highlighted)){for(let s=0;s<t.length;s++)if(t[s].classList.contains(this.classes.highlighted)){const i=t[s];i.classList.remove(this.classes.highlighted);const n=i.parentElement;if(n&&n.classList.contains(this.classes.open)){const e=n.querySelector("."+this.classes.optgroupLabel);e&&e.click()}let l=t["down"===e?s+1<t.length?s+1:0:s-1>=0?s-1:t.length-1];l.classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,l);const a=l.parentElement;if(a&&a.classList.contains(this.classes.close)){const e=a.querySelector("."+this.classes.optgroupLabel);e&&e.click()}return}t["down"===e?0:t.length-1].classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,t["down"===e?0:t.length-1])}else t[0].classList.add(this.classes.highlighted)}listDiv(){const e=document.createElement("div");return e.classList.add(this.classes.list),e.setAttribute("role","listbox"),e}renderError(e){this.content.list.innerHTML="";const t=document.createElement("div");t.classList.add(this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.content.list.innerHTML="";const e=document.createElement("div");e.classList.add(this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e)}renderOptions(e){if(this.content.list.innerHTML="",0===e.length){const e=document.createElement("div");return e.classList.add(this.classes.option),e.classList.add(this.classes.disabled),e.innerHTML=this.settings.searchText,void this.content.list.appendChild(e)}for(const t of e){if(t instanceof s){const e=document.createElement("div");e.classList.add(this.classes.optgroup);const s=document.createElement("div");s.classList.add(this.classes.optgroupLabel),e.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.optgroupLabelText),i.textContent=t.label,s.appendChild(i);const n=document.createElement("div");if(n.classList.add(this.classes.optgroupActions),s.appendChild(n),this.settings.isMultiple&&t.selectAll){const e=document.createElement("div");e.classList.add(this.classes.optgroupSelectAll);let s=!0;for(const e of t.options)if(!e.selected){s=!1;break}s&&e.classList.add(this.classes.selected);const i=document.createElement("span");i.textContent="Select All",e.appendChild(i);const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("viewBox","0 0 100 100"),e.appendChild(l);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",this.classes.optgroupSelectAllBox),l.appendChild(a);const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.classes.optgroupSelectAllCheck),l.appendChild(o),e.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation();const i=this.store.getSelected();if(s){const e=i.filter((e=>{for(const s of t.options)if(e===s.value)return!1;return!0}));this.callbacks.setSelected(e)}else{const e=i.concat(t.options.map((e=>e.value)));this.callbacks.setSelected(e)}})),n.appendChild(e)}if("off"!==t.closable){const i=document.createElement("div");i.classList.add(this.classes.optgroupClosable);const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("viewBox","0 0 100 100"),l.classList.add(this.classes.arrow),i.appendChild(l);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",this.classes.arrow),l.appendChild(a),t.options.some((e=>e.selected))?(i.classList.add(this.classes.open),a.setAttribute("d",this.classes.arrowOpen)):"open"===t.closable?(e.classList.add(this.classes.open),a.setAttribute("d",this.classes.arrowOpen)):"close"===t.closable&&(e.classList.add(this.classes.close),a.setAttribute("d",this.classes.arrowClose)),s.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),e.classList.contains(this.classes.close)?(e.classList.remove(this.classes.close),e.classList.add(this.classes.open),a.setAttribute("d",this.classes.arrowOpen)):(e.classList.remove(this.classes.open),e.classList.add(this.classes.close),a.setAttribute("d",this.classes.arrowClose))})),n.appendChild(i)}e.appendChild(s);for(const s of t.options)e.appendChild(this.option(s));this.content.list.appendChild(e)}t instanceof i&&this.content.list.appendChild(this.option(t))}}option(e){if(e.placeholder){const e=document.createElement("div");return e.classList.add(this.classes.option),e.classList.add(this.classes.hide),e}const t=document.createElement("div");if(t.dataset.id=e.id,t.classList.add(this.classes.option),t.setAttribute("role","option"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.style&&(t.style.cssText=e.style),this.settings.searchHighlight&&""!==this.content.search.input.value.trim()){const s=""!==e.html?e.html:e.text;t.innerHTML=this.highlightText(s,this.content.search.input.value,this.classes.searchHighlighter)}else""!==e.html?t.innerHTML=e.html:t.textContent=e.text;return this.settings.showOptionTooltips&&t.textContent&&t.setAttribute("title",t.textContent),(e.selected&&!this.settings.allowDeselect||e.disabled&&!this.settings.allowDeselect)&&t.classList.add(this.classes.disabled),e.selected&&this.settings.hideSelected&&t.classList.add(this.classes.hide),e.selected?t.classList.add(this.classes.selected):t.classList.remove(this.classes.selected),t.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation();const s=this.store.getSelected(),i=t.currentTarget,n=String(i.dataset.id);if(e.disabled||e.selected&&!this.settings.allowDeselect)return;if(this.settings.isMultiple&&Array.isArray(s)&&this.settings.maxSelected<=s.length)return;let l=!1;const a=this.store.getSelectedOptions();let o=[];this.settings.isMultiple&&(o=e.selected?a.filter((e=>e.id!==n)):a.concat(e)),this.settings.isMultiple||(o=e.selected?[]:[e]),this.callbacks.beforeChange||(l=!0),this.callbacks.beforeChange&&(l=!1!==this.callbacks.beforeChange(o,a)),l&&(this.store.getOptionByID(n)||this.callbacks.addOption(e),this.callbacks.setSelected(o.map((e=>e.value))),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(o))})),t}destroy(){this.main.main.remove(),this.content.main.remove()}highlightText(e,t,s){let i=e;const n=new RegExp("("+t.trim()+")(?![^<]*>[^<>]*</)","i");if(!e.match(n))return e;const l=e.match(n).index,a=l+e.match(n)[0].toString().length,o=e.substring(l,a);return i=i.replace(n,`<mark class="${s}">${o}</mark>`),i}moveContentAbove(){const e=this.main.main.offsetHeight+this.content.main.offsetHeight-1;this.content.main.style.margin="-"+e+"px 0px 0px 0px",this.content.main.style.transformOrigin="center bottom",this.main.main.classList.remove(this.classes.openBelow),this.main.main.classList.add(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.content.main.classList.add(this.classes.openAbove)}moveContentBelow(){this.content.main.style.margin="-1px 0px 0px 0px",this.content.main.style.transformOrigin="center top",this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.add(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.add(this.classes.openBelow)}ensureElementInView(e,t){const s=e.scrollTop+e.offsetTop,i=s+e.clientHeight,n=t.offsetTop,l=n+t.clientHeight;n<s?e.scrollTop-=s-n:l>i&&(e.scrollTop+=l-i)}putContent(e,t){const s=e.offsetHeight,i=e.getBoundingClientRect(),n=t?i.top:i.top-s,l=t?i.bottom:i.bottom+s;return n<=0?"down":l>=window.innerHeight?"up":"down"}}class a{constructor(e){this.listen=!1,this.observer=null,this.select=e}enable(){this.disconnectObserver(),this.select.disabled=!1,this.connectObserver()}disable(){this.disconnectObserver(),this.select.disabled=!0,this.connectObserver()}hideUI(){this.select.tabIndex=-1,this.select.style.display="none",this.select.setAttribute("aria-hidden","true")}showUI(){this.select.removeAttribute("tabindex"),this.select.style.display="",this.select.removeAttribute("aria-hidden")}changeListen(e){this.listen=e,this.listen?this.connectObserver():this.disconnectObserver()}addSelectChangeListener(e){this.onSelectChange=e,this.addObserver(),this.connectObserver(),this.changeListen(!0)}removeSelectChangeListener(){this.changeListen(!1),this.onSelectChange=void 0}addValueChangeListener(e){this.onValueChange=e,this.select.addEventListener("change",this.valueChange.bind(this))}removeValueChangeListener(){this.onValueChange=void 0,this.select.removeEventListener("change",this.valueChange.bind(this))}valueChange(e){this.onValueChange&&this.onValueChange(this.getSelectedValues())}observeWrapper(e){this.onSelectChange&&(this.changeListen(!1),this.onSelectChange(this.getData()),this.changeListen(!0))}addObserver(){this.observer&&(this.disconnectObserver(),this.observer=null),this.observer=new MutationObserver(this.observeWrapper.bind(this))}connectObserver(){this.observer&&this.observer.observe(this.select,{childList:!0})}disconnectObserver(){this.observer&&this.observer.disconnect()}getData(){let e=[];const t=this.select.childNodes;for(const s of t)"OPTGROUP"===s.nodeName&&e.push(this.getDataFromOptgroup(s)),"OPTION"===s.nodeName&&e.push(this.getDataFromOption(s));return e}getDataFromOptgroup(e){let t={id:!!e.dataset&&e.dataset.id||"",label:e.label,selectAll:!!e.dataset&&"true"===e.dataset.selectall,closable:e.dataset?e.dataset.closable:"off",options:[]};const s=e.childNodes;for(const e of s)"OPTION"===e.nodeName&&t.options.push(this.getDataFromOption(e));return t}getDataFromOption(e){return{id:!!e.dataset&&e.dataset.id||"",value:e.value,text:e.text,html:e.innerHTML,selected:e.selected,display:"none"!==e.style.display,disabled:e.disabled,mandatory:!!e.dataset&&"true"===e.dataset.mandatory,placeholder:"true"===e.dataset.placeholder,class:e.className,style:e.style.cssText,data:e.dataset}}getSelectedValues(){let e=[];const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}return e}setSelected(e){const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}}updateSelect(e,t,s){this.changeListen(!1),e&&(this.select.id=e),t&&(this.select.style.cssText=t),s&&(this.select.className="",s.forEach((e=>{""!==e.trim()&&this.select.classList.add(e.trim())}))),this.changeListen(!0)}updateOptions(e){this.changeListen(!1),this.select.innerHTML="";for(const t of e)t instanceof s&&this.select.appendChild(this.createOptgroup(t)),t instanceof i&&this.select.appendChild(this.createOption(t));this.changeListen(!0)}createOptgroup(e){const t=document.createElement("optgroup");if(t.id=e.id,t.label=e.label,e.selectAll&&(t.dataset.selectAll="true"),"off"!==e.closable&&(t.dataset.closable=e.closable),e.options)for(const s of e.options)t.appendChild(this.createOption(s));return t}createOption(e){const t=document.createElement("option");return t.value=""!==e.value?e.value:e.text,t.innerHTML=e.html||e.text,e.selected&&(t.selected=e.selected),e.disabled&&(t.disabled=!0),!1===e.display&&(t.style.display="none"),e.placeholder&&t.setAttribute("data-placeholder","true"),e.mandatory&&t.setAttribute("data-mandatory","true"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.data&&"object"==typeof e.data&&Object.keys(e.data).forEach((s=>{t.setAttribute("data-"+function(e){const t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase()));return e[0]===e[0].toUpperCase()?t.substring(1):t}(s),e.data[s])})),t}destroy(){this.changeListen(!1),this.disconnectObserver(),this.removeSelectChangeListener(),this.removeValueChangeListener(),this.showUI()}}class o{constructor(t){this.id="",this.style="",this.class=[],this.isMultiple=!1,this.isOpen=!1,this.triggerFocus=!0,this.intervalMove=null,t||(t={}),this.id="ss-"+e(),this.style=t.style||"",this.class=t.class||[],this.isEnabled=void 0===t.isEnabled||t.isEnabled,this.alwaysOpen=void 0!==t.alwaysOpen&&t.alwaysOpen,this.showSearch=void 0===t.showSearch||t.showSearch,this.searchPlaceholder=t.searchPlaceholder||"Search",this.searchText=t.searchText||"No Results",this.searchingText=t.searchingText||"Searching...",this.searchHighlight=void 0!==t.searchHighlight&&t.searchHighlight,this.closeOnSelect=void 0===t.closeOnSelect||t.closeOnSelect,this.contentLocation=t.contentLocation||document.body,this.contentPosition=t.contentPosition||"absolute",this.openPosition=t.openPosition||"auto",this.placeholderText=t.placeholderText||"Select Value",this.allowDeselect=void 0!==t.allowDeselect&&t.allowDeselect,this.hideSelected=void 0!==t.hideSelected&&t.hideSelected,this.showOptionTooltips=void 0!==t.showOptionTooltips&&t.showOptionTooltips,this.minSelected=t.minSelected||0,this.maxSelected=t.maxSelected||1e3,this.timeoutDelay=t.timeoutDelay||200}}return class{constructor(e){if(this.events={search:void 0,searchFilter:(e,t)=>-1!==e.text.toLowerCase().indexOf(t.toLowerCase()),addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0},this.windowResize=t((()=>{this.settings.isOpen&&this.render.moveContent()})),this.windowScroll=t((()=>{this.settings.isOpen&&("down"!==this.settings.openPosition?"up"!==this.settings.openPosition?"relative"===this.settings.contentPosition?this.render.moveContentBelow():"up"===this.render.putContent(this.render.content.main,this.settings.isOpen)?this.render.moveContentAbove():this.render.moveContentBelow():this.render.moveContentAbove():this.render.moveContentBelow())})),this.documentClick=e=>{this.settings.isOpen&&e.target&&!function(e,t){function s(e,s){return s&&e&&e.classList&&e.classList.contains(s)||s&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}return s(e,t)||function e(t,i){return t&&t!==document?s(t,i)?t:e(t.parentNode,i):null}(e,t)}(e.target,this.settings.id)&&this.close()},this.selectEl="string"==typeof e.select?document.querySelector(e.select):e.select,!this.selectEl)return void(e.events&&e.events.error&&e.events.error(new Error("Could not find select element")));if("SELECT"!==this.selectEl.tagName)return void(e.events&&e.events.error&&e.events.error(new Error("Element isnt of type select")));this.selectEl.dataset.ssid&&this.destroy(),this.settings=new o(e.settings);for(const t in e.events)e.events.hasOwnProperty(t)&&(this.events[t]=e.events[t]);this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(" "),this.select=new a(this.selectEl),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.addSelectChangeListener((e=>{this.setData(e)})),this.select.addValueChangeListener((e=>{this.setSelected(e)})),this.store=new n(this.settings.isMultiple?"multiple":"single",e.data?e.data:this.select.getData()),e.data&&this.select.updateOptions(this.store.getData());const s={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:this.setSelected.bind(this),addOption:this.addOption.bind(this),search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.render=new l(this.settings,this.store,s),this.render.renderValues(),this.render.renderOptions(this.store.getData()),this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),document.addEventListener("click",this.documentClick),window.addEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.addEventListener("scroll",this.windowScroll,!1),this.settings.isEnabled||this.disable(),this.settings.alwaysOpen&&this.open(),this.selectEl.slim=this}enable(){this.settings.isEnabled=!0,this.select.enable(),this.render.enable()}disable(){this.settings.isEnabled=!1,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){const t=this.store.validateDataArray(e);if(t)return void(this.events.error&&this.events.error(t));this.store.setData(e);const s=this.store.getData();this.select.updateOptions(s),this.render.renderValues(),this.render.renderOptions(s)}getSelected(){return this.store.getSelected()}setSelected(e){this.store.setSelectedBy("value",Array.isArray(e)?e:[e]);const t=this.store.getData();this.select.updateOptions(t),this.render.renderValues(),this.render.renderOptions(t)}addOption(e){this.store.addOption(e);const t=this.store.getData();this.select.updateOptions(t),this.render.renderValues(),this.render.renderOptions(t)}open(){this.settings.isEnabled&&!this.settings.isOpen&&(this.events.beforeOpen&&this.events.beforeOpen(),this.render.open(),this.settings.showSearch&&this.render.searchFocus(!1),setTimeout((()=>{this.events.afterOpen&&this.events.afterOpen(),this.settings.isOpen=!0}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove),this.settings.intervalMove=setInterval(this.render.moveContent.bind(this.render),500))}close(){this.settings.isOpen&&!this.settings.alwaysOpen&&(this.events.beforeClose&&this.events.beforeClose(),this.render.close(),this.search(""),this.render.mainFocus(!1),setTimeout((()=>{this.events.afterClose&&this.events.afterClose(),this.settings.isOpen=!1}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove))}search(e){if(this.render.content.search.input.value!==e&&(this.render.content.search.input.value=e),!this.events.search)return void this.render.renderOptions(""===e?this.store.getData():this.store.search(e,this.events.searchFilter));this.render.renderSearching();const t=this.events.search(e,this.store.getSelectedOptions());t instanceof Promise?t.then((e=>{this.render.renderOptions(this.store.partialToFullData(e))})).catch((e=>{this.render.renderError("string"==typeof e?e:e.message)})):Array.isArray(t)?this.render.renderOptions(this.store.partialToFullData(t)):this.render.renderError("Search event must return a promise or an array of data")}destroy(){document.removeEventListener("click",this.documentClick),window.removeEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.removeEventListener("scroll",this.windowScroll,!1),this.store.setData([]),this.render.destroy(),this.select.destroy()}}}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SlimSelect=t()}(this,(function(){"use strict";function e(){return Math.random().toString(36).substring(2,10)}function t(e,t=50,s=!1){let i;return function(...n){const l=self,a=s&&!i;clearTimeout(i),i=setTimeout((()=>{i=null,s||e.apply(l,n)}),t),a&&e.apply(l,n)}}function s(e,t){return JSON.stringify(e)===JSON.stringify(t)}class i{constructor(t){this.id="",this.style="",this.class=[],this.isMultiple=!1,this.isOpen=!1,this.triggerFocus=!0,this.intervalMove=null,t||(t={}),this.id="ss-"+e(),this.style=t.style||"",this.class=t.class||[],this.isEnabled=void 0===t.isEnabled||t.isEnabled,this.alwaysOpen=void 0!==t.alwaysOpen&&t.alwaysOpen,this.showSearch=void 0===t.showSearch||t.showSearch,this.searchPlaceholder=t.searchPlaceholder||"Search",this.searchText=t.searchText||"No Results",this.searchingText=t.searchingText||"Searching...",this.searchHighlight=void 0!==t.searchHighlight&&t.searchHighlight,this.closeOnSelect=void 0===t.closeOnSelect||t.closeOnSelect,this.contentLocation=t.contentLocation||document.body,this.contentPosition=t.contentPosition||"absolute",this.openPosition=t.openPosition||"auto",this.placeholderText=t.placeholderText||"Select Value",this.allowDeselect=void 0!==t.allowDeselect&&t.allowDeselect,this.hideSelected=void 0!==t.hideSelected&&t.hideSelected,this.showOptionTooltips=void 0!==t.showOptionTooltips&&t.showOptionTooltips,this.minSelected=t.minSelected||0,this.maxSelected=t.maxSelected||1e3,this.timeoutDelay=t.timeoutDelay||200}}class n{constructor(t){if(this.id=t.id&&""!==t.id?t.id:e(),this.label=t.label||"",this.selectAll=void 0!==t.selectAll&&t.selectAll,this.closable=t.closable||"off",this.options=[],t.options)for(const e of t.options)this.options.push(new l(e))}}class l{constructor(t){this.id=t.id&&""!==t.id?t.id:e(),this.value=void 0===t.value?t.text:t.value,this.text=t.text||"",this.html=t.html||"",this.selected=void 0!==t.selected&&t.selected,this.display=void 0===t.display||t.display,this.disabled=void 0!==t.disabled&&t.disabled,this.mandatory=void 0!==t.mandatory&&t.mandatory,this.placeholder=void 0!==t.placeholder&&t.placeholder,this.class=t.class||"",this.style=t.style||"",this.data=t.data||{}}}class a{constructor(e,t){this.selectType="single",this.data=[],this.selectType=e,this.setData(t)}validateDataArray(e){if(!Array.isArray(e))return new Error("Data must be an array");for(let t of e){if(!(t instanceof n||"label"in t))return t instanceof l||"text"in t?this.validateOption(t):new Error("Data object must be a valid optgroup or option");if(!("label"in t))return new Error("Optgroup must have a label");if("options"in t&&t.options)for(let e of t.options)return this.validateOption(e)}return null}validateOption(e){return"text"in e?null:new Error("Option must have a text")}partialToFullData(e){let t=[];return e.forEach((e=>{if(e instanceof n||"label"in e){let s=[];"options"in e&&e.options&&e.options.forEach((e=>{s.push(new l(e))})),s.length>0&&t.push(new n(e))}(e instanceof l||"text"in e)&&t.push(new l(e))})),t}setData(e){this.data=this.partialToFullData(e),"single"===this.selectType&&this.setSelectedBy("value",this.getSelected())}getData(){return this.filter(null,!0)}getDataOptions(){return this.filter(null,!1)}addOption(e){this.setData(this.getData().concat(new l(e)))}setSelectedBy(e,t){let s=null,i=!1;for(let a of this.data){if(a instanceof n)for(let n of a.options)s||(s=n),n.selected=!i&&t.includes(n[e]),n.selected&&"single"===this.selectType&&(i=!0);a instanceof l&&(s||(s=a),a.selected=!i&&t.includes(a[e]),a.selected&&"single"===this.selectType&&(i=!0))}"single"===this.selectType&&s&&!i&&(s.selected=!0)}getSelected(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.value)})),t}getSelectedOptions(){return this.filter((e=>e.selected),!1)}getSelectedIDs(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.id)})),t}getOptgroupByID(e){for(let t of this.data)if(t instanceof n&&t.id===e)return t;return null}getOptionByID(e){let t=this.filter((t=>t.id===e),!1);return t.length?t[0]:null}search(e,t){return""===(e=e.trim())?this.getData():this.filter((s=>t(s,e)),!0)}filter(e,t){const s=[];return this.data.forEach((i=>{if(i instanceof n)if(t){let t=[];i.options.forEach((s=>{e&&!e(s)||t.push(new l(s))})),t.length>0&&s.push(new n(i))}else i.options.forEach((t=>{e&&e(t)&&s.push(t)}));i instanceof l&&(e&&!e(i)||s.push(new l(i)))})),s}}class o{constructor(e,t,s){this.classes={main:"ss-main",placeholder:"ss-placeholder",values:"ss-values",single:"ss-single",value:"ss-value",valueText:"ss-value-text",valueDelete:"ss-value-delete",valueOut:"ss-value-out",deselect:"ss-deselect",deselectPath:"M10,10 L90,90 M10,90 L90,10",arrow:"ss-arrow",arrowClose:"M10,30 L50,70 L90,30",arrowOpen:"M10,70 L50,30 L90,70",content:"ss-content",openAbove:"ss-open-above",openBelow:"ss-open-below",search:"ss-search",searchHighlighter:"ss-search-highlight",searching:"ss-searching",addable:"ss-addable",addablePath:"M50,10 L50,90 M10,50 L90,50",list:"ss-list",optgroup:"ss-optgroup",optgroupLabel:"ss-optgroup-label",optgroupLabelText:"ss-optgroup-label-text",optgroupActions:"ss-optgroup-actions",optgroupSelectAll:"ss-selectall",optgroupSelectAllBox:"M60,10 L10,10 L10,90 L90,90 L90,50",optgroupSelectAllCheck:"M30,45 L50,70 L90,10",optgroupClosable:"ss-closable",option:"ss-option",optionDelete:"M10,10 L90,90 M10,90 L90,10",highlighted:"ss-highlighted",open:"ss-open",close:"ss-close",selected:"ss-selected",error:"ss-error",disabled:"ss-disabled",hide:"ss-hide"},this.store=t,this.settings=e,this.callbacks=s,this.main=this.mainDiv(),this.content=this.contentDiv(),this.settings.contentLocation.appendChild(this.content.main)}enable(){this.main.main.classList.remove(this.classes.disabled),this.content.search.input.disabled=!1}disable(){this.main.main.classList.add(this.classes.disabled),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute("d",this.classes.arrowOpen),this.main.main.classList.add("up"===this.settings.openPosition?this.classes.openAbove:this.classes.openBelow),this.moveContent(),this.renderOptions(this.store.getData()),"relative"===this.settings.contentPosition?this.moveContentBelow():"up"===this.settings.openPosition.toLowerCase()?this.moveContentAbove():"down"===this.settings.openPosition.toLowerCase()?this.moveContentBelow():"up"===this.putContent(this.content.main,this.settings.isOpen)?this.moveContentAbove():this.moveContentBelow();const e=this.store.getSelectedOptions();if(e.length){const t=e[e.length-1].id,s=this.content.list.querySelector('[data-id="'+t+'"]');s&&this.ensureElementInView(this.content.list,s)}}close(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.remove(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.main.arrow.path.setAttribute("d",this.classes.arrowClose)}mainDiv(){const e=document.createElement("div");if(e.tabIndex=0,e.style.cssText=""!==this.settings.style?this.settings.style:"",e.className="",e.classList.add(this.settings.id),e.classList.add(this.classes.main),this.settings.class)for(const t of this.settings.class)""!==t.trim()&&e.classList.add(t.trim());e.onfocus=()=>{this.settings.triggerFocus&&this.callbacks.open()},e.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Enter":const t=this.content.list.querySelector("."+this.classes.highlighted);return t&&t.click(),!1;case"Escape":return this.callbacks.close(),!1}},e.onclick=e=>{this.settings.isEnabled&&(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};const t=document.createElement("div");t.classList.add(this.classes.values),e.appendChild(t);const s=document.createElement("div");s.classList.add(this.classes.deselect),this.settings.allowDeselect&&!this.settings.isMultiple||s.classList.add(this.classes.hide),s.onclick=e=>{if(e.stopPropagation(),!this.settings.isEnabled)return;let t=!0;const s=this.store.getSelectedOptions(),i=[];this.callbacks.beforeChange&&(t=!0===this.callbacks.beforeChange(i,s)),t&&(this.callbacks.setSelected([""]),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(i))};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",this.classes.deselectPath),i.appendChild(n),s.appendChild(i),e.appendChild(s);const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.classList.add(this.classes.arrow),l.setAttribute("viewBox","0 0 100 100");const a=document.createElementNS("http://www.w3.org/2000/svg","path");return a.setAttribute("d",this.classes.arrowClose),this.settings.alwaysOpen&&l.classList.add(this.classes.hide),l.appendChild(a),e.appendChild(l),{main:e,values:t,deselect:{main:s,svg:i,path:n},arrow:{main:l,path:a}}}mainFocus(e){e||(this.settings.triggerFocus=!1),this.main.main.focus({preventScroll:!0}),this.settings.triggerFocus=!0}placeholder(){const e=this.store.filter((e=>e.placeholder),!1);let t=this.settings.placeholderText;e.length&&(""!==e[0].html?t=e[0].html:""!==e[0].text&&(t=e[0].text));const s=document.createElement("div");return s.classList.add(this.classes.placeholder),s.innerHTML=t,s}renderValues(){this.settings.isMultiple?this.renderMultipleValues():this.renderSingleValue()}renderSingleValue(){const e=this.store.filter((e=>e.selected&&!e.placeholder),!1),t=e.length>0?e[0]:null;if(t){const e=document.createElement("div");e.classList.add(this.classes.single),e.innerHTML=t.html?t.html:t.text,this.main.values.innerHTML=e.outerHTML}else this.main.values.innerHTML=this.placeholder().outerHTML;this.settings.allowDeselect&&e.length?this.main.deselect.main.classList.remove(this.classes.hide):this.main.deselect.main.classList.add(this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter((e=>e.selected&&e.display),!1);if(0===t.length)return void(this.main.values.innerHTML=this.placeholder().outerHTML);{const e=this.main.values.querySelector("."+this.classes.placeholder);e&&e.remove()}let s=[];for(let i=0;i<e.length;i++){const n=e[i],l=n.getAttribute("data-id");if(l){t.filter((e=>e.id===l),!1).length||s.push(n)}}for(const e of s)e.classList.add(this.classes.valueOut),setTimeout((()=>{this.main.values.removeChild(e)}),100);e=this.main.values.childNodes;for(let s=0;s<t.length;s++){let i=!0;for(let n=0;n<e.length;n++)t[s].id===String(e[n].dataset.id)&&(i=!1);i&&(0===e.length?this.main.values.appendChild(this.multipleValue(t[s])):0===s?this.main.values.insertBefore(this.multipleValue(t[s]),e[s]):e[s-1].insertAdjacentElement("afterend",this.multipleValue(t[s])))}}multipleValue(e){const t=document.createElement("div");t.classList.add(this.classes.value),t.dataset.id=e.id;const s=document.createElement("div");if(s.classList.add(this.classes.valueText),s.innerHTML=e.text,t.appendChild(s),!e.mandatory){const s=document.createElement("div");s.classList.add(this.classes.valueDelete),s.onclick=t=>{t.preventDefault(),t.stopPropagation();let s=!0;const i=this.store.getSelectedOptions(),a=i.filter((t=>t.selected&&t.id!==e.id),!0);if(!(this.settings.minSelected&&a.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(s=!0===this.callbacks.beforeChange(a,i)),s)){let e=[];for(const t of a){if(t instanceof n)for(const s of t.options)e.push(s.value);t instanceof l&&e.push(t.value)}this.callbacks.setSelected(e),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(a)}};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",this.classes.optionDelete),i.appendChild(a),s.appendChild(i),t.appendChild(s)}return t}contentDiv(){const e=document.createElement("div");if(e.classList.add(this.classes.content),e.dataset.id=this.settings.id,""!==this.settings.style&&(e.style.cssText=this.settings.style),"relative"===this.settings.contentPosition&&e.classList.add("ss-"+this.settings.contentPosition),this.settings.class.length)for(const t of this.settings.class)""!==t.trim()&&e.classList.add(t.trim());const t=this.searchDiv();e.appendChild(t.main);const s=this.listDiv();return e.appendChild(s),{main:e,search:t,list:s}}moveContent(){if("relative"===this.settings.contentPosition)return;const e=this.main.main.getBoundingClientRect();this.content.main.style.top=e.top+e.height+window.scrollY+"px",this.content.main.style.left=e.left+window.scrollX+"px",this.content.main.style.width=e.width+"px"}searchDiv(){const e=document.createElement("div"),s=document.createElement("input"),i=document.createElement("div");e.classList.add(this.classes.search);const n={main:e,input:s};if(this.settings.showSearch||(e.classList.add(this.classes.hide),s.readOnly=!0),s.type="search",s.placeholder=this.settings.searchPlaceholder,s.tabIndex=-1,s.setAttribute("aria-label",this.settings.searchPlaceholder),s.setAttribute("autocapitalize","off"),s.setAttribute("autocomplete","off"),s.setAttribute("autocorrect","off"),s.oninput=t((e=>{this.callbacks.search(e.target.value)}),100),s.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Escape":return this.callbacks.close(),!1;case"Enter":if(this.callbacks.addable&&e.ctrlKey)i.click();else{const e=this.content.list.querySelector("."+this.classes.highlighted);e&&e.click()}return!1}},s.onfocus=()=>{this.settings.isOpen||this.callbacks.open()},e.appendChild(s),this.callbacks.addable){i.classList.add(this.classes.addable);const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 100 100");const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",this.classes.addablePath),t.appendChild(s),i.appendChild(t),i.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;const t=this.content.search.input.value.trim();if(""===t)return void this.content.search.input.focus();const s=e=>{let t=new l(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.value),this.callbacks.setSelected(e)}else this.callbacks.setSelected([t.value]);this.callbacks.search(""),this.settings.closeOnSelect&&setTimeout((()=>{this.callbacks.close()}),100)},i=this.callbacks.addable(t);i instanceof Promise?i.then((e=>{s("string"==typeof e?{text:e,value:e}:e)})):s("string"==typeof i?{text:i,value:i}:i)},e.appendChild(i),n.addable={main:i,svg:t,path:s}}return n}searchFocus(e){e||(this.settings.triggerFocus=!1),this.content.search.input.focus(),this.settings.triggerFocus=!0}getOptions(e=!1,t=!1,s=!1){let i="."+this.classes.option;return e&&(i+=":not(."+this.classes.placeholder+")"),t&&(i+=":not(."+this.classes.disabled+")"),s&&(i+=":not(."+this.classes.hide+")"),Array.from(this.content.list.querySelectorAll(i))}highlight(e){const t=this.getOptions(!0,!0,!0);if(0!==t.length)if(1!==t.length||t[0].classList.contains(this.classes.highlighted)){for(let s=0;s<t.length;s++)if(t[s].classList.contains(this.classes.highlighted)){const i=t[s];i.classList.remove(this.classes.highlighted);const n=i.parentElement;if(n&&n.classList.contains(this.classes.open)){const e=n.querySelector("."+this.classes.optgroupLabel);e&&e.click()}let l=t["down"===e?s+1<t.length?s+1:0:s-1>=0?s-1:t.length-1];l.classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,l);const a=l.parentElement;if(a&&a.classList.contains(this.classes.close)){const e=a.querySelector("."+this.classes.optgroupLabel);e&&e.click()}return}t["down"===e?0:t.length-1].classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,t["down"===e?0:t.length-1])}else t[0].classList.add(this.classes.highlighted)}listDiv(){const e=document.createElement("div");return e.classList.add(this.classes.list),e.setAttribute("role","listbox"),e}renderError(e){this.content.list.innerHTML="";const t=document.createElement("div");t.classList.add(this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.content.list.innerHTML="";const e=document.createElement("div");e.classList.add(this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e)}renderOptions(e){if(this.content.list.innerHTML="",0===e.length){const e=document.createElement("div");return e.classList.add(this.classes.option),e.classList.add(this.classes.disabled),e.innerHTML=this.settings.searchText,void this.content.list.appendChild(e)}for(const t of e){if(t instanceof n){const e=document.createElement("div");e.classList.add(this.classes.optgroup);const s=document.createElement("div");s.classList.add(this.classes.optgroupLabel),e.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.optgroupLabelText),i.textContent=t.label,s.appendChild(i);const n=document.createElement("div");if(n.classList.add(this.classes.optgroupActions),s.appendChild(n),this.settings.isMultiple&&t.selectAll){const e=document.createElement("div");e.classList.add(this.classes.optgroupSelectAll);let s=!0;for(const e of t.options)if(!e.selected){s=!1;break}s&&e.classList.add(this.classes.selected);const i=document.createElement("span");i.textContent="Select All",e.appendChild(i);const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("viewBox","0 0 100 100"),e.appendChild(l);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",this.classes.optgroupSelectAllBox),l.appendChild(a);const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.classes.optgroupSelectAllCheck),l.appendChild(o),e.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation();const i=this.store.getSelected();if(s){const e=i.filter((e=>{for(const s of t.options)if(e===s.value)return!1;return!0}));this.callbacks.setSelected(e)}else{const e=i.concat(t.options.map((e=>e.value)));this.callbacks.setSelected(e)}})),n.appendChild(e)}if("off"!==t.closable){const i=document.createElement("div");i.classList.add(this.classes.optgroupClosable);const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("viewBox","0 0 100 100"),l.classList.add(this.classes.arrow),i.appendChild(l);const a=document.createElementNS("http://www.w3.org/2000/svg","path");l.appendChild(a),t.options.some((e=>e.selected))?(i.classList.add(this.classes.open),a.setAttribute("d",this.classes.arrowOpen)):"open"===t.closable?(e.classList.add(this.classes.open),a.setAttribute("d",this.classes.arrowOpen)):"close"===t.closable&&(e.classList.add(this.classes.close),a.setAttribute("d",this.classes.arrowClose)),s.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),e.classList.contains(this.classes.close)?(e.classList.remove(this.classes.close),e.classList.add(this.classes.open),a.setAttribute("d",this.classes.arrowOpen)):(e.classList.remove(this.classes.open),e.classList.add(this.classes.close),a.setAttribute("d",this.classes.arrowClose))})),n.appendChild(i)}e.appendChild(s);for(const s of t.options)e.appendChild(this.option(s));this.content.list.appendChild(e)}t instanceof l&&this.content.list.appendChild(this.option(t))}}option(e){if(e.placeholder){const e=document.createElement("div");return e.classList.add(this.classes.option),e.classList.add(this.classes.hide),e}const t=document.createElement("div");if(t.dataset.id=e.id,t.classList.add(this.classes.option),t.setAttribute("role","option"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.style&&(t.style.cssText=e.style),this.settings.searchHighlight&&""!==this.content.search.input.value.trim()){const s=""!==e.html?e.html:e.text;t.innerHTML=this.highlightText(s,this.content.search.input.value,this.classes.searchHighlighter)}else""!==e.html?t.innerHTML=e.html:t.textContent=e.text;return this.settings.showOptionTooltips&&t.textContent&&t.setAttribute("title",t.textContent),(e.selected&&!this.settings.allowDeselect||e.disabled&&!this.settings.allowDeselect)&&t.classList.add(this.classes.disabled),e.selected&&this.settings.hideSelected&&t.classList.add(this.classes.hide),e.selected?t.classList.add(this.classes.selected):t.classList.remove(this.classes.selected),t.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation();const s=this.store.getSelected(),i=t.currentTarget,n=String(i.dataset.id);if(e.disabled||e.selected&&!this.settings.allowDeselect)return;if(this.settings.isMultiple&&Array.isArray(s)&&this.settings.maxSelected<=s.length)return;let l=!1;const a=this.store.getSelectedOptions();let o=[];this.settings.isMultiple&&(o=e.selected?a.filter((e=>e.id!==n)):a.concat(e)),this.settings.isMultiple||(o=e.selected?[]:[e]),this.callbacks.beforeChange||(l=!0),this.callbacks.beforeChange&&(l=!1!==this.callbacks.beforeChange(o,a)),l&&(this.store.getOptionByID(n)||this.callbacks.addOption(e),this.callbacks.setSelected(o.map((e=>e.value))),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(o))})),t}destroy(){this.main.main.remove(),this.content.main.remove()}highlightText(e,t,s){let i=e;const n=new RegExp("("+t.trim()+")(?![^<]*>[^<>]*</)","i");if(!e.match(n))return e;const l=e.match(n).index,a=l+e.match(n)[0].toString().length,o=e.substring(l,a);return i=i.replace(n,`<mark class="${s}">${o}</mark>`),i}moveContentAbove(){const e=this.main.main.offsetHeight+this.content.main.offsetHeight-1;this.content.main.style.margin="-"+e+"px 0px 0px 0px",this.content.main.style.transformOrigin="center bottom",this.main.main.classList.remove(this.classes.openBelow),this.main.main.classList.add(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.content.main.classList.add(this.classes.openAbove)}moveContentBelow(){this.content.main.style.margin="-1px 0px 0px 0px",this.content.main.style.transformOrigin="center top",this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.add(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.add(this.classes.openBelow)}ensureElementInView(e,t){const s=e.scrollTop+e.offsetTop,i=s+e.clientHeight,n=t.offsetTop,l=n+t.clientHeight;n<s?e.scrollTop-=s-n:l>i&&(e.scrollTop+=l-i)}putContent(e,t){const s=e.offsetHeight,i=e.getBoundingClientRect(),n=t?i.top:i.top-s,l=t?i.bottom:i.bottom+s;return n<=0?"down":l>=window.innerHeight?"up":"down"}}class c{constructor(e){this.listen=!1,this.observer=null,this.select=e}enable(){this.disconnectObserver(),this.select.disabled=!1,this.connectObserver()}disable(){this.disconnectObserver(),this.select.disabled=!0,this.connectObserver()}hideUI(){this.select.tabIndex=-1,this.select.style.display="none",this.select.setAttribute("aria-hidden","true")}showUI(){this.select.removeAttribute("tabindex"),this.select.style.display="",this.select.removeAttribute("aria-hidden")}changeListen(e){this.listen=e,this.listen?this.connectObserver():this.disconnectObserver()}addSelectChangeListener(e){this.onSelectChange=e,this.addObserver(),this.connectObserver(),this.changeListen(!0)}removeSelectChangeListener(){this.changeListen(!1),this.onSelectChange=void 0}addValueChangeListener(e){this.onValueChange=e,this.select.addEventListener("change",this.valueChange.bind(this),{passive:!0})}removeValueChangeListener(){this.onValueChange=void 0,this.select.removeEventListener("change",this.valueChange.bind(this))}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedValues()),!0}observeWrapper(e){this.onSelectChange&&(this.changeListen(!1),this.onSelectChange(this.getData()),this.changeListen(!0))}addObserver(){this.observer&&(this.disconnectObserver(),this.observer=null),this.observer=new MutationObserver(this.observeWrapper.bind(this))}connectObserver(){this.observer&&this.observer.observe(this.select,{childList:!0})}disconnectObserver(){this.observer&&this.observer.disconnect()}getData(){let e=[];const t=this.select.childNodes;for(const s of t)"OPTGROUP"===s.nodeName&&e.push(this.getDataFromOptgroup(s)),"OPTION"===s.nodeName&&e.push(this.getDataFromOption(s));return e}getDataFromOptgroup(e){let t={id:!!e.dataset&&e.dataset.id||"",label:e.label,selectAll:!!e.dataset&&"true"===e.dataset.selectall,closable:e.dataset?e.dataset.closable:"off",options:[]};const s=e.childNodes;for(const e of s)"OPTION"===e.nodeName&&t.options.push(this.getDataFromOption(e));return t}getDataFromOption(e){return{id:!!e.dataset&&e.dataset.id||"",value:e.value,text:e.text,html:e.innerHTML,selected:e.selected,display:"none"!==e.style.display,disabled:e.disabled,mandatory:!!e.dataset&&"true"===e.dataset.mandatory,placeholder:"true"===e.dataset.placeholder,class:e.className,style:e.style.cssText,data:e.dataset}}getSelectedValues(){let e=[];const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}return e}setSelected(e){const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}}updateSelect(e,t,s){this.changeListen(!1),e&&(this.select.id=e),t&&(this.select.style.cssText=t),s&&(this.select.className="",s.forEach((e=>{""!==e.trim()&&this.select.classList.add(e.trim())}))),this.changeListen(!0)}updateOptions(e){this.changeListen(!1),this.select.innerHTML="";for(const t of e)t instanceof n&&this.select.appendChild(this.createOptgroup(t)),t instanceof l&&this.select.appendChild(this.createOption(t));this.select.dispatchEvent(new Event("change")),this.changeListen(!0)}createOptgroup(e){const t=document.createElement("optgroup");if(t.id=e.id,t.label=e.label,e.selectAll&&(t.dataset.selectAll="true"),"off"!==e.closable&&(t.dataset.closable=e.closable),e.options)for(const s of e.options)t.appendChild(this.createOption(s));return t}createOption(e){const t=document.createElement("option");return t.value=""!==e.value?e.value:e.text,t.innerHTML=e.html||e.text,e.selected&&(t.selected=e.selected),e.disabled&&(t.disabled=!0),!1===e.display&&(t.style.display="none"),e.placeholder&&t.setAttribute("data-placeholder","true"),e.mandatory&&t.setAttribute("data-mandatory","true"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.data&&"object"==typeof e.data&&Object.keys(e.data).forEach((s=>{t.setAttribute("data-"+function(e){const t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase()));return e[0]===e[0].toUpperCase()?t.substring(1):t}(s),e.data[s])})),t}destroy(){this.changeListen(!1),this.disconnectObserver(),this.removeSelectChangeListener(),this.removeValueChangeListener(),this.showUI()}}return class{constructor(e){if(this.events={search:void 0,searchFilter:(e,t)=>-1!==e.text.toLowerCase().indexOf(t.toLowerCase()),addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0},this.windowResize=t((()=>{this.settings.isOpen&&this.render.moveContent()})),this.windowScroll=t((()=>{this.settings.isOpen&&("down"!==this.settings.openPosition?"up"!==this.settings.openPosition?"relative"===this.settings.contentPosition?this.render.moveContentBelow():"up"===this.render.putContent(this.render.content.main,this.settings.isOpen)?this.render.moveContentAbove():this.render.moveContentBelow():this.render.moveContentAbove():this.render.moveContentBelow())})),this.documentClick=e=>{this.settings.isOpen&&e.target&&!function(e,t){function s(e,s){return s&&e&&e.classList&&e.classList.contains(s)||s&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}return s(e,t)||function e(t,i){return t&&t!==document?s(t,i)?t:e(t.parentNode,i):null}(e,t)}(e.target,this.settings.id)&&this.close()},this.selectEl="string"==typeof e.select?document.querySelector(e.select):e.select,!this.selectEl)return void(e.events&&e.events.error&&e.events.error(new Error("Could not find select element")));if("SELECT"!==this.selectEl.tagName)return void(e.events&&e.events.error&&e.events.error(new Error("Element isnt of type select")));this.selectEl.dataset.ssid&&this.destroy(),this.settings=new i(e.settings);for(const t in e.events)e.events.hasOwnProperty(t)&&(this.events[t]=e.events[t]);this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(" "),this.select=new c(this.selectEl),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.addSelectChangeListener((e=>{this.setData(e)})),this.select.addValueChangeListener((e=>{this.setSelected(e)})),this.store=new a(this.settings.isMultiple?"multiple":"single",e.data?e.data:this.select.getData()),e.data&&this.select.updateOptions(this.store.getData());const s={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:this.setSelected.bind(this),addOption:this.addOption.bind(this),search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.render=new o(this.settings,this.store,s),this.render.renderValues(),this.render.renderOptions(this.store.getData()),this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),document.addEventListener("click",this.documentClick),window.addEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.addEventListener("scroll",this.windowScroll,!1),this.settings.isEnabled||this.disable(),this.settings.alwaysOpen&&this.open(),this.selectEl.slim=this}enable(){this.settings.isEnabled=!0,this.select.enable(),this.render.enable()}disable(){this.settings.isEnabled=!1,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){const t=this.store.getSelected(),i=this.store.validateDataArray(e);if(i)return void(this.events.error&&this.events.error(i));this.store.setData(e);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),this.render.renderOptions(n),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}getSelected(){return this.store.getSelected()}setSelected(e){const t=this.store.getSelected();this.store.setSelectedBy("value",Array.isArray(e)?e:[e]);const i=this.store.getData();this.select.updateOptions(i),this.render.renderValues(),this.render.renderOptions(i),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}addOption(e){const t=this.store.getSelected();this.store.addOption(e);const i=this.store.getData();this.select.updateOptions(i),this.render.renderValues(),this.render.renderOptions(i),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}open(){this.settings.isEnabled&&!this.settings.isOpen&&(this.events.beforeOpen&&this.events.beforeOpen(),this.render.open(),this.settings.showSearch&&this.render.searchFocus(!1),setTimeout((()=>{this.events.afterOpen&&this.events.afterOpen(),this.settings.isOpen=!0}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove),this.settings.intervalMove=setInterval(this.render.moveContent.bind(this.render),500))}close(){this.settings.isOpen&&!this.settings.alwaysOpen&&(this.events.beforeClose&&this.events.beforeClose(),this.render.close(),this.search(""),this.render.mainFocus(!1),setTimeout((()=>{this.events.afterClose&&this.events.afterClose(),this.settings.isOpen=!1}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove))}search(e){if(this.render.content.search.input.value!==e&&(this.render.content.search.input.value=e),!this.events.search)return void this.render.renderOptions(""===e?this.store.getData():this.store.search(e,this.events.searchFilter));this.render.renderSearching();const t=this.events.search(e,this.store.getSelectedOptions());t instanceof Promise?t.then((e=>{this.render.renderOptions(this.store.partialToFullData(e))})).catch((e=>{this.render.renderError("string"==typeof e?e:e.message)})):Array.isArray(t)?this.render.renderOptions(this.store.partialToFullData(t)):this.render.renderError("Search event must return a promise or an array of data")}destroy(){document.removeEventListener("click",this.documentClick),window.removeEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.removeEventListener("scroll",this.windowScroll,!1),this.store.setData([]),this.render.destroy(),this.select.destroy()}}}));
|
package/package.json
CHANGED
|
@@ -50,6 +50,10 @@ export function debounce(func: (...params: any[]) => void, wait = 50, immediate
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export function isEqual(a: any, b: any) {
|
|
54
|
+
return JSON.stringify(a) === JSON.stringify(b)
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
export function kebabCase(str: string) {
|
|
54
58
|
const result = str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => '-' + match.toLowerCase())
|
|
55
59
|
return str[0] === str[0].toUpperCase() ? result.substring(1) : result
|
package/src/slim-select/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import Settings, { SettingsPartial } from './settings'
|
|
2
2
|
import Render from './render'
|
|
3
3
|
import Select from './select'
|
|
4
|
-
import Settings, { SettingsPartial } from './settings'
|
|
5
4
|
import Store, { DataArray, DataArrayPartial, Option, OptionOptional } from './store'
|
|
5
|
+
import { debounce, hasClassInTree, isEqual } from './helpers'
|
|
6
6
|
|
|
7
7
|
export interface Config {
|
|
8
8
|
select: string | Element
|
|
@@ -181,6 +181,9 @@ export default class SlimSelect {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
public setData(data: DataArrayPartial): void {
|
|
184
|
+
// Get original selected values
|
|
185
|
+
const selected = this.store.getSelected()
|
|
186
|
+
|
|
184
187
|
// Validate data
|
|
185
188
|
const err = this.store.validateDataArray(data)
|
|
186
189
|
if (err) {
|
|
@@ -200,6 +203,11 @@ export default class SlimSelect {
|
|
|
200
203
|
// Update the render
|
|
201
204
|
this.render.renderValues()
|
|
202
205
|
this.render.renderOptions(dataClean)
|
|
206
|
+
|
|
207
|
+
// Trigger afterChange event, if it doesnt equal the original selected values
|
|
208
|
+
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
209
|
+
this.events.afterChange(this.store.getSelectedOptions())
|
|
210
|
+
}
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
public getSelected(): string[] {
|
|
@@ -207,6 +215,9 @@ export default class SlimSelect {
|
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
public setSelected(value: string | string[]): void {
|
|
218
|
+
// Get original selected values
|
|
219
|
+
const selected = this.store.getSelected()
|
|
220
|
+
|
|
210
221
|
// Update the store
|
|
211
222
|
this.store.setSelectedBy('value', Array.isArray(value) ? value : [value])
|
|
212
223
|
const data = this.store.getData()
|
|
@@ -217,9 +228,17 @@ export default class SlimSelect {
|
|
|
217
228
|
// Update the render
|
|
218
229
|
this.render.renderValues()
|
|
219
230
|
this.render.renderOptions(data)
|
|
231
|
+
|
|
232
|
+
// Trigger afterChange event, if it doesnt equal the original selected values
|
|
233
|
+
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
234
|
+
this.events.afterChange(this.store.getSelectedOptions())
|
|
235
|
+
}
|
|
220
236
|
}
|
|
221
237
|
|
|
222
238
|
public addOption(option: OptionOptional): void {
|
|
239
|
+
// Get original selected values
|
|
240
|
+
const selected = this.store.getSelected()
|
|
241
|
+
|
|
223
242
|
// Add option to store
|
|
224
243
|
this.store.addOption(option)
|
|
225
244
|
const data = this.store.getData()
|
|
@@ -230,6 +249,11 @@ export default class SlimSelect {
|
|
|
230
249
|
// Update the render
|
|
231
250
|
this.render.renderValues()
|
|
232
251
|
this.render.renderOptions(data)
|
|
252
|
+
|
|
253
|
+
// Trigger afterChange event, if it doesnt equal the original selected values
|
|
254
|
+
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
255
|
+
this.events.afterChange(this.store.getSelectedOptions())
|
|
256
|
+
}
|
|
233
257
|
}
|
|
234
258
|
|
|
235
259
|
public open(): void {
|
|
@@ -1029,7 +1029,6 @@ export default class Render {
|
|
|
1029
1029
|
|
|
1030
1030
|
// Create new path for arrow
|
|
1031
1031
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
|
1032
|
-
optgroupClosableArrow.setAttribute('d', this.classes.arrow)
|
|
1033
1032
|
optgroupClosableSvg.appendChild(optgroupClosableArrow)
|
|
1034
1033
|
|
|
1035
1034
|
// If any options are selected, set optgroup to open
|
|
@@ -70,7 +70,10 @@ export default class Select {
|
|
|
70
70
|
|
|
71
71
|
public addValueChangeListener(func: (value: string[]) => void): void {
|
|
72
72
|
this.onValueChange = func
|
|
73
|
-
this.select.addEventListener('change', this.valueChange.bind(this)
|
|
73
|
+
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
74
|
+
// allow bubbling of event
|
|
75
|
+
passive: true,
|
|
76
|
+
})
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
public removeValueChangeListener(): void {
|
|
@@ -78,10 +81,13 @@ export default class Select {
|
|
|
78
81
|
this.select.removeEventListener('change', this.valueChange.bind(this))
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
public valueChange(ev: Event):
|
|
82
|
-
if (this.onValueChange) {
|
|
84
|
+
public valueChange(ev: Event): boolean {
|
|
85
|
+
if (this.listen && this.onValueChange) {
|
|
83
86
|
this.onValueChange(this.getSelectedValues())
|
|
84
87
|
}
|
|
88
|
+
|
|
89
|
+
// Allow bubbling back to other change event listeners
|
|
90
|
+
return true
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
private observeWrapper(mutations: MutationRecord[]): void {
|
|
@@ -282,6 +288,9 @@ export default class Select {
|
|
|
282
288
|
}
|
|
283
289
|
}
|
|
284
290
|
|
|
291
|
+
// Trigger change event on original select
|
|
292
|
+
this.select.dispatchEvent(new Event('change'))
|
|
293
|
+
|
|
285
294
|
// Start listening to changes
|
|
286
295
|
this.changeListen(true)
|
|
287
296
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function generateID(): string;
|
|
2
2
|
export declare function hasClassInTree(element: HTMLElement, className: string): any;
|
|
3
3
|
export declare function debounce(func: (...params: any[]) => void, wait?: number, immediate?: boolean): () => void;
|
|
4
|
+
export declare function isEqual(a: any, b: any): boolean;
|
|
4
5
|
export declare function kebabCase(str: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import Settings, { SettingsPartial } from './settings';
|
|
1
2
|
import Render from './render';
|
|
2
3
|
import Select from './select';
|
|
3
|
-
import Settings, { SettingsPartial } from './settings';
|
|
4
4
|
import Store, { DataArray, DataArrayPartial, Option, OptionOptional } from './store';
|
|
5
5
|
export interface Config {
|
|
6
6
|
select: string | Element;
|
|
@@ -15,7 +15,7 @@ export default class Select {
|
|
|
15
15
|
removeSelectChangeListener(): void;
|
|
16
16
|
addValueChangeListener(func: (value: string[]) => void): void;
|
|
17
17
|
removeValueChangeListener(): void;
|
|
18
|
-
valueChange(ev: Event):
|
|
18
|
+
valueChange(ev: Event): boolean;
|
|
19
19
|
private observeWrapper;
|
|
20
20
|
private addObserver;
|
|
21
21
|
private connectObserver;
|
|
@@ -44,11 +44,50 @@ function debounce(func, wait = 50, immediate = false) {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
function isEqual(a, b) {
|
|
48
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
49
|
+
}
|
|
47
50
|
function kebabCase(str) {
|
|
48
51
|
const result = str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => '-' + match.toLowerCase());
|
|
49
52
|
return str[0] === str[0].toUpperCase() ? result.substring(1) : result;
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
class Settings {
|
|
56
|
+
constructor(settings) {
|
|
57
|
+
this.id = '';
|
|
58
|
+
this.style = '';
|
|
59
|
+
this.class = [];
|
|
60
|
+
this.isMultiple = false;
|
|
61
|
+
this.isOpen = false;
|
|
62
|
+
this.triggerFocus = true;
|
|
63
|
+
this.intervalMove = null;
|
|
64
|
+
if (!settings) {
|
|
65
|
+
settings = {};
|
|
66
|
+
}
|
|
67
|
+
this.id = 'ss-' + generateID();
|
|
68
|
+
this.style = settings.style || '';
|
|
69
|
+
this.class = settings.class || [];
|
|
70
|
+
this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
|
|
71
|
+
this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
|
|
72
|
+
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
|
|
73
|
+
this.searchPlaceholder = settings.searchPlaceholder || 'Search';
|
|
74
|
+
this.searchText = settings.searchText || 'No Results';
|
|
75
|
+
this.searchingText = settings.searchingText || 'Searching...';
|
|
76
|
+
this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
|
|
77
|
+
this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
|
|
78
|
+
this.contentLocation = settings.contentLocation || document.body;
|
|
79
|
+
this.contentPosition = settings.contentPosition || 'absolute';
|
|
80
|
+
this.openPosition = settings.openPosition || 'auto';
|
|
81
|
+
this.placeholderText = settings.placeholderText || 'Select Value';
|
|
82
|
+
this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
|
|
83
|
+
this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
|
|
84
|
+
this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
|
|
85
|
+
this.minSelected = settings.minSelected || 0;
|
|
86
|
+
this.maxSelected = settings.maxSelected || 1000;
|
|
87
|
+
this.timeoutDelay = settings.timeoutDelay || 200;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
52
91
|
class Optgroup {
|
|
53
92
|
constructor(optgroup) {
|
|
54
93
|
this.id = !optgroup.id || optgroup.id === '' ? generateID() : optgroup.id;
|
|
@@ -942,7 +981,6 @@ class Render {
|
|
|
942
981
|
optgroupClosableSvg.classList.add(this.classes.arrow);
|
|
943
982
|
optgroupClosable.appendChild(optgroupClosableSvg);
|
|
944
983
|
const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
945
|
-
optgroupClosableArrow.setAttribute('d', this.classes.arrow);
|
|
946
984
|
optgroupClosableSvg.appendChild(optgroupClosableArrow);
|
|
947
985
|
if (d.options.some((o) => o.selected)) {
|
|
948
986
|
optgroupClosable.classList.add(this.classes.open);
|
|
@@ -1195,16 +1233,19 @@ class Select {
|
|
|
1195
1233
|
}
|
|
1196
1234
|
addValueChangeListener(func) {
|
|
1197
1235
|
this.onValueChange = func;
|
|
1198
|
-
this.select.addEventListener('change', this.valueChange.bind(this)
|
|
1236
|
+
this.select.addEventListener('change', this.valueChange.bind(this), {
|
|
1237
|
+
passive: true,
|
|
1238
|
+
});
|
|
1199
1239
|
}
|
|
1200
1240
|
removeValueChangeListener() {
|
|
1201
1241
|
this.onValueChange = undefined;
|
|
1202
1242
|
this.select.removeEventListener('change', this.valueChange.bind(this));
|
|
1203
1243
|
}
|
|
1204
1244
|
valueChange(ev) {
|
|
1205
|
-
if (this.onValueChange) {
|
|
1245
|
+
if (this.listen && this.onValueChange) {
|
|
1206
1246
|
this.onValueChange(this.getSelectedValues());
|
|
1207
1247
|
}
|
|
1248
|
+
return true;
|
|
1208
1249
|
}
|
|
1209
1250
|
observeWrapper(mutations) {
|
|
1210
1251
|
if (this.onSelectChange) {
|
|
@@ -1349,6 +1390,7 @@ class Select {
|
|
|
1349
1390
|
this.select.appendChild(this.createOption(d));
|
|
1350
1391
|
}
|
|
1351
1392
|
}
|
|
1393
|
+
this.select.dispatchEvent(new Event('change'));
|
|
1352
1394
|
this.changeListen(true);
|
|
1353
1395
|
}
|
|
1354
1396
|
createOptgroup(optgroup) {
|
|
@@ -1408,42 +1450,6 @@ class Select {
|
|
|
1408
1450
|
}
|
|
1409
1451
|
}
|
|
1410
1452
|
|
|
1411
|
-
class Settings {
|
|
1412
|
-
constructor(settings) {
|
|
1413
|
-
this.id = '';
|
|
1414
|
-
this.style = '';
|
|
1415
|
-
this.class = [];
|
|
1416
|
-
this.isMultiple = false;
|
|
1417
|
-
this.isOpen = false;
|
|
1418
|
-
this.triggerFocus = true;
|
|
1419
|
-
this.intervalMove = null;
|
|
1420
|
-
if (!settings) {
|
|
1421
|
-
settings = {};
|
|
1422
|
-
}
|
|
1423
|
-
this.id = 'ss-' + generateID();
|
|
1424
|
-
this.style = settings.style || '';
|
|
1425
|
-
this.class = settings.class || [];
|
|
1426
|
-
this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
|
|
1427
|
-
this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
|
|
1428
|
-
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
|
|
1429
|
-
this.searchPlaceholder = settings.searchPlaceholder || 'Search';
|
|
1430
|
-
this.searchText = settings.searchText || 'No Results';
|
|
1431
|
-
this.searchingText = settings.searchingText || 'Searching...';
|
|
1432
|
-
this.searchHighlight = settings.searchHighlight !== undefined ? settings.searchHighlight : false;
|
|
1433
|
-
this.closeOnSelect = settings.closeOnSelect !== undefined ? settings.closeOnSelect : true;
|
|
1434
|
-
this.contentLocation = settings.contentLocation || document.body;
|
|
1435
|
-
this.contentPosition = settings.contentPosition || 'absolute';
|
|
1436
|
-
this.openPosition = settings.openPosition || 'auto';
|
|
1437
|
-
this.placeholderText = settings.placeholderText || 'Select Value';
|
|
1438
|
-
this.allowDeselect = settings.allowDeselect !== undefined ? settings.allowDeselect : false;
|
|
1439
|
-
this.hideSelected = settings.hideSelected !== undefined ? settings.hideSelected : false;
|
|
1440
|
-
this.showOptionTooltips = settings.showOptionTooltips !== undefined ? settings.showOptionTooltips : false;
|
|
1441
|
-
this.minSelected = settings.minSelected || 0;
|
|
1442
|
-
this.maxSelected = settings.maxSelected || 1000;
|
|
1443
|
-
this.timeoutDelay = settings.timeoutDelay || 200;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
1453
|
class SlimSelect {
|
|
1448
1454
|
constructor(config) {
|
|
1449
1455
|
this.events = {
|
|
@@ -1576,6 +1582,7 @@ class SlimSelect {
|
|
|
1576
1582
|
return this.store.getData();
|
|
1577
1583
|
}
|
|
1578
1584
|
setData(data) {
|
|
1585
|
+
const selected = this.store.getSelected();
|
|
1579
1586
|
const err = this.store.validateDataArray(data);
|
|
1580
1587
|
if (err) {
|
|
1581
1588
|
if (this.events.error) {
|
|
@@ -1588,23 +1595,34 @@ class SlimSelect {
|
|
|
1588
1595
|
this.select.updateOptions(dataClean);
|
|
1589
1596
|
this.render.renderValues();
|
|
1590
1597
|
this.render.renderOptions(dataClean);
|
|
1598
|
+
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1599
|
+
this.events.afterChange(this.store.getSelectedOptions());
|
|
1600
|
+
}
|
|
1591
1601
|
}
|
|
1592
1602
|
getSelected() {
|
|
1593
1603
|
return this.store.getSelected();
|
|
1594
1604
|
}
|
|
1595
1605
|
setSelected(value) {
|
|
1606
|
+
const selected = this.store.getSelected();
|
|
1596
1607
|
this.store.setSelectedBy('value', Array.isArray(value) ? value : [value]);
|
|
1597
1608
|
const data = this.store.getData();
|
|
1598
1609
|
this.select.updateOptions(data);
|
|
1599
1610
|
this.render.renderValues();
|
|
1600
1611
|
this.render.renderOptions(data);
|
|
1612
|
+
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1613
|
+
this.events.afterChange(this.store.getSelectedOptions());
|
|
1614
|
+
}
|
|
1601
1615
|
}
|
|
1602
1616
|
addOption(option) {
|
|
1617
|
+
const selected = this.store.getSelected();
|
|
1603
1618
|
this.store.addOption(option);
|
|
1604
1619
|
const data = this.store.getData();
|
|
1605
1620
|
this.select.updateOptions(data);
|
|
1606
1621
|
this.render.renderValues();
|
|
1607
1622
|
this.render.renderOptions(data);
|
|
1623
|
+
if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
|
|
1624
|
+
this.events.afterChange(this.store.getSelectedOptions());
|
|
1625
|
+
}
|
|
1608
1626
|
}
|
|
1609
1627
|
open() {
|
|
1610
1628
|
if (!this.settings.isEnabled || this.settings.isOpen) {
|
|
@@ -1690,6 +1708,13 @@ class SlimSelect {
|
|
|
1690
1708
|
var script = defineComponent({
|
|
1691
1709
|
name: 'SlimSelect',
|
|
1692
1710
|
props: {
|
|
1711
|
+
modelValue: {
|
|
1712
|
+
type: [String, Array, undefined],
|
|
1713
|
+
},
|
|
1714
|
+
multiple: {
|
|
1715
|
+
type: Boolean,
|
|
1716
|
+
default: false,
|
|
1717
|
+
},
|
|
1693
1718
|
data: {
|
|
1694
1719
|
type: Array,
|
|
1695
1720
|
},
|
|
@@ -1700,6 +1725,7 @@ var script = defineComponent({
|
|
|
1700
1725
|
type: Object,
|
|
1701
1726
|
},
|
|
1702
1727
|
},
|
|
1728
|
+
emits: ['update:modelValue'],
|
|
1703
1729
|
data() {
|
|
1704
1730
|
return {
|
|
1705
1731
|
slim: null,
|
|
@@ -1718,7 +1744,24 @@ var script = defineComponent({
|
|
|
1718
1744
|
if (this.events) {
|
|
1719
1745
|
config.events = this.events;
|
|
1720
1746
|
}
|
|
1747
|
+
if (!config.events) {
|
|
1748
|
+
config.events = {};
|
|
1749
|
+
}
|
|
1750
|
+
const ogAfterChange = config.events.afterChange;
|
|
1751
|
+
config.events.afterChange = (newVal) => {
|
|
1752
|
+
const value = this.multiple ? newVal.map((option) => option.value) : newVal[0].value;
|
|
1753
|
+
if (this.value !== value) {
|
|
1754
|
+
this.value = value;
|
|
1755
|
+
}
|
|
1756
|
+
if (config.events && ogAfterChange) {
|
|
1757
|
+
ogAfterChange(newVal);
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1721
1760
|
this.slim = new SlimSelect(config);
|
|
1761
|
+
let selected = this.$props.multiple ? this.slim.getSelected() : this.slim.getSelected()[0];
|
|
1762
|
+
if (this.value !== selected) {
|
|
1763
|
+
this.value = selected;
|
|
1764
|
+
}
|
|
1722
1765
|
},
|
|
1723
1766
|
beforeUnmount() {
|
|
1724
1767
|
if (this.slim) {
|
|
@@ -1735,6 +1778,27 @@ var script = defineComponent({
|
|
|
1735
1778
|
deep: true,
|
|
1736
1779
|
},
|
|
1737
1780
|
},
|
|
1781
|
+
computed: {
|
|
1782
|
+
value: {
|
|
1783
|
+
get() {
|
|
1784
|
+
const multi = this.$props.multiple;
|
|
1785
|
+
const val = this.$props.modelValue;
|
|
1786
|
+
if (val === undefined) {
|
|
1787
|
+
return multi ? [] : '';
|
|
1788
|
+
}
|
|
1789
|
+
if (multi && typeof val === 'string') {
|
|
1790
|
+
return [val];
|
|
1791
|
+
}
|
|
1792
|
+
if (!multi && Array.isArray(val)) {
|
|
1793
|
+
return val[0];
|
|
1794
|
+
}
|
|
1795
|
+
return multi ? [] : '';
|
|
1796
|
+
},
|
|
1797
|
+
set(value) {
|
|
1798
|
+
this.$emit('update:modelValue', value);
|
|
1799
|
+
},
|
|
1800
|
+
},
|
|
1801
|
+
},
|
|
1738
1802
|
methods: {
|
|
1739
1803
|
getSlimSelect() {
|
|
1740
1804
|
return this.slim;
|
|
@@ -1742,12 +1806,15 @@ var script = defineComponent({
|
|
|
1742
1806
|
},
|
|
1743
1807
|
});
|
|
1744
1808
|
|
|
1745
|
-
const _hoisted_1 =
|
|
1809
|
+
const _hoisted_1 = ["multiple"];
|
|
1746
1810
|
|
|
1747
1811
|
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
1748
|
-
return (openBlock(), createElementBlock("select",
|
|
1812
|
+
return (openBlock(), createElementBlock("select", {
|
|
1813
|
+
multiple: _ctx.multiple,
|
|
1814
|
+
ref: "slim"
|
|
1815
|
+
}, [
|
|
1749
1816
|
renderSlot(_ctx.$slots, "default")
|
|
1750
|
-
],
|
|
1817
|
+
], 8 /* PROPS */, _hoisted_1))
|
|
1751
1818
|
}
|
|
1752
1819
|
|
|
1753
1820
|
script.render = render;
|