slim-select 2.0.1 → 2.1.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.
Files changed (85) hide show
  1. package/dist/{helper.d.ts → helpers.d.ts} +0 -0
  2. package/dist/index.d.ts +1 -7
  3. package/dist/render.d.ts +1 -1
  4. package/dist/settings.d.ts +1 -1
  5. package/dist/slimselect.cjs.js +1589 -2
  6. package/dist/slimselect.css +1 -1
  7. package/dist/slimselect.css.map +1 -1
  8. package/dist/slimselect.es.js +1587 -2
  9. package/dist/slimselect.global.js +1592 -2
  10. package/dist/slimselect.js +1595 -2
  11. package/dist/slimselect.min.js +1 -0
  12. package/dist/slimselect.umd.js +1595 -2
  13. package/dist/slimselect.umd.min.js +1 -0
  14. package/dist/store.d.ts +5 -5
  15. package/docs/404.html +18 -12
  16. package/docs/assets/home.js +1 -1
  17. package/docs/assets/index.css +1 -1
  18. package/docs/assets/index.js +7 -7
  19. package/docs/assets/index3.js +25 -16
  20. package/docs/assets/index5.js +147 -0
  21. package/docs/assets/install.js +6 -6
  22. package/docs/index.html +20 -2
  23. package/index.html +20 -2
  24. package/package.json +17 -6
  25. package/public/404.html +18 -12
  26. package/src/docs/app.vue +10 -4
  27. package/{docs → src/docs/assets}/images/check-mark.svg +0 -0
  28. package/{docs → src/docs/assets}/images/chrome.svg +0 -0
  29. package/{docs → src/docs/assets}/images/firefox.svg +0 -0
  30. package/{docs → src/docs/assets}/images/github.png +0 -0
  31. package/{docs → src/docs/assets}/images/ie.svg +0 -0
  32. package/{docs → src/docs/assets}/images/npm.png +0 -0
  33. package/{docs → src/docs/assets}/images/opera.svg +0 -0
  34. package/{docs → src/docs/assets}/images/safari.svg +0 -0
  35. package/src/docs/assets/scss/_variables.scss +1 -1
  36. package/src/docs/assets/scss/misc.scss +7 -0
  37. package/src/docs/env.d.ts +1 -0
  38. package/src/docs/pages/events/addable.vue +22 -6
  39. package/src/docs/pages/events/before_after_change.vue +15 -1
  40. package/src/docs/pages/events/search.vue +2 -1
  41. package/src/docs/pages/frameworks/index.vue +18 -0
  42. package/src/docs/pages/frameworks/vue.vue +405 -0
  43. package/src/docs/pages/home.vue +19 -19
  44. package/src/docs/pages/install.vue +27 -6
  45. package/src/docs/pages/methods/get_data.vue +2 -1
  46. package/src/docs/pages/methods/open_close.vue +1 -1
  47. package/src/docs/router.ts +5 -0
  48. package/src/slim-select/{helper.ts → helpers.ts} +0 -0
  49. package/src/slim-select/index.ts +2 -12
  50. package/src/slim-select/render.ts +84 -26
  51. package/src/slim-select/rollup.config.mjs +117 -30
  52. package/src/slim-select/select.ts +15 -6
  53. package/src/slim-select/settings.ts +1 -1
  54. package/src/slim-select/slimselect.scss +7 -0
  55. package/src/slim-select/store.ts +1 -1
  56. package/src/vue/dist/slimselectvue.es.js +1655 -0
  57. package/src/vue/dist/slimselectvue.global.js +1658 -0
  58. package/src/vue/dist/slimselectvue.ssr.js +1657 -0
  59. package/src/vue/hello.ts +5 -0
  60. package/src/vue/package.json +27 -0
  61. package/src/vue/rollup.config.mjs +44 -0
  62. package/src/vue/slimselect.vue +59 -43
  63. package/src/vue/tsconfig.json +14 -0
  64. package/dist/slimselect.cjs.js.map +0 -1
  65. package/dist/slimselect.es.js.map +0 -1
  66. package/dist/slimselect.global.js.map +0 -1
  67. package/dist/slimselect.js.map +0 -1
  68. package/dist/slimselect.umd.js.map +0 -1
  69. package/public/images/check-mark.svg +0 -6
  70. package/public/images/chrome.svg +0 -22
  71. package/public/images/firefox.svg +0 -58
  72. package/public/images/github.png +0 -0
  73. package/public/images/ie.svg +0 -11
  74. package/public/images/npm.png +0 -0
  75. package/public/images/opera.svg +0 -15
  76. package/public/images/safari.svg +0 -22
  77. package/public/index.html +0 -28
  78. package/src/docs/images/check-mark.svg +0 -6
  79. package/src/docs/images/chrome.svg +0 -22
  80. package/src/docs/images/firefox.svg +0 -58
  81. package/src/docs/images/github.png +0 -0
  82. package/src/docs/images/ie.svg +0 -11
  83. package/src/docs/images/npm.png +0 -0
  84. package/src/docs/images/opera.svg +0 -15
  85. package/src/docs/images/safari.svg +0 -22
@@ -43,19 +43,36 @@ export default defineComponent({
43
43
 
44
44
  <div id="cdn" class="content">
45
45
  <h2>Cdn</h2>
46
- <p>Cdn has a url link you can grab.</p>
47
46
  <p>
48
- See full list of available options.
49
- <a target="_blank" href="https://cdnjs.com/libraries/slim-select">cdnjs.com/libraries/slim-select</a>
47
+ Cdn has a url link you can grab. Cdn exists on both
48
+ <a target="_blank" href="https://cdnjs.com">cdnjs.com</a> and
49
+ <a target="_blank" href="https://unpkg.com">unpkg.com</a>
50
+ </p>
51
+ <p>
52
+ See full list of available options.<br />
53
+ <strong>cdnjs</strong> -
54
+ <a target="_blank" href="https://cdnjs.com/libraries/slim-select">cdnjs.com/libraries/slim-select</a><br />
55
+ <strong>unpkg</strong> -
56
+ <a target="_blank" href="https://unpkg.com/browse/slim-select/dist/"
57
+ >https://unpkg.com/browse/slim-select/dist/</a
58
+ >
50
59
  </p>
60
+ <ul>
61
+ <li>slimselct.js - UMD unminified</li>
62
+ <li>slimselct.min.js - UMD minified</li>
63
+ <li>slimselect.cjs.js - CommonJS (for Node) and ES module (for bundlers) build</li>
64
+ <li>slimselect.umd.js - UMD build for browsers</li>
65
+ <li>slimselect.es.js - ES module build for modern browsers</li>
66
+ <li>slimselect.global.js - IIFE build for modern browsers</li>
67
+ </ul>
51
68
  <div class="alert info">New releases may be delayed until the next time its indexed</div>
52
69
 
53
70
  <pre class="install-code">
54
71
  <code class="language-html">
55
72
  &lt;html&gt;
56
73
  &lt;head&gt;
57
- &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/slim-select/{{version}}/slimselect.js"&gt;&lt;/script&gt;
58
- &lt;link href="https://cdnjs.cloudflare.com/ajax/libs/slim-select/{{version}}/slimselect.css" rel="stylesheet"&gt;&lt;/link&gt;
74
+ &lt;script src="unpkg.com/slim-select@{{version}}/dist/slimselect.min.js"&gt;&lt;/script&gt;
75
+ &lt;link href="unpkg.com/slim-select@{{version}}/dist/slimselect.css" rel="stylesheet"&gt;&lt;/link&gt;
59
76
 
60
77
  &lt;script&gt;
61
78
  new SlimSelect({
@@ -77,7 +94,11 @@ export default defineComponent({
77
94
 
78
95
  <div id="download" class="content">
79
96
  <h2>Download</h2>
80
- <p>Download the latest minified version of slim select</p>
97
+ <p>Download the latest minified umd version of slim select</p>
98
+ <p>
99
+ See full list of available downloadable options.
100
+ <a target="_blank" href="https://cdnjs.com/libraries/slim-select">cdnjs.com/libraries/slim-select</a>
101
+ </p>
81
102
  <div class="btn" @click="downloadLink()">Click Here To Download</div>
82
103
  </div>
83
104
  </div>
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
2
  import { defineComponent } from 'vue'
3
3
 
4
- import SlimSelect, { DataArray } from '../../../slim-select'
4
+ import SlimSelect from '../../../slim-select'
5
+ import { DataArray } from '../../../slim-select/store'
5
6
 
6
7
  export default defineComponent({
7
8
  name: 'GetData',
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { defineComponent } from 'vue'
3
3
 
4
- import SlimSelect, { DataArray } from '../../../slim-select'
4
+ import SlimSelect from '../../../slim-select'
5
5
 
6
6
  export default defineComponent({
7
7
  name: 'OpenClose',
@@ -39,6 +39,11 @@ const router = createRouter({
39
39
  name: 'Methods',
40
40
  component: () => import('./pages/methods/index.vue'),
41
41
  },
42
+ {
43
+ path: '/frameworks',
44
+ name: 'Frameworks',
45
+ component: () => import('./pages/frameworks/index.vue'),
46
+ },
42
47
  ],
43
48
  })
44
49
 
File without changes
@@ -1,19 +1,9 @@
1
- import { debounce, hasClassInTree } from './helper'
1
+ import { debounce, hasClassInTree } from './helpers'
2
2
  import Render from './render'
3
3
  import Select from './select'
4
4
  import Settings, { SettingsPartial } from './settings'
5
5
  import Store, { DataArray, DataArrayPartial, Option, OptionOptional } from './store'
6
6
 
7
- // Export everything except the "export default"
8
- export * from './helper'
9
- export * from './settings'
10
- export * from './select'
11
- export * from './store'
12
- export * from './render'
13
-
14
- // Export all "export defaults"
15
- export { Settings, Select, Store, Render }
16
-
17
7
  export interface Config {
18
8
  select: string | Element
19
9
  data?: DataArrayPartial
@@ -24,7 +14,7 @@ export interface Config {
24
14
  export interface Events {
25
15
  search?: (searchValue: string, currentData: DataArray) => Promise<DataArrayPartial> | DataArrayPartial
26
16
  searchFilter?: (option: Option, search: string) => boolean
27
- addable?: (value: string) => OptionOptional | string
17
+ addable?: (value: string) => Promise<OptionOptional | string> | OptionOptional | string
28
18
  beforeChange?: (newVal: Option[], oldVal: Option[]) => boolean | void
29
19
  afterChange?: (newVal: Option[]) => void
30
20
  beforeOpen?: () => void
@@ -1,11 +1,11 @@
1
- import { debounce } from './helper'
1
+ import { debounce } from './helpers'
2
2
  import Settings from './settings'
3
3
  import Store, { DataArray, Optgroup, Option, OptionOptional } from './store'
4
4
 
5
5
  export interface Callbacks {
6
6
  open: () => void
7
7
  close: () => void
8
- addable?: (value: string) => OptionOptional | string
8
+ addable?: (value: string) => Promise<OptionOptional | string> | OptionOptional | string
9
9
  setSelected: (value: string[]) => void
10
10
  addOption: (option: Option) => void
11
11
  search: (search: string) => void
@@ -266,6 +266,8 @@ export default class Render {
266
266
  if (!this.settings.allowDeselect || this.settings.isMultiple) {
267
267
  deselect.classList.add(this.classes.hide)
268
268
  }
269
+
270
+ // Add deselect onclick event
269
271
  deselect.onclick = (e: Event) => {
270
272
  e.stopPropagation()
271
273
 
@@ -274,7 +276,29 @@ export default class Render {
274
276
  return
275
277
  }
276
278
 
277
- this.callbacks.setSelected([''])
279
+ // By Default we will delete
280
+ let shouldDelete = true
281
+ const before = this.store.getSelectedOptions()
282
+ const after = [] as Option[]
283
+
284
+ // Add beforeChange callback
285
+ if (this.callbacks.beforeChange) {
286
+ shouldDelete = this.callbacks.beforeChange(after, before) === true
287
+ }
288
+
289
+ if (shouldDelete) {
290
+ this.callbacks.setSelected([''])
291
+
292
+ // Check if we need to close the dropdown
293
+ if (this.settings.closeOnSelect) {
294
+ this.callbacks.close()
295
+ }
296
+
297
+ // Run afterChange callback
298
+ if (this.callbacks.afterChange) {
299
+ this.callbacks.afterChange(after)
300
+ }
301
+ }
278
302
  }
279
303
 
280
304
  // Add deselect svg
@@ -466,8 +490,11 @@ export default class Render {
466
490
 
467
491
  // Only add deletion if the option is not mandatory
468
492
  if (!option.mandatory) {
493
+ // Create delete div element
469
494
  const deleteDiv = document.createElement('div')
470
495
  deleteDiv.classList.add(this.classes.valueDelete)
496
+
497
+ // Add delete onclick event
471
498
  deleteDiv.onclick = (e: Event) => {
472
499
  e.preventDefault()
473
500
  e.stopPropagation()
@@ -656,13 +683,18 @@ export default class Render {
656
683
 
657
684
  // If addable is enabled, add the addable div
658
685
  if (this.callbacks.addable) {
686
+ // Add main class
659
687
  addable.classList.add(this.classes.addable)
688
+
689
+ // Add svg icon
660
690
  const plus = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
661
691
  plus.setAttribute('viewBox', '0 0 100 100')
662
692
  const plusPath = document.createElementNS('http://www.w3.org/2000/svg', 'path')
663
693
  plusPath.setAttribute('d', this.classes.addablePath)
664
694
  plus.appendChild(plusPath)
665
695
  addable.appendChild(plus)
696
+
697
+ // Add click event to addable div
666
698
  addable.onclick = (e: Event) => {
667
699
  e.preventDefault()
668
700
  e.stopPropagation()
@@ -679,35 +711,61 @@ export default class Render {
679
711
  return
680
712
  }
681
713
 
714
+ // Run finish will be ran at the end of the addable function.
715
+ // Reason its in a function is so we can run it after the
716
+ // addable function is done for promise based addables
717
+ const runFinish = (oo: OptionOptional) => {
718
+ let newOption = new Option(oo)
719
+
720
+ // Call addOption to add the new option
721
+ this.callbacks.addOption(newOption)
722
+
723
+ // set selected value for single and multiple
724
+ if (this.settings.isMultiple) {
725
+ let values = this.store.getSelected()
726
+ values.push(newOption.value)
727
+ this.callbacks.setSelected(values)
728
+ } else {
729
+ this.callbacks.setSelected([newOption.value])
730
+ }
731
+
732
+ // Clear search
733
+ this.callbacks.search('')
734
+
735
+ // Close it only if closeOnSelect = true
736
+ if (this.settings.closeOnSelect) {
737
+ setTimeout(() => {
738
+ // Give it a little padding for a better looking animation
739
+ this.callbacks.close()
740
+ }, 100)
741
+ }
742
+ }
743
+
682
744
  // Call addable callback
683
745
  const addableValue = this.callbacks.addable(inputValue)
684
746
 
685
- // If the addableValue is a string, we will add it as a new option
686
- // Otherwise we will assume it is an option object
687
- if (typeof addableValue === 'string') {
688
- this.callbacks.addOption(
689
- new Option({
690
- text: addableValue,
691
- value: addableValue,
692
- }),
693
- )
747
+ // If addableValue is a promise, wait for it to resolve
748
+ if (addableValue instanceof Promise) {
749
+ addableValue.then((value) => {
750
+ if (typeof value === 'string') {
751
+ runFinish({
752
+ text: value,
753
+ value: value,
754
+ })
755
+ } else {
756
+ runFinish(value)
757
+ }
758
+ })
759
+ } else if (typeof addableValue === 'string') {
760
+ runFinish({
761
+ text: addableValue,
762
+ value: addableValue,
763
+ })
694
764
  } else {
695
- this.callbacks.addOption(new Option(addableValue))
765
+ runFinish(addableValue)
696
766
  }
697
767
 
698
- // Add option to selected
699
- this.callbacks.setSelected([inputValue])
700
-
701
- // Clear search
702
- this.callbacks.search('')
703
-
704
- // Close it only if closeOnSelect = true
705
- if (this.settings.closeOnSelect) {
706
- setTimeout(() => {
707
- // Give it a little padding for a better looking animation
708
- this.callbacks.close()
709
- }, 100)
710
- }
768
+ return
711
769
  }
712
770
  main.appendChild(addable)
713
771
 
@@ -1,40 +1,127 @@
1
1
  import typescript from '@rollup/plugin-typescript'
2
- import { terser } from 'rollup-plugin-terser'
2
+ import babel from '@rollup/plugin-babel'
3
+ import commonjs from '@rollup/plugin-commonjs'
4
+ import resolve from '@rollup/plugin-node-resolve'
5
+ import terser from '@rollup/plugin-terser'
3
6
 
4
- export default {
5
- input: './index.ts',
6
- output: [
7
- // Default umd
8
- {
9
- name: 'SlimSelect',
10
- file: '../../dist/slimselect.js',
11
- format: 'umd',
12
- sourcemap: true,
7
+ export default [
8
+ // CommonJS (for Node) and ES module (for bundlers) build
9
+ {
10
+ input: './index.ts',
11
+ output: {
12
+ file: '../../dist/slimselect.cjs.js',
13
+ format: 'cjs',
14
+ exports: 'default',
13
15
  },
14
- {
15
- name: 'SlimSelect',
16
+ plugins: [
17
+ typescript(),
18
+ resolve(),
19
+ commonjs(),
20
+ babel({
21
+ babelHelpers: 'bundled',
22
+ exclude: 'node_modules/**',
23
+ babelrc: false,
24
+ presets: [
25
+ [
26
+ '@babel/env',
27
+ {
28
+ modules: false,
29
+ useBuiltIns: 'usage',
30
+ targets: 'maintained node versions',
31
+ },
32
+ ],
33
+ ],
34
+ }),
35
+ ],
36
+ },
37
+
38
+ // UMD build for browsers
39
+ {
40
+ input: './index.ts',
41
+ output: [
42
+ {
43
+ name: 'SlimSelect',
44
+ file: '../../dist/slimselect.js',
45
+ format: 'umd',
46
+ },
47
+ {
48
+ name: 'SlimSelect',
49
+ file: '../../dist/slimselect.umd.js',
50
+ format: 'umd',
51
+ },
52
+ ],
53
+ plugins: [
54
+ typescript(),
55
+ resolve(),
56
+ commonjs(),
57
+ babel({
58
+ babelHelpers: 'bundled',
59
+ exclude: 'node_modules/**',
60
+ }),
61
+ ],
62
+ },
63
+
64
+ // UMD build for browsers minified with terser
65
+ {
66
+ input: './index.ts',
67
+ output: [
68
+ {
69
+ name: 'SlimSelect',
70
+ file: '../../dist/slimselect.min.js',
71
+ format: 'umd',
72
+ },
73
+ {
74
+ name: 'SlimSelect',
75
+ file: '../../dist/slimselect.umd.min.js',
76
+ format: 'umd',
77
+ },
78
+ ],
79
+ plugins: [
80
+ typescript(),
81
+ resolve(),
82
+ commonjs(),
83
+ babel({
84
+ babelHelpers: 'bundled',
85
+ exclude: 'node_modules/**',
86
+ }),
87
+ terser(),
88
+ ],
89
+ },
90
+
91
+ // ES module build for modern browsers
92
+ {
93
+ input: './index.ts',
94
+ output: {
16
95
  file: '../../dist/slimselect.es.js',
17
96
  format: 'es',
18
- sourcemap: true,
19
97
  },
20
- {
21
- name: 'SlimSelect',
22
- file: '../../dist/slimselect.cjs.js',
23
- format: 'cjs',
24
- sourcemap: true,
25
- },
26
- {
98
+ plugins: [
99
+ typescript(),
100
+ resolve(),
101
+ commonjs(),
102
+ babel({
103
+ babelHelpers: 'bundled',
104
+ exclude: 'node_modules/**',
105
+ }),
106
+ ],
107
+ },
108
+
109
+ // IIFE build for modern browsers
110
+ {
111
+ input: './index.ts',
112
+ output: {
27
113
  name: 'SlimSelect',
28
114
  file: '../../dist/slimselect.global.js',
29
115
  format: 'iife',
30
- sourcemap: true,
31
- },
32
- {
33
- name: 'SlimSelect',
34
- file: '../../dist/slimselect.umd.js',
35
- format: 'umd',
36
- sourcemap: true,
37
116
  },
38
- ],
39
- plugins: [typescript(), terser()],
40
- }
117
+ plugins: [
118
+ typescript(),
119
+ resolve(),
120
+ commonjs(),
121
+ babel({
122
+ babelHelpers: 'bundled',
123
+ exclude: 'node_modules/**',
124
+ }),
125
+ ],
126
+ },
127
+ ]
@@ -1,5 +1,5 @@
1
- import { generateID, kebabCase } from './helper'
2
- import { DataArray, DataObject, Optgroup, Option } from './store'
1
+ import { generateID, kebabCase } from './helpers'
2
+ import { DataArray, Optgroup, Option } from './store'
3
3
 
4
4
  export default class Select {
5
5
  public select: HTMLSelectElement
@@ -86,7 +86,11 @@ export default class Select {
86
86
 
87
87
  private observeWrapper(mutations: MutationRecord[]): void {
88
88
  if (this.onSelectChange) {
89
+ // Just in case this triggers a change in the select
90
+ // we want to stop listening to it while we run onSelectChange
91
+ this.changeListen(false)
89
92
  this.onSelectChange(this.getData())
93
+ this.changeListen(true)
90
94
  }
91
95
  }
92
96
 
@@ -99,16 +103,21 @@ export default class Select {
99
103
  }
100
104
 
101
105
  // If anything changes in the select then update the data
102
- this.observer = new MutationObserver(this.observeWrapper)
106
+ this.observer = new MutationObserver(this.observeWrapper.bind(this))
103
107
  }
104
108
 
109
+ // Start observing the select
105
110
  private connectObserver(): void {
106
111
  if (this.observer) {
107
112
  this.observer.observe(this.select, {
108
- attributes: true,
113
+ // For now we only care about if the children change
109
114
  childList: true,
110
- characterData: true,
111
- subtree: true,
115
+
116
+ // We dont care about attributes for now
117
+ // might need to add this later
118
+ // attributes: true,
119
+ // characterData: true,
120
+ // subtree: true,
112
121
  })
113
122
  }
114
123
  }
@@ -1,4 +1,4 @@
1
- import { generateID } from './helper'
1
+ import { generateID } from './helpers'
2
2
 
3
3
  export type SettingsPartial = Partial<Settings>
4
4
 
@@ -150,12 +150,16 @@
150
150
  .ss-value-delete {
151
151
  display: flex;
152
152
  align-items: center;
153
+ height: var(--ss-spacing-l);
153
154
  width: var(--ss-spacing-l);
154
155
  padding: var(--ss-spacing-s) var(--ss-spacing-m);
155
156
  cursor: pointer;
156
157
  border-left: solid 1px var(--ss-bg-color);
157
158
 
158
159
  svg {
160
+ height: var(--ss-spacing-l);
161
+ width: var(--ss-spacing-l);
162
+
159
163
  path {
160
164
  fill: none;
161
165
  stroke: var(--ss-bg-color);
@@ -178,6 +182,9 @@
178
182
  margin: 0 var(--ss-spacing-m) 0 var(--ss-spacing-m);
179
183
 
180
184
  svg {
185
+ width: 8px;
186
+ height: 8px;
187
+
181
188
  path {
182
189
  fill: none;
183
190
  stroke: var(--ss-font-color);
@@ -1,4 +1,4 @@
1
- import { generateID } from './helper'
1
+ import { generateID } from './helpers'
2
2
 
3
3
  export type DataArray = DataObject[]
4
4
  export type DataObject = Optgroup | Option