slim-select 2.2.3 → 2.3.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.
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { PropType } from 'vue';
3
3
  import SlimSelect, { Events } from '../slim-select';
4
- import Settings from '../slim-select/settings';
5
4
  import { DataArrayPartial, Option } from '../slim-select/store';
6
5
  declare const _default: import("vue").DefineComponent<{
7
6
  modelValue: {
@@ -15,7 +14,7 @@ declare const _default: import("vue").DefineComponent<{
15
14
  type: PropType<DataArrayPartial>;
16
15
  };
17
16
  settings: {
18
- type: PropType<Settings>;
17
+ type: PropType<Partial<import("../slim-select/settings").default>>;
19
18
  };
20
19
  events: {
21
20
  type: PropType<Events>;
@@ -44,7 +43,7 @@ declare const _default: import("vue").DefineComponent<{
44
43
  ref: () => NodeJS.Timeout;
45
44
  unref: () => NodeJS.Timeout;
46
45
  } | null;
47
- isEnabled: boolean;
46
+ disabled: boolean;
48
47
  alwaysOpen: boolean;
49
48
  showSearch: boolean;
50
49
  searchPlaceholder: string;
@@ -62,21 +61,20 @@ declare const _default: import("vue").DefineComponent<{
62
61
  minSelected: number;
63
62
  maxSelected: number;
64
63
  timeoutDelay: number;
64
+ maxValuesShown: number;
65
+ maxValuesMessage: string;
65
66
  };
66
67
  select: {
67
68
  select: HTMLSelectElement;
68
- listen: boolean;
69
- onSelectChange?: ((data: DataArrayPartial) => void) | undefined;
70
69
  onValueChange?: ((value: string[]) => void) | undefined;
70
+ onDisabledChange?: ((disabled: boolean) => void) | undefined;
71
+ onOptionsChange?: ((data: DataArrayPartial) => void) | undefined;
72
+ listen: boolean;
71
73
  enable: () => void;
72
74
  disable: () => void;
73
75
  hideUI: () => void;
74
76
  showUI: () => void;
75
- changeListen: (on: boolean) => void;
76
- addSelectChangeListener: (func: (data: DataArrayPartial) => void) => void;
77
- removeSelectChangeListener: () => void;
78
- addValueChangeListener: (func: (value: string[]) => void) => void;
79
- removeValueChangeListener: () => void;
77
+ changeListen: (listen: boolean) => void;
80
78
  valueChange: (ev: Event) => boolean;
81
79
  getData: () => DataArrayPartial;
82
80
  getDataFromOptgroup: (optgroup: HTMLOptGroupElement) => import("../slim-select/store").OptgroupOptional;
@@ -97,7 +95,7 @@ declare const _default: import("vue").DefineComponent<{
97
95
  getData: () => import("../slim-select/store").DataArray;
98
96
  getDataOptions: () => Option[];
99
97
  addOption: (option: import("../slim-select/store").OptionOptional) => void;
100
- setSelectedBy: (selectedType: "value" | "id", selectedValues: string[]) => void;
98
+ setSelectedBy: (selectedType: "id" | "value", selectedValues: string[]) => void;
101
99
  getSelected: () => string[];
102
100
  getSelectedOptions: () => Option[];
103
101
  getSelectedIDs: () => string[];
@@ -121,7 +119,7 @@ declare const _default: import("vue").DefineComponent<{
121
119
  ref: () => NodeJS.Timeout;
122
120
  unref: () => NodeJS.Timeout;
123
121
  } | null;
124
- isEnabled: boolean;
122
+ disabled: boolean;
125
123
  alwaysOpen: boolean;
126
124
  showSearch: boolean;
127
125
  searchPlaceholder: string;
@@ -139,6 +137,8 @@ declare const _default: import("vue").DefineComponent<{
139
137
  minSelected: number;
140
138
  maxSelected: number;
141
139
  timeoutDelay: number;
140
+ maxValuesShown: number;
141
+ maxValuesMessage: string;
142
142
  };
143
143
  store: {
144
144
  validateDataArray: (data: DataArrayPartial | import("../slim-select/store").DataArray) => Error | null;
@@ -148,7 +148,7 @@ declare const _default: import("vue").DefineComponent<{
148
148
  getData: () => import("../slim-select/store").DataArray;
149
149
  getDataOptions: () => Option[];
150
150
  addOption: (option: import("../slim-select/store").OptionOptional) => void;
151
- setSelectedBy: (selectedType: "value" | "id", selectedValues: string[]) => void;
151
+ setSelectedBy: (selectedType: "id" | "value", selectedValues: string[]) => void;
152
152
  getSelected: () => string[];
153
153
  getSelectedOptions: () => Option[];
154
154
  getSelectedIDs: () => string[];
@@ -198,6 +198,7 @@ declare const _default: import("vue").DefineComponent<{
198
198
  placeholder: string;
199
199
  values: string;
200
200
  single: string;
201
+ max: string;
201
202
  value: string;
202
203
  valueText: string;
203
204
  valueDelete: string;
@@ -258,7 +259,7 @@ declare const _default: import("vue").DefineComponent<{
258
259
  moveContentAbove: () => void;
259
260
  moveContentBelow: () => void;
260
261
  ensureElementInView: (container: HTMLElement, element: HTMLElement) => void;
261
- putContent: (el: HTMLElement, isOpen: boolean) => "up" | "down";
262
+ putContent: () => "up" | "down";
262
263
  };
263
264
  events: {
264
265
  search?: ((searchValue: string, currentData: import("../slim-select/store").DataArray) => DataArrayPartial | Promise<DataArrayPartial>) | undefined;
@@ -284,6 +285,7 @@ declare const _default: import("vue").DefineComponent<{
284
285
  search: (value: string) => void;
285
286
  destroy: () => void;
286
287
  } | null;
288
+ getCleanValue(val: string | string[] | undefined): string | string[];
287
289
  }, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
288
290
  modelValue: {
289
291
  type: PropType<string | string[] | undefined>;
@@ -296,7 +298,7 @@ declare const _default: import("vue").DefineComponent<{
296
298
  type: PropType<DataArrayPartial>;
297
299
  };
298
300
  settings: {
299
- type: PropType<Settings>;
301
+ type: PropType<Partial<import("../slim-select/settings").default>>;
300
302
  };
301
303
  events: {
302
304
  type: PropType<Events>;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@slim-select/vue",
3
3
  "private": false,
4
- "version": "1.2.1",
4
+ "version": "1.3.0",
5
5
  "description": "Vue integration",
6
6
  "repository": {
7
7
  "type": "git",
@@ -2,7 +2,7 @@
2
2
  import { defineComponent, PropType } from 'vue'
3
3
 
4
4
  import SlimSelect, { Config, Events } from '../slim-select'
5
- import Settings from '../slim-select/settings'
5
+ import { SettingsPartial } from '../slim-select/settings'
6
6
  import { DataArrayPartial, Option } from '../slim-select/store'
7
7
 
8
8
  export default defineComponent({
@@ -19,7 +19,7 @@ export default defineComponent({
19
19
  type: Array as PropType<DataArrayPartial>,
20
20
  },
21
21
  settings: {
22
- type: Object as PropType<Settings>,
22
+ type: Object as PropType<SettingsPartial>,
23
23
  },
24
24
  events: {
25
25
  type: Object as PropType<Events>,
@@ -54,7 +54,7 @@ export default defineComponent({
54
54
  config.events = {}
55
55
  }
56
56
 
57
- // Wrap config.events.afterChange to run emitUpdateSelectedValues
57
+ // Wrap config.events.afterChange to run value update
58
58
  const ogAfterChange = config.events.afterChange
59
59
  config.events.afterChange = (newVal: Option[]) => {
60
60
  const value = this.multiple ? newVal.map((option) => option.value) : newVal[0].value
@@ -79,7 +79,7 @@ export default defineComponent({
79
79
  // Check if modelValue is the same as the value of the select
80
80
  if (this.value !== selected) {
81
81
  // If not, set the value of the select to the modelValue
82
- this.value = selected
82
+ this.slim.setSelected(this.value)
83
83
  }
84
84
  },
85
85
  beforeUnmount() {
@@ -88,6 +88,13 @@ export default defineComponent({
88
88
  }
89
89
  },
90
90
  watch: {
91
+ modelValue: {
92
+ handler: function (newVal: string | string[] | undefined) {
93
+ // Set the value of the select to the newVal
94
+ this.slim?.setSelected(this.getCleanValue(newVal))
95
+ },
96
+ immediate: true,
97
+ },
91
98
  data: {
92
99
  handler: function (newData) {
93
100
  if (this.slim) {
@@ -100,25 +107,7 @@ export default defineComponent({
100
107
  computed: {
101
108
  value: {
102
109
  get(): string | string[] {
103
- const multi = this.$props.multiple
104
- const val = this.$props.modelValue
105
-
106
- // If modelValue is undefined, return empty string or array
107
- if (val === undefined) {
108
- return multi ? [] : ''
109
- }
110
-
111
- // If its multiple and the modelValue is a string, return an array with the string
112
- if (multi && typeof val === 'string') {
113
- return [val]
114
- }
115
-
116
- // If its not multiple and the modelValue is an array, return the first item
117
- if (!multi && Array.isArray(val)) {
118
- return val[0]
119
- }
120
-
121
- return multi ? [] : ''
110
+ return this.getCleanValue(this.$props.modelValue)
122
111
  },
123
112
  set(value: string | string[]) {
124
113
  this.$emit('update:modelValue', value)
@@ -130,6 +119,21 @@ export default defineComponent({
130
119
  getSlimSelect() {
131
120
  return this.slim
132
121
  },
122
+ getCleanValue(val: string | string[] | undefined): string | string[] {
123
+ const multi = this.$props.multiple
124
+
125
+ // If its multiple and the modelValue is a string, return an array with the string
126
+ if (typeof val === 'string') {
127
+ return multi ? [val] : val
128
+ }
129
+
130
+ // If its not multiple and the modelValue is an array, return the first item
131
+ if (Array.isArray(val)) {
132
+ return multi ? val : val[0]
133
+ }
134
+
135
+ return multi ? [] : ''
136
+ },
133
137
  },
134
138
  })
135
139
  </script>