slim-select 1.27.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/.github/ISSUE_TEMPLATE/issue-report.md +3 -3
  2. package/.nvmrc +1 -0
  3. package/.prettierrc +6 -0
  4. package/.vscode/extensions.json +3 -0
  5. package/.vscode/settings.json +15 -5
  6. package/README.md +17 -19
  7. package/dist/helper.d.ts +1 -4
  8. package/dist/index.d.ts +38 -58
  9. package/dist/render.d.ts +109 -0
  10. package/dist/select.d.ts +31 -20
  11. package/dist/settings.d.ts +33 -0
  12. package/dist/slimselect.cjs.js +2 -0
  13. package/dist/slimselect.cjs.js.map +1 -0
  14. package/dist/slimselect.css +1 -2
  15. package/dist/slimselect.css.map +1 -0
  16. package/dist/slimselect.es.js +2 -0
  17. package/dist/slimselect.es.js.map +1 -0
  18. package/dist/slimselect.global.js +2 -0
  19. package/dist/slimselect.global.js.map +1 -0
  20. package/dist/slimselect.js +2 -1970
  21. package/dist/slimselect.js.map +1 -0
  22. package/dist/slimselect.umd.js +2 -0
  23. package/dist/slimselect.umd.js.map +1 -0
  24. package/dist/store.d.ts +71 -0
  25. package/docs/assets/check-mark.svg +6 -0
  26. package/docs/assets/data.js +59 -0
  27. package/docs/assets/home.css +1 -0
  28. package/docs/assets/home.js +1 -0
  29. package/docs/assets/index.css +1 -0
  30. package/docs/assets/index.js +16 -0
  31. package/docs/assets/index2.js +274 -0
  32. package/docs/assets/index3.js +126 -0
  33. package/docs/assets/index4.js +60 -0
  34. package/docs/assets/install.js +34 -0
  35. package/docs/assets/selects.js +55 -0
  36. package/docs/index.html +18 -5
  37. package/docs.go +3 -1
  38. package/index.html +16 -0
  39. package/jest.config.js +7 -0
  40. package/package.json +39 -35
  41. package/src/docs/app.vue +196 -73
  42. package/src/docs/assets/scss/_variables.scss +26 -10
  43. package/src/docs/assets/scss/alert.scss +12 -0
  44. package/src/docs/assets/scss/animations.scss +5 -3
  45. package/src/docs/assets/scss/button.scss +21 -0
  46. package/src/docs/assets/scss/index.scss +8 -6
  47. package/src/docs/assets/scss/input.scss +2 -2
  48. package/src/docs/assets/scss/layout.scss +195 -65
  49. package/src/docs/assets/scss/misc.scss +144 -34
  50. package/src/docs/assets/scss/prism.scss +155 -153
  51. package/src/docs/env.d.ts +12 -0
  52. package/src/docs/images/check-mark.svg +6 -0
  53. package/src/docs/images/chrome.svg +22 -0
  54. package/src/docs/images/firefox.svg +58 -0
  55. package/src/docs/images/github.png +0 -0
  56. package/src/docs/images/ie.svg +11 -0
  57. package/src/docs/images/npm.png +0 -0
  58. package/src/docs/images/opera.svg +15 -0
  59. package/src/docs/images/safari.svg +22 -0
  60. package/src/docs/main.ts +27 -0
  61. package/src/docs/pages/data.vue +130 -0
  62. package/src/docs/pages/events/addable.vue +79 -0
  63. package/src/docs/pages/events/before_after_change.vue +140 -0
  64. package/src/docs/pages/events/before_after_open_close.vue +122 -0
  65. package/src/docs/pages/events/error.vue +59 -0
  66. package/src/docs/pages/events/index.vue +33 -0
  67. package/src/docs/pages/events/search.vue +154 -0
  68. package/src/docs/pages/events/search_filter.vue +45 -0
  69. package/src/docs/pages/home.vue +131 -117
  70. package/src/docs/pages/install.vue +51 -74
  71. package/src/docs/pages/methods/destroy.vue +66 -0
  72. package/src/docs/pages/methods/enable_disable.vue +70 -0
  73. package/src/docs/pages/methods/get_data.vue +81 -0
  74. package/src/docs/pages/methods/get_selected.vue +78 -0
  75. package/src/docs/pages/methods/index.vue +36 -0
  76. package/src/docs/pages/methods/open_close.vue +63 -0
  77. package/src/docs/pages/methods/search.vue +62 -0
  78. package/src/docs/pages/methods/set_data.vue +106 -0
  79. package/src/docs/pages/methods/set_selected.vue +70 -0
  80. package/src/docs/pages/selects.vue +108 -114
  81. package/src/docs/pages/settings/always_open.vue +88 -0
  82. package/src/docs/pages/settings/close_on_select.vue +69 -0
  83. package/src/docs/pages/settings/content_location.vue +64 -0
  84. package/src/docs/pages/settings/content_position.vue +86 -0
  85. package/src/docs/pages/settings/css.vue +73 -0
  86. package/src/docs/pages/settings/data_attributes.vue +39 -0
  87. package/src/docs/pages/settings/deselect.vue +69 -0
  88. package/src/docs/pages/settings/display.vue +88 -0
  89. package/src/docs/pages/settings/hide_selected.vue +73 -0
  90. package/src/docs/pages/settings/html.vue +86 -0
  91. package/src/docs/pages/settings/index.vue +73 -0
  92. package/src/docs/pages/settings/mandatory.vue +91 -0
  93. package/src/docs/pages/settings/min_max.vue +61 -0
  94. package/src/docs/pages/settings/open_position.vue +60 -0
  95. package/src/docs/pages/settings/placeholder.vue +72 -0
  96. package/src/docs/pages/settings/search.vue +140 -0
  97. package/src/docs/pages/settings/select.vue +32 -0
  98. package/src/docs/pages/settings/select_by_group.vue +46 -0
  99. package/src/docs/pages/settings/show_tooltip.vue +44 -0
  100. package/src/docs/pages/settings/styles.vue +51 -0
  101. package/src/docs/router.ts +41 -13
  102. package/src/slim-select/helper.ts +25 -86
  103. package/src/slim-select/index.ts +317 -420
  104. package/src/slim-select/render.test.ts +39 -0
  105. package/src/slim-select/render.ts +1129 -0
  106. package/src/slim-select/rollup.config.mjs +40 -0
  107. package/src/slim-select/select.test.ts +155 -0
  108. package/src/slim-select/select.ts +280 -108
  109. package/src/slim-select/settings.ts +68 -0
  110. package/src/slim-select/slimselect.scss +263 -278
  111. package/src/slim-select/store.test.ts +220 -0
  112. package/src/slim-select/store.ts +320 -0
  113. package/src/slim-select/tsconfig.json +11 -5
  114. package/src/vue/slimselect.vue +61 -0
  115. package/tsconfig.json +10 -29
  116. package/vite.config.ts +18 -0
  117. package/.browserslistrc +0 -4
  118. package/.postcssrc.js +0 -5
  119. package/.travis.yml +0 -22
  120. package/babel.config.js +0 -5
  121. package/dist/config.d.ts +0 -83
  122. package/dist/data.d.ts +0 -50
  123. package/dist/slim.d.ts +0 -50
  124. package/dist/slimselect.min.css +0 -1
  125. package/dist/slimselect.min.js +0 -1
  126. package/dist/slimselect.min.mjs +0 -1
  127. package/docs/css/app.d5840d21.css +0 -1
  128. package/docs/css/chunk-vendors.fa8199af.css +0 -1
  129. package/docs/css/home.57020178.css +0 -1
  130. package/docs/css/install.baa5d3fb.css +0 -1
  131. package/docs/css/methods.728c742a.css +0 -1
  132. package/docs/css/options.b28a32ef.css +0 -1
  133. package/docs/css/selects.1a7e1e6a.css +0 -1
  134. package/docs/js/app.238ee382.js +0 -2
  135. package/docs/js/app.238ee382.js.map +0 -1
  136. package/docs/js/chunk-vendors.5125e3d8.js +0 -21
  137. package/docs/js/chunk-vendors.5125e3d8.js.map +0 -1
  138. package/docs/js/home.e7b28581.js +0 -2
  139. package/docs/js/home.e7b28581.js.map +0 -1
  140. package/docs/js/install.d4300783.js +0 -2
  141. package/docs/js/install.d4300783.js.map +0 -1
  142. package/docs/js/methods.fa1608f1.js +0 -11
  143. package/docs/js/methods.fa1608f1.js.map +0 -1
  144. package/docs/js/options.2c4ceb87.js +0 -2
  145. package/docs/js/options.2c4ceb87.js.map +0 -1
  146. package/docs/js/selects.1eeba693.js +0 -2
  147. package/docs/js/selects.1eeba693.js.map +0 -1
  148. package/src/docs/pages/methods.vue +0 -427
  149. package/src/docs/pages/options.vue +0 -1480
  150. package/src/main.ts +0 -29
  151. package/src/shims-vue.d.ts +0 -8
  152. package/src/slim-select/config.ts +0 -118
  153. package/src/slim-select/data.ts +0 -377
  154. package/src/slim-select/slim.ts +0 -775
  155. package/src/slim-select/webpack.config.js +0 -73
  156. package/tslint.json +0 -26
  157. 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
+ &lt;select id="select-style" style="color: red;"&gt;
38
+ &lt;option value="value1"&gt;Value 1&lt;/option&gt;
39
+ &lt;option value="value2"&gt;Value 2&lt;/option&gt;
40
+ &lt;option value="value3"&gt;Value 3&lt;/option&gt;
41
+ &lt;/select&gt;
42
+
43
+ &lt;select id="option-style"&gt;
44
+ &lt;option style="color: red;" value="value1"&gt;Red&lt;/option&gt;
45
+ &lt;option style="color: green;"&gt;Green&lt;/option&gt;
46
+ &lt;option style="color: blue;"&gt;Blue&lt;/option&gt;
47
+ &lt;/select&gt;
48
+ </code>
49
+ </pre>
50
+ </div>
51
+ </template>
@@ -1,17 +1,45 @@
1
- import Vue from 'vue'
2
- import Router from 'vue-router'
1
+ import { createRouter, createWebHistory } from 'vue-router'
3
2
 
4
- Vue.use(Router)
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
- { path: '/', component: () => import(/* webpackChunkName: "home" */ './pages/home.vue') },
12
- { path: '/install', component: () => import(/* webpackChunkName: "install" */ './pages/install.vue') },
13
- { path: '/selects', component: () => import(/* webpackChunkName: "selects" */ './pages/selects.vue') },
14
- { path: '/options', component: () => import(/* webpackChunkName: "options" */ './pages/options.vue') },
15
- { path: '/methods', component: () => import(/* webpackChunkName: "methods" */ './pages/methods.vue') }
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
- if (!(!c || !e || !e.classList || !e.classList.contains(c))) { return e }
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 ensureElementInView(container: HTMLElement, element: HTMLElement): void {
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) { func.apply(context, args) }
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) { func.apply(context, args) }
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
- /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,
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
- })()