@danielgindi/selectbox 2.0.26 → 2.0.27

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/lib/DropList.js CHANGED
@@ -114,7 +114,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
114
114
  /** */
115
115
 
116
116
  /** @type {DropList.Options} */
117
- let defaultOptions = {
117
+ export const DefaultOptions = {
118
118
  baseClassName: 'droplist',
119
119
 
120
120
  autoItemBlur: true,
@@ -173,7 +173,7 @@ class DropList {
173
173
  * @param {DropList.Options} options
174
174
  */
175
175
  constructor(options) {
176
- const o = { ...defaultOptions };
176
+ const o = { ...DefaultOptions };
177
177
 
178
178
  for (let [key, value] of Object.entries(/**@type Object*/options))
179
179
  if (value !== undefined)
package/lib/SelectBox.js CHANGED
@@ -96,6 +96,7 @@ const inputBackbufferCssProps = [
96
96
  * @property {string} [labelProp='label']
97
97
  * @property {string} [valueProp='value']
98
98
  * @property {string} [multiItemLabelProp='short_label']
99
+ * @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
99
100
  * @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
100
101
  * @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
101
102
  * @property {DropList.ItemBase[]|null} [items] initial items
@@ -118,7 +119,7 @@ const inputBackbufferCssProps = [
118
119
  * @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
119
120
  * @property {string[]} [clearInputWhen=['single_close','multi_select_single']] clear input box when closing the droplist or selecting <code>['single_close', 'multi_close', 'multi_select_single']</code>
120
121
  * */
121
- const defaultOptions = {
122
+ export const DefaultOptions = {
122
123
  el: null,
123
124
  baseClassName: 'selectbox',
124
125
  disabled: false,
@@ -145,6 +146,7 @@ const defaultOptions = {
145
146
  labelProp: 'label',
146
147
  valueProp: 'value',
147
148
  multiItemLabelProp: 'short_label',
149
+ multiItemRemovePosition: 'after',
148
150
  maxMultiItems: null,
149
151
  multiItemsRestLabelProvider: null,
150
152
  items: [],
@@ -203,7 +205,7 @@ class SelectBox {
203
205
  * @param {SelectBox.Options} options
204
206
  */
205
207
  constructor(options) {
206
- const o = { ...defaultOptions };
208
+ const o = { ...DefaultOptions };
207
209
 
208
210
  for (let [key, value] of Object.entries(/**@type Object*/options))
209
211
  if (value !== undefined)
@@ -241,6 +243,7 @@ class SelectBox {
241
243
  labelProp: o.labelProp,
242
244
  valueProp: o.valueProp,
243
245
  multiItemLabelProp: o.multiItemLabelProp,
246
+ multiItemRemovePosition: o.multiItemRemovePosition,
244
247
 
245
248
  maxMultiItems: o.maxMultiItems,
246
249
  multiItemsRestLabelProvider: o.multiItemsRestLabelProvider,
@@ -1153,6 +1156,18 @@ class SelectBox {
1153
1156
  setMultiItemLabelProp(prop) {
1154
1157
  const p = this._p;
1155
1158
  p.multiItemLabelProp = prop;
1159
+ this._scheduleSync('render_items');
1160
+ return this;
1161
+ }
1162
+
1163
+ /**
1164
+ * @param {'before'|'after'|'none'} position
1165
+ * @returns {SelectBox}
1166
+ */
1167
+ setMultiItemRemovePosition(position) {
1168
+ const p = this._p;
1169
+ p.multiItemRemovePosition = position;
1170
+ this._scheduleSync('render_items');
1156
1171
  return this;
1157
1172
  }
1158
1173
 
@@ -2873,22 +2888,29 @@ class SelectBox {
2873
2888
  if (label === false)
2874
2889
  return null;
2875
2890
 
2891
+ const elRemove = createElement('span', {
2892
+ class: `${p.baseClassName}__item_remove`,
2893
+ role: 'presentation',
2894
+ });
2895
+
2876
2896
  const itemEl = createElement('li',
2877
2897
  {
2878
2898
  class: `${p.baseClassName}__item`,
2879
2899
  tabindex: '0',
2880
2900
  title: label,
2881
2901
  },
2882
- [
2883
- createElement('span', {
2884
- class: `${p.baseClassName}__item_remove`,
2885
- role: 'presentation',
2886
- }),
2887
- ],
2888
2902
  );
2889
2903
 
2904
+ if (p.multiItemRemovePosition === 'before') {
2905
+ itemEl.appendChild(elRemove);
2906
+ }
2907
+
2890
2908
  this._renderMultiItemContent(item, itemEl);
2891
2909
 
2910
+ if (p.multiItemRemovePosition === 'after') {
2911
+ itemEl.appendChild(elRemove);
2912
+ }
2913
+
2892
2914
  itemEl[ItemSymbol] = item;
2893
2915
 
2894
2916
  return itemEl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "2.0.26",
3
+ "version": "2.0.27",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",
@@ -375,16 +375,30 @@ $spinner-transition-duration: .15s;
375
375
  display: inline-block;
376
376
  font-weight: bold;
377
377
  margin-top: 0.2em;
378
- margin-right: var(--selectbox-multi-item-remove-spacing);
379
378
  font-size: 13px;
380
379
 
381
380
  &:before {
382
381
  content: '×';
383
382
  }
384
383
 
385
- @include insideRtlSelectBox {
384
+ &:first-child {
385
+ margin-right: var(--selectbox-multi-item-remove-spacing);
386
+ }
387
+
388
+ &:last-child {
386
389
  margin-left: var(--selectbox-multi-item-remove-spacing);
387
- margin-right: 0;
390
+ }
391
+
392
+ @include insideRtlSelectBox {
393
+ &:first-child {
394
+ margin-left: var(--selectbox-multi-item-remove-spacing);
395
+ margin-right: 0;
396
+ }
397
+
398
+ &:last-child {
399
+ margin-right: var(--selectbox-multi-item-remove-spacing);
400
+ margin-left: 0;
401
+ }
388
402
  }
389
403
  }
390
404
 
package/vue/DropList.vue CHANGED
@@ -19,136 +19,138 @@ const AllListEvents = [
19
19
  'subitems:select', 'subitems:blur',
20
20
  ];
21
21
 
22
+ export const PropTypes = {
23
+ baseClassName: {
24
+ type: String,
25
+ },
26
+ additionalClasses: {
27
+ type: [Object, Array, String],
28
+ },
29
+ direction: {
30
+ type: String,
31
+ default: undefined,
32
+ },
33
+ autoFocus: {
34
+ type: Boolean,
35
+ default: true,
36
+ },
37
+ autoItemBlur: {
38
+ type: Boolean,
39
+ default: true,
40
+ },
41
+ autoItemBlurDelay: {
42
+ type: Number,
43
+ default: 300,
44
+ },
45
+ capturesFocus: {
46
+ type: Boolean,
47
+ default: true,
48
+ },
49
+ multi: {
50
+ type: Boolean,
51
+ default: false,
52
+ },
53
+ isHeaderVisible: {
54
+ type: Boolean,
55
+ default: false,
56
+ },
57
+ searchable: {
58
+ type: Boolean,
59
+ default: false,
60
+ },
61
+ noResultsText: {
62
+ type: String,
63
+ default: 'No matching results',
64
+ },
65
+ filterThrottleWindow: {
66
+ type: Number,
67
+ default: 300,
68
+ },
69
+ filterOnEmptyTerm: {
70
+ type: Boolean,
71
+ default: false,
72
+ },
73
+ filterGroups: {
74
+ type: Boolean,
75
+ default: false,
76
+ },
77
+ filterEmptyGroups: {
78
+ type: Boolean,
79
+ default: false,
80
+ },
81
+ filterFn: {
82
+ type: Function,
83
+ default: undefined,
84
+ },
85
+ filterDependencies: {
86
+ type: [Array, String, Number, Boolean, Object],
87
+ default: undefined,
88
+ },
89
+ keyDownHandler: {
90
+ type: Function,
91
+ },
92
+ autoCheckGroupChildren: {
93
+ type: Boolean,
94
+ default: true,
95
+ },
96
+ useExactTargetWidth: {
97
+ type: Boolean,
98
+ default: false,
99
+ },
100
+ constrainToWindow: {
101
+ type: Boolean,
102
+ default: true,
103
+ },
104
+ autoFlipDirection: {
105
+ type: Boolean,
106
+ default: true,
107
+ },
108
+ estimatedItemHeight: {
109
+ type: Number,
110
+ default: 20,
111
+ },
112
+ estimateWidth: {
113
+ type: Boolean,
114
+ default: false,
115
+ },
116
+ virtualMinItems: {
117
+ type: Number,
118
+ default: 10,
119
+ },
120
+ labelProp: {
121
+ type: String,
122
+ default: 'label',
123
+ },
124
+ valueProp: {
125
+ type: String,
126
+ default: 'value',
127
+ },
128
+ items: {
129
+ type: Array,
130
+ default: () => [],
131
+ },
132
+ [isVue3 ? 'modelValue' : 'value']: { // Vue 2
133
+ type: [Number, String, Object, Array],
134
+ },
135
+ renderItem: {
136
+ type: Function,
137
+ },
138
+ unrenderItem: {
139
+ type: Function,
140
+ },
141
+ positionOptions: {
142
+ type: Object,
143
+ },
144
+ autoRelayoutOnItemsChange: {
145
+ type: Boolean,
146
+ default: true,
147
+ },
148
+ };
149
+
22
150
  export default {
23
151
  inheritAttrs: false,
24
152
 
25
- props: {
26
- baseClassName: {
27
- type: String,
28
- },
29
- additionalClasses: {
30
- type: [Object, Array, String],
31
- },
32
- direction: {
33
- type: String,
34
- default: undefined,
35
- },
36
- autoFocus: {
37
- type: Boolean,
38
- default: true,
39
- },
40
- autoItemBlur: {
41
- type: Boolean,
42
- default: true,
43
- },
44
- autoItemBlurDelay: {
45
- type: Number,
46
- default: 300,
47
- },
48
- capturesFocus: {
49
- type: Boolean,
50
- default: true,
51
- },
52
- multi: {
53
- type: Boolean,
54
- default: false,
55
- },
56
- isHeaderVisible: {
57
- type: Boolean,
58
- default: false,
59
- },
60
- searchable: {
61
- type: Boolean,
62
- default: false,
63
- },
64
- noResultsText: {
65
- type: String,
66
- default: 'No matching results',
67
- },
68
- filterThrottleWindow: {
69
- type: Number,
70
- default: 300,
71
- },
72
- filterOnEmptyTerm: {
73
- type: Boolean,
74
- default: false,
75
- },
76
- filterGroups: {
77
- type: Boolean,
78
- default: false,
79
- },
80
- filterEmptyGroups: {
81
- type: Boolean,
82
- default: false,
83
- },
84
- filterFn: {
85
- type: Function,
86
- default: undefined,
87
- },
88
- // eslint-disable-next-line vue/require-prop-types
89
- filterDependencies: {
90
- default: undefined,
91
- },
92
- keyDownHandler: {
93
- type: Function,
94
- },
95
- autoCheckGroupChildren: {
96
- type: Boolean,
97
- default: true,
98
- },
99
- useExactTargetWidth: {
100
- type: Boolean,
101
- default: false,
102
- },
103
- constrainToWindow: {
104
- type: Boolean,
105
- default: true,
106
- },
107
- autoFlipDirection: {
108
- type: Boolean,
109
- default: true,
110
- },
111
- estimatedItemHeight: {
112
- type: Number,
113
- default: 20,
114
- },
115
- estimateWidth: {
116
- type: Boolean,
117
- default: false,
118
- },
119
- virtualMinItems: {
120
- type: Number,
121
- default: 10,
122
- },
123
- labelProp: {
124
- type: String,
125
- default: 'label',
126
- },
127
- valueProp: {
128
- type: String,
129
- default: 'value',
130
- },
131
- items: {
132
- type: Array,
133
- default: () => [],
134
- },
135
- [isVue3 ? 'modelValue' : 'value']: { // Vue 2
136
- type: [Number, String, Object, Array],
137
- },
138
- renderItem: {
139
- type: Function,
140
- },
141
- unrenderItem: {
142
- type: Function,
143
- },
144
- positionOptions: {
145
- type: Object,
146
- },
147
- autoRelayoutOnItemsChange: {
148
- type: Boolean,
149
- default: true,
150
- },
151
- },
153
+ props: PropTypes,
152
154
 
153
155
  emits: [
154
156
  // vue events