slim-select 1.27.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/.prettierrc +6 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +15 -5
- package/README.md +2 -1
- package/dist/helper.d.ts +1 -4
- package/dist/index.d.ts +38 -58
- package/dist/render.d.ts +109 -0
- package/dist/select.d.ts +31 -20
- package/dist/settings.d.ts +33 -0
- package/dist/slimselect.cjs.js +2 -0
- package/dist/slimselect.cjs.js.map +1 -0
- package/dist/slimselect.css +1 -2
- package/dist/slimselect.css.map +1 -0
- package/dist/slimselect.es.js +2 -0
- package/dist/slimselect.es.js.map +1 -0
- package/dist/slimselect.global.js +2 -0
- package/dist/slimselect.global.js.map +1 -0
- package/dist/slimselect.js +2 -1970
- package/dist/slimselect.js.map +1 -0
- package/dist/slimselect.umd.js +2 -0
- package/dist/slimselect.umd.js.map +1 -0
- package/dist/store.d.ts +71 -0
- package/docs/assets/check-mark.svg +6 -0
- package/docs/assets/data.js +59 -0
- package/docs/assets/home.css +1 -0
- package/docs/assets/home.js +1 -0
- package/docs/assets/index.css +1 -0
- package/docs/assets/index.js +16 -0
- package/docs/assets/index2.js +274 -0
- package/docs/assets/index3.js +126 -0
- package/docs/assets/index4.js +60 -0
- package/docs/assets/install.js +34 -0
- package/docs/assets/selects.js +55 -0
- package/docs/index.html +18 -5
- package/docs.go +3 -1
- package/index.html +16 -0
- package/jest.config.js +7 -0
- package/package.json +39 -35
- package/src/docs/app.vue +185 -76
- package/src/docs/assets/scss/_variables.scss +26 -10
- package/src/docs/assets/scss/alert.scss +12 -0
- package/src/docs/assets/scss/animations.scss +5 -3
- package/src/docs/assets/scss/button.scss +21 -0
- package/src/docs/assets/scss/index.scss +8 -6
- package/src/docs/assets/scss/input.scss +2 -2
- package/src/docs/assets/scss/layout.scss +195 -65
- package/src/docs/assets/scss/misc.scss +144 -34
- package/src/docs/assets/scss/prism.scss +155 -153
- package/src/docs/env.d.ts +12 -0
- package/src/docs/images/check-mark.svg +6 -0
- package/src/docs/images/chrome.svg +22 -0
- package/src/docs/images/firefox.svg +58 -0
- package/src/docs/images/github.png +0 -0
- package/src/docs/images/ie.svg +11 -0
- package/src/docs/images/npm.png +0 -0
- package/src/docs/images/opera.svg +15 -0
- package/src/docs/images/safari.svg +22 -0
- package/src/docs/main.ts +27 -0
- package/src/docs/pages/data.vue +130 -0
- package/src/docs/pages/events/addable.vue +79 -0
- package/src/docs/pages/events/before_after_change.vue +140 -0
- package/src/docs/pages/events/before_after_open_close.vue +122 -0
- package/src/docs/pages/events/error.vue +59 -0
- package/src/docs/pages/events/index.vue +33 -0
- package/src/docs/pages/events/search.vue +154 -0
- package/src/docs/pages/events/search_filter.vue +45 -0
- package/src/docs/pages/home.vue +96 -116
- package/src/docs/pages/install.vue +47 -74
- package/src/docs/pages/methods/destroy.vue +66 -0
- package/src/docs/pages/methods/enable_disable.vue +70 -0
- package/src/docs/pages/methods/get_data.vue +81 -0
- package/src/docs/pages/methods/get_selected.vue +78 -0
- package/src/docs/pages/methods/index.vue +36 -0
- package/src/docs/pages/methods/open_close.vue +63 -0
- package/src/docs/pages/methods/search.vue +62 -0
- package/src/docs/pages/methods/set_data.vue +106 -0
- package/src/docs/pages/methods/set_selected.vue +70 -0
- package/src/docs/pages/selects.vue +108 -114
- package/src/docs/pages/settings/always_open.vue +88 -0
- package/src/docs/pages/settings/close_on_select.vue +69 -0
- package/src/docs/pages/settings/content_location.vue +64 -0
- package/src/docs/pages/settings/content_position.vue +86 -0
- package/src/docs/pages/settings/css.vue +73 -0
- package/src/docs/pages/settings/data_attributes.vue +39 -0
- package/src/docs/pages/settings/deselect.vue +69 -0
- package/src/docs/pages/settings/display.vue +88 -0
- package/src/docs/pages/settings/hide_selected.vue +73 -0
- package/src/docs/pages/settings/html.vue +86 -0
- package/src/docs/pages/settings/index.vue +73 -0
- package/src/docs/pages/settings/mandatory.vue +91 -0
- package/src/docs/pages/settings/min_max.vue +61 -0
- package/src/docs/pages/settings/open_position.vue +60 -0
- package/src/docs/pages/settings/placeholder.vue +72 -0
- package/src/docs/pages/settings/search.vue +140 -0
- package/src/docs/pages/settings/select.vue +32 -0
- package/src/docs/pages/settings/select_by_group.vue +46 -0
- package/src/docs/pages/settings/show_tooltip.vue +44 -0
- package/src/docs/pages/settings/styles.vue +51 -0
- package/src/docs/router.ts +41 -13
- package/src/slim-select/helper.ts +25 -86
- package/src/slim-select/index.ts +317 -420
- package/src/slim-select/render.test.ts +39 -0
- package/src/slim-select/render.ts +1129 -0
- package/src/slim-select/rollup.config.mjs +39 -0
- package/src/slim-select/select.test.ts +155 -0
- package/src/slim-select/select.ts +280 -108
- package/src/slim-select/settings.ts +68 -0
- package/src/slim-select/slimselect.scss +263 -278
- package/src/slim-select/store.test.ts +220 -0
- package/src/slim-select/store.ts +320 -0
- package/src/slim-select/tsconfig.json +11 -5
- package/src/vue/slimselect.vue +61 -0
- package/tsconfig.json +10 -29
- package/vite.config.ts +18 -0
- package/.browserslistrc +0 -4
- package/.postcssrc.js +0 -5
- package/.travis.yml +0 -22
- package/babel.config.js +0 -5
- package/dist/config.d.ts +0 -83
- package/dist/data.d.ts +0 -50
- package/dist/slim.d.ts +0 -50
- package/dist/slimselect.min.css +0 -1
- package/dist/slimselect.min.js +0 -1
- package/dist/slimselect.min.mjs +0 -1
- package/docs/css/app.d5840d21.css +0 -1
- package/docs/css/chunk-vendors.fa8199af.css +0 -1
- package/docs/css/home.57020178.css +0 -1
- package/docs/css/install.baa5d3fb.css +0 -1
- package/docs/css/methods.728c742a.css +0 -1
- package/docs/css/options.b28a32ef.css +0 -1
- package/docs/css/selects.1a7e1e6a.css +0 -1
- package/docs/js/app.238ee382.js +0 -2
- package/docs/js/app.238ee382.js.map +0 -1
- package/docs/js/chunk-vendors.5125e3d8.js +0 -21
- package/docs/js/chunk-vendors.5125e3d8.js.map +0 -1
- package/docs/js/home.e7b28581.js +0 -2
- package/docs/js/home.e7b28581.js.map +0 -1
- package/docs/js/install.d4300783.js +0 -2
- package/docs/js/install.d4300783.js.map +0 -1
- package/docs/js/methods.fa1608f1.js +0 -11
- package/docs/js/methods.fa1608f1.js.map +0 -1
- package/docs/js/options.2c4ceb87.js +0 -2
- package/docs/js/options.2c4ceb87.js.map +0 -1
- package/docs/js/selects.1eeba693.js +0 -2
- package/docs/js/selects.1eeba693.js.map +0 -1
- package/src/docs/pages/methods.vue +0 -427
- package/src/docs/pages/options.vue +0 -1480
- package/src/main.ts +0 -29
- package/src/shims-vue.d.ts +0 -8
- package/src/slim-select/config.ts +0 -118
- package/src/slim-select/data.ts +0 -377
- package/src/slim-select/slim.ts +0 -775
- package/tslint.json +0 -26
- package/vue.config.js +0 -23
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
import SlimSelect from '../../../slim-select'
|
|
5
|
+
|
|
6
|
+
export default defineComponent({
|
|
7
|
+
name: 'ShowTooltip',
|
|
8
|
+
mounted() {
|
|
9
|
+
new SlimSelect({
|
|
10
|
+
select: this.$refs.showOptionTooltips as HTMLSelectElement,
|
|
11
|
+
settings: {
|
|
12
|
+
showOptionTooltips: true,
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<div id="showOptionTooltips" class="content">
|
|
21
|
+
<h2 class="header">showOptionTooltips</h2>
|
|
22
|
+
<p>
|
|
23
|
+
showOptionTooltips option is used to active displaying the on-hover tooltips for select options. The tooltip text
|
|
24
|
+
is equal to the option text content.
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
<select ref="showOptionTooltips">
|
|
28
|
+
<option value="value1">Value 1</option>
|
|
29
|
+
<option value="value2">Value 2</option>
|
|
30
|
+
<option value="value3">Value 3</option>
|
|
31
|
+
</select>
|
|
32
|
+
|
|
33
|
+
<pre>
|
|
34
|
+
<code class="language-javascript">
|
|
35
|
+
new SlimSelect({
|
|
36
|
+
select: '#selectElement',
|
|
37
|
+
settings: {
|
|
38
|
+
showOptionTooltips: true,
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
</code>
|
|
42
|
+
</pre>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
import SlimSelect from '../../../slim-select'
|
|
5
|
+
|
|
6
|
+
export default defineComponent({
|
|
7
|
+
name: 'Styles',
|
|
8
|
+
mounted() {
|
|
9
|
+
new SlimSelect({ select: this.$refs.selectStyle as HTMLSelectElement })
|
|
10
|
+
new SlimSelect({ select: this.$refs.optionStyle as HTMLSelectElement })
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<div id="inlineStyles" class="content">
|
|
17
|
+
<h2 class="header">inline styles</h2>
|
|
18
|
+
<p>
|
|
19
|
+
Slim select will inherit any styles that were added to the original select element. This includes options as well.
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<div class="row">
|
|
23
|
+
<select ref="selectStyle" style="color: red">
|
|
24
|
+
<option value="value1">Value 1</option>
|
|
25
|
+
<option value="value2">Value 2</option>
|
|
26
|
+
<option value="value3">Value 3</option>
|
|
27
|
+
</select>
|
|
28
|
+
<select ref="optionStyle">
|
|
29
|
+
<option style="color: red" value="value1">Red</option>
|
|
30
|
+
<option style="color: green">Green</option>
|
|
31
|
+
<option style="color: blue">Blue</option>
|
|
32
|
+
</select>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<pre>
|
|
36
|
+
<code class="language-html">
|
|
37
|
+
<select id="select-style" style="color: red;">
|
|
38
|
+
<option value="value1">Value 1</option>
|
|
39
|
+
<option value="value2">Value 2</option>
|
|
40
|
+
<option value="value3">Value 3</option>
|
|
41
|
+
</select>
|
|
42
|
+
|
|
43
|
+
<select id="option-style">
|
|
44
|
+
<option style="color: red;" value="value1">Red</option>
|
|
45
|
+
<option style="color: green;">Green</option>
|
|
46
|
+
<option style="color: blue;">Blue</option>
|
|
47
|
+
</select>
|
|
48
|
+
</code>
|
|
49
|
+
</pre>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
package/src/docs/router.ts
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Router from 'vue-router'
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default new Router({
|
|
7
|
-
mode: 'history',
|
|
8
|
-
base: '/',
|
|
3
|
+
const router = createRouter({
|
|
4
|
+
history: createWebHistory(),
|
|
9
5
|
linkActiveClass: 'active',
|
|
10
6
|
routes: [
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
{
|
|
8
|
+
path: '/',
|
|
9
|
+
name: 'Home',
|
|
10
|
+
component: () => import('./pages/home.vue'),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
path: '/install',
|
|
14
|
+
name: 'Install',
|
|
15
|
+
component: () => import('./pages/install.vue'),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
path: '/selects',
|
|
19
|
+
name: 'Selects',
|
|
20
|
+
component: () => import('./pages/selects.vue'),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
path: '/data',
|
|
24
|
+
name: 'Data',
|
|
25
|
+
component: () => import('./pages/data.vue'),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
path: '/settings',
|
|
29
|
+
name: 'Settings',
|
|
30
|
+
component: () => import('./pages/settings/index.vue'),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
path: '/events',
|
|
34
|
+
name: 'Events',
|
|
35
|
+
component: () => import('./pages/events/index.vue'),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
path: '/methods',
|
|
39
|
+
name: 'Methods',
|
|
40
|
+
component: () => import('./pages/methods/index.vue'),
|
|
41
|
+
},
|
|
42
|
+
],
|
|
17
43
|
})
|
|
44
|
+
|
|
45
|
+
export default router
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
+
// Generate an 8 character random string
|
|
2
|
+
export function generateID(): string {
|
|
3
|
+
return Math.random().toString(36).substring(2, 10)
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
export function hasClassInTree(element: HTMLElement, className: string) {
|
|
2
7
|
function hasClass(e: HTMLElement, c: string) {
|
|
3
|
-
|
|
8
|
+
// If the element has the class return element
|
|
9
|
+
if (c && e && e.classList && e.classList.contains(c)) {
|
|
10
|
+
return e
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// If the element has a dataset id of the class return element
|
|
14
|
+
if (c && e && e.dataset && e.dataset.id && e.dataset.id === className) {
|
|
15
|
+
return e
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
return null
|
|
5
19
|
}
|
|
6
20
|
|
|
7
21
|
function parentByClass(e: any, c: string): any {
|
|
8
|
-
if (!e || e === document as any) {
|
|
22
|
+
if (!e || e === (document as any)) {
|
|
9
23
|
return null
|
|
10
24
|
} else if (hasClass(e, c)) {
|
|
11
25
|
return e
|
|
@@ -17,101 +31,26 @@ export function hasClassInTree(element: HTMLElement, className: string) {
|
|
|
17
31
|
return hasClass(element, className) || parentByClass(element, className)
|
|
18
32
|
}
|
|
19
33
|
|
|
20
|
-
export function
|
|
21
|
-
// Determine container top and bottom
|
|
22
|
-
const cTop = container.scrollTop + container.offsetTop // Make sure to have offsetTop
|
|
23
|
-
const cBottom = cTop + container.clientHeight
|
|
24
|
-
|
|
25
|
-
// Determine element top and bottom
|
|
26
|
-
const eTop = element.offsetTop
|
|
27
|
-
const eBottom = eTop + element.clientHeight
|
|
28
|
-
|
|
29
|
-
// Check if out of view
|
|
30
|
-
if (eTop < cTop) {
|
|
31
|
-
container.scrollTop -= (cTop - eTop)
|
|
32
|
-
} else if (eBottom > cBottom) {
|
|
33
|
-
container.scrollTop += (eBottom - cBottom)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function putContent(el: HTMLElement, currentPosition: string, isOpen: boolean): string {
|
|
38
|
-
const height = el.offsetHeight
|
|
39
|
-
const rect = el.getBoundingClientRect()
|
|
40
|
-
const elemTop = (isOpen ? rect.top : rect.top - height)
|
|
41
|
-
const elemBottom = (isOpen ? rect.bottom : rect.bottom + height)
|
|
42
|
-
|
|
43
|
-
if (elemTop <= 0) { return 'below' }
|
|
44
|
-
if (elemBottom >= window.innerHeight) { return 'above' }
|
|
45
|
-
return (isOpen ? currentPosition : 'below')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function debounce(func: (...params: any[]) => void, wait = 100, immediate = false): () => void {
|
|
34
|
+
export function debounce(func: (...params: any[]) => void, wait = 50, immediate = false): () => void {
|
|
49
35
|
let timeout: any
|
|
50
|
-
return function(this: any, ...args: any[]) {
|
|
36
|
+
return function (this: any, ...args: any[]) {
|
|
51
37
|
const context = self
|
|
52
38
|
const later = () => {
|
|
53
39
|
timeout = null
|
|
54
|
-
if (!immediate) {
|
|
40
|
+
if (!immediate) {
|
|
41
|
+
func.apply(context, args)
|
|
42
|
+
}
|
|
55
43
|
}
|
|
56
44
|
const callNow = immediate && !timeout
|
|
57
45
|
clearTimeout(timeout)
|
|
58
46
|
timeout = setTimeout(later, wait)
|
|
59
|
-
if (callNow) {
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function isValueInArrayOfObjects(selected: any, key: string, value: string): boolean {
|
|
64
|
-
if (!Array.isArray(selected)) {
|
|
65
|
-
return selected[key] === value
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (const s of selected) {
|
|
69
|
-
if (s && s[key] && s[key] === value) {
|
|
70
|
-
return true
|
|
47
|
+
if (callNow) {
|
|
48
|
+
func.apply(context, args)
|
|
71
49
|
}
|
|
72
50
|
}
|
|
73
|
-
|
|
74
|
-
return false
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function highlight(str: string, search: any, className: string) {
|
|
78
|
-
// the completed string will be itself if already set, otherwise, the string that was passed in
|
|
79
|
-
let completedString: any = str
|
|
80
|
-
const regex = new RegExp('(' + search.trim() + ')(?![^<]*>[^<>]*</)', 'i')
|
|
81
|
-
|
|
82
|
-
// If the regex doesn't match the string just exit
|
|
83
|
-
if (!str.match(regex)) { return str }
|
|
84
|
-
|
|
85
|
-
// Otherwise, get to highlighting
|
|
86
|
-
const matchStartPosition = (str.match(regex) as any).index
|
|
87
|
-
const matchEndPosition = matchStartPosition + (str.match(regex) as any)[0].toString().length
|
|
88
|
-
const originalTextFoundByRegex = str.substring(matchStartPosition, matchEndPosition)
|
|
89
|
-
completedString = completedString.replace(regex, `<mark class="${className}">${originalTextFoundByRegex}</mark>`)
|
|
90
|
-
return completedString
|
|
91
51
|
}
|
|
92
52
|
|
|
93
53
|
export function kebabCase(str: string) {
|
|
94
|
-
const result = str.replace(
|
|
95
|
-
|
|
96
|
-
(match) => '-' + match.toLowerCase()
|
|
97
|
-
)
|
|
98
|
-
return (str[0] === str[0].toUpperCase())
|
|
99
|
-
? result.substring(1)
|
|
100
|
-
: result
|
|
54
|
+
const result = str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => '-' + match.toLowerCase())
|
|
55
|
+
return str[0] === str[0].toUpperCase() ? result.substring(1) : result
|
|
101
56
|
}
|
|
102
|
-
|
|
103
|
-
// Custom events
|
|
104
|
-
(() => {
|
|
105
|
-
const w = (window as any)
|
|
106
|
-
if (typeof w.CustomEvent === 'function') { return }
|
|
107
|
-
|
|
108
|
-
function CustomEvent(event: any, params: any) {
|
|
109
|
-
params = params || { bubbles: false, cancelable: false, detail: undefined }
|
|
110
|
-
const evt = document.createEvent('CustomEvent')
|
|
111
|
-
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
|
|
112
|
-
return evt
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
CustomEvent.prototype = w.Event.prototype
|
|
116
|
-
w.CustomEvent = CustomEvent
|
|
117
|
-
})()
|