wave-ui 3.8.1 → 3.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wave-ui",
3
- "version": "3.8.1",
3
+ "version": "3.9.0",
4
4
  "description": "An emerging UI framework for Vue.js (2 & 3) with only the bright side. :sunny:",
5
5
  "author": "Antoni Andre <antoniandre.web@gmail.com>",
6
6
  "homepage": "https://antoniandre.github.io/wave-ui",
@@ -213,10 +213,7 @@ export default {
213
213
  &:before {
214
214
  content: '';
215
215
  position: absolute;
216
- top: 0;
217
- left: 0;
218
- right: 0;
219
- bottom: 0;
216
+ inset: 0;
220
217
  background-color: currentColor;
221
218
  opacity: 0;
222
219
  transition: $fast-transition-duration;
@@ -162,10 +162,7 @@ export default {
162
162
  // ------------------------------------------------------
163
163
  &:before, &:after {
164
164
  position: absolute;
165
- top: 0;
166
- bottom: 0;
167
- left: 0;
168
- right: 0;
165
+ inset: 0;
169
166
  background-color: currentColor;
170
167
  pointer-events: none;
171
168
  }
@@ -2,26 +2,41 @@
2
2
  .w-autocomplete(:class="classes" @click="onClick")
3
3
  template(v-if="selection.length")
4
4
  .w-autocomplete__selection(v-for="(item, i) in selection")
5
- span(v-html="item[itemLabelKey]")
6
- w-button(@click.stop="unselectItem(i)" icon="wi-cross" xs text)
7
- .w-autocomplete__placeholder(v-if="!selection.length && !keywords && placeholder" v-html="placeholder")
5
+ slot(name="selection" :item="item" :unselect="i => unselectItem(i)")
6
+ span(v-html="item[itemLabelKey]")
7
+ w-button(@click.stop="unselectItem(i)" icon="wi-cross" xs text color="currentColor")
8
+ .w-autocomplete__placeholder(
9
+ v-if="!selection.length && !keywords && placeholder"
10
+ v-html="placeholder")
8
11
  input.w-autocomplete__input(
9
12
  ref="input"
10
- :model-value="keywords"
13
+ :value="keywords"
11
14
  v-on="inputEventListeners")
12
- w-transition-slide-fade(y)
13
- ul.w-autocomplete__menu(v-if="menuOpen" ref="menu")
15
+ w-transition-slide-fade
16
+ ul.w-autocomplete__menu(
17
+ v-if="menuOpen"
18
+ ref="menu"
19
+ @mousedown="menuIsBeingClicked = true"
20
+ @mouseup="setEndOfMenuClick"
21
+ @touchstart="menuIsBeingClicked = true"
22
+ @touchend="setEndOfMenuClick")
14
23
  li(
15
24
  v-for="(item, i) in filteredItems"
16
25
  :key="i"
17
- @click.stop="selectItem(item)"
26
+ @click.stop="selectItem(item), $emit('item-click', item)"
18
27
  :class="{ highlighted: highlightedItem === item.uid }")
19
- span(v-html="item[itemLabelKey]")
28
+ slot(name="item" :item="item" :highlighted="highlightedItem === item.uid")
29
+ span(v-html="item[itemLabelKey]")
20
30
  li.w-autocomplete__no-match(
21
31
  v-if="!filteredItems.length"
22
32
  :class="{ 'w-autocomplete__no-match--default': !$slots.noMatch }")
23
33
  slot(name="no-match")
24
34
  .caption(v-html="noMatch ?? 'No match.'")
35
+ li.w-autocomplete__extra-item(
36
+ v-if="$slots['extra-item']"
37
+ @click="selectExtraItem"
38
+ :class="{ highlighted: highlightedItem === 'extra-item' }")
39
+ slot(name="extra-item")
25
40
  </template>
26
41
 
27
42
  <script>
@@ -47,13 +62,17 @@ export default {
47
62
  itemSearchableKey: { type: String, default: 'searchable' }
48
63
  },
49
64
 
50
- emits: ['input'],
65
+ // item-select is also from keyboard, 'item-click' may be useful for mouseenter mouseleave events.
66
+ emits: ['update:modelValue', 'input', 'focus', 'blur', 'keydown', 'item-click', 'item-select', 'extra-item-select'],
51
67
 
52
68
  data: () => ({
53
69
  keywords: '',
54
70
  selection: [],
55
71
  menuOpen: false,
56
- highlightedItem: null
72
+ highlightedItem: null,
73
+ // The focus-blur events occur more times than it should emit to the outside due to the menu
74
+ // item clicking. So keep the focus on as long as the user is interacting with the autocomplete.
75
+ menuIsBeingClicked: false
57
76
  }),
58
77
 
59
78
  computed: {
@@ -97,6 +116,7 @@ export default {
97
116
 
98
117
  highlightedItemIndex () {
99
118
  if (this.highlightedItem === null) return -1
119
+ else if (this.highlightedItem === 'extra-item') return this.filteredItems.length
100
120
  return this.filteredItems.findIndex(item => item.uid === this.highlightedItem)
101
121
  },
102
122
 
@@ -105,10 +125,19 @@ export default {
105
125
  ...this.$attrs,
106
126
  input: e => {
107
127
  this.keywords = e.target.value
108
- if (typeof this.$attrs.input === 'function') this.$attrs.input(this.keywords)
109
128
  },
110
- focus: this.onFocus,
111
- keydown: this.onKeydown,
129
+ focus: e => {
130
+ if (this.menuIsBeingClicked) return
131
+ this.onFocus(e)
132
+ this.$emit('focus', e)
133
+ },
134
+ blur: e => {
135
+ if (!this.menuIsBeingClicked) this.$emit('blur', e)
136
+ },
137
+ keydown: e => {
138
+ this.onKeydown(e)
139
+ this.$emit('keydown', e)
140
+ },
112
141
  drop: this.onDrop,
113
142
  compositionstart: this.onCompositionStart,
114
143
  compositionupdate: this.onCompositionUpdate
@@ -137,7 +166,11 @@ export default {
137
166
  this.selection.push(item)
138
167
  this.highlightedItem = item.uid
139
168
  this.keywords = ''
140
- this.$emit('input', this.multiple ? this.selection.map(item => item[this.itemValueKey]) : item[this.itemValueKey])
169
+ const emitPayload = this.multiple ? this.selection.map(item => item[this.itemValueKey]) : item[this.itemValueKey]
170
+ // Unlike input, item-select is only emitted when selecting (not unselecting).
171
+ this.$emit('item-select', item)
172
+ this.$emit('update:modelValue', emitPayload)
173
+ this.$emit('input', emitPayload)
141
174
  this.$refs.input.focus()
142
175
  if (!this.multiple) this.closeMenu()
143
176
  },
@@ -145,10 +178,21 @@ export default {
145
178
  unselectItem (i) {
146
179
  this.selection.splice(i ?? this.selection.length - 1, 1)
147
180
  this.highlightedItem = null
181
+ this.$emit('update:modelValue', null)
148
182
  this.$emit('input', null)
149
183
  this.$refs.input.focus()
150
184
  },
151
185
 
186
+ selectExtraItem () {
187
+ this.keywords = ''
188
+ this.$emit('extra-item-select')
189
+ this.closeMenu()
190
+ },
191
+
192
+ setEndOfMenuClick () {
193
+ setTimeout(() => (this.menuIsBeingClicked = false), 100)
194
+ },
195
+
152
196
  onClick () {
153
197
  if (!this.openOnKeydown) this.openMenu()
154
198
  this.$refs.input.focus()
@@ -166,7 +210,7 @@ export default {
166
210
  // },
167
211
 
168
212
  onKeydown (e) {
169
- const itemsCount = this.filteredItems.length
213
+ const itemsCount = this.filteredItems.length + (this.$slots['extra-item'] ? 1 : 0)
170
214
  // `e.key.length === 1`: is all the keyboard keys that generate a character.
171
215
  if (!this.openOnKeydown || ((this.keywords || e.key.length === 1) && !this.menuOpen)) this.openMenu()
172
216
 
@@ -181,7 +225,8 @@ export default {
181
225
  // Enter key.
182
226
  else if (e.keyCode === 13) {
183
227
  e.preventDefault() // Prevent form submissions.
184
- if (this.highlightedItemIndex >= 0) this.selectItem(this.filteredItems[this.highlightedItemIndex])
228
+ if (this.highlightedItem === 'extra-item') this.selectExtraItem()
229
+ else if (this.highlightedItemIndex >= 0) this.selectItem(this.filteredItems[this.highlightedItemIndex])
185
230
  }
186
231
 
187
232
  // Up & down arrow keys.
@@ -191,16 +236,20 @@ export default {
191
236
  if (index === -1) index = e.keyCode === 38 ? itemsCount - 1 : 0
192
237
  else index = (index + (e.keyCode === 38 ? -1 : 1) + itemsCount) % itemsCount // Never out of range.
193
238
 
194
- this.highlightedItem = this.filteredItems[index]?.uid || 0
239
+ if (this.$slots['extra-item'] && index === itemsCount - 1) this.highlightedItem = 'extra-item'
240
+ else this.highlightedItem = this.filteredItems[index]?.uid || 0
195
241
 
196
242
  // Scroll the container if highlighted item is not in view.
197
243
  const menuEl = this.$refs.menu
198
244
  if (menuEl) {
199
- const { offsetHeight: itemElHeight, offsetTop: itemElTop } = menuEl.childNodes[index] || {}
200
- if (menuEl.scrollTop + menuEl.offsetHeight - itemElHeight < itemElTop) {
201
- menuEl.scrollTop = itemElTop - menuEl.offsetHeight + itemElHeight
245
+ if (this.$slots['extra-item'] && index === itemsCount - 1) menuEl.scrollTop = menuEl.scrollHeight
246
+ else {
247
+ const { offsetHeight: itemElHeight, offsetTop: itemElTop } = menuEl.childNodes[index] || {}
248
+ if (menuEl.scrollTop + menuEl.offsetHeight - itemElHeight < itemElTop) {
249
+ menuEl.scrollTop = itemElTop - menuEl.offsetHeight + itemElHeight
250
+ }
251
+ else if (menuEl.scrollTop > itemElTop) menuEl.scrollTop = itemElTop
202
252
  }
203
- else if (menuEl.scrollTop > itemElTop) menuEl.scrollTop = itemElTop
204
253
  }
205
254
  }
206
255
 
@@ -249,6 +298,18 @@ export default {
249
298
 
250
299
  beforeUnmount () {
251
300
  document.removeEventListener('click', this.onDocumentClick)
301
+ },
302
+
303
+ watch: {
304
+ modelValue (value) {
305
+ this.selection = []
306
+ if (value) {
307
+ const arrayOfValues = Array.isArray(value) ? value : [value]
308
+ arrayOfValues.forEach(value => {
309
+ this.selection.push(this.optimizedItemsForSearch.find(item => item[this.itemValueKey] === +value))
310
+ })
311
+ }
312
+ }
252
313
  }
253
314
  }
254
315
  </script>
@@ -259,7 +320,7 @@ export default {
259
320
  flex-wrap: wrap;
260
321
  gap: 4px;
261
322
  position: relative;
262
- border-radius: 4px;
323
+ border-radius: $border-radius;
263
324
  border: $border;
264
325
  padding: 2px 4px;
265
326
  user-select: none;
@@ -274,7 +335,7 @@ export default {
274
335
  align-items: center;
275
336
  background: rgba(var(--w-contrast-bg-color-rgb), 0.035);
276
337
  border: 1px solid rgba(var(--w-contrast-bg-color-rgb), 0.05);
277
- border-radius: 4px;
338
+ border-radius: $border-radius;
278
339
  padding: 0 2px 0 4px;
279
340
  flex-shrink: 0;
280
341
 
@@ -306,8 +367,8 @@ export default {
306
367
  background-color: $base-bg-color;
307
368
  border: 1px solid rgba(var(--w-contrast-bg-color-rgb), 0.2);
308
369
  border-top: none;
309
- border-bottom-left-radius: inherit;
310
- border-bottom-right-radius: inherit;
370
+ border-bottom-left-radius: $border-radius;
371
+ border-bottom-right-radius: $border-radius;
311
372
  overflow: auto;
312
373
  z-index: 10;
313
374
 
@@ -236,10 +236,7 @@ $spinner-size: 40;
236
236
  &:before {
237
237
  content: '';
238
238
  position: absolute;
239
- top: 0;
240
- left: 0;
241
- right: 0;
242
- bottom: 0;
239
+ inset: 0;
243
240
  opacity: 0;
244
241
  background-color: #000;
245
242
  border-radius: inherit;
@@ -302,10 +299,7 @@ $spinner-size: 40;
302
299
 
303
300
  &__loader {
304
301
  position: absolute;
305
- top: 0;
306
- bottom: 0;
307
- left: 0;
308
- right: 0;
302
+ inset: 0;
309
303
  display: flex;
310
304
  align-items: center;
311
305
  justify-content: center;
@@ -204,10 +204,7 @@ export default {
204
204
 
205
205
  &--absolute {
206
206
  position: absolute;
207
- top: 0;
208
- left: 0;
209
- bottom: 0;
210
- right: 0;
207
+ inset: 0;
211
208
  overflow: hidden;
212
209
  }
213
210
 
@@ -223,10 +220,7 @@ export default {
223
220
 
224
221
  .w-overlay {
225
222
  position: absolute;
226
- top: 0;
227
- bottom: 0;
228
- left: 0;
229
- right: 0;
223
+ inset: 0;
230
224
  z-index: 2;
231
225
  }
232
226
  .w-drawer {position: absolute;}
@@ -196,19 +196,13 @@ export default {
196
196
  background-repeat: no-repeat;
197
197
  background-size: cover;
198
198
  position: absolute;
199
- top: 0;
200
- left: 0;
201
- right: 0;
202
- bottom: 0;
199
+ inset: 0;
203
200
 
204
201
  &--contain {background-size: contain;}
205
202
 
206
203
  &__loader, &__content {
207
204
  position: absolute;
208
- top: 0;
209
- left: 0;
210
- right: 0;
211
- bottom: 0;
205
+ inset: 0;
212
206
  display: flex;
213
207
  justify-content: center;
214
208
  align-items: center;
@@ -449,10 +449,7 @@ export default {
449
449
  &:before {
450
450
  content: '';
451
451
  position: absolute;
452
- top: 0;
453
- left: 0;
454
- bottom: 0;
455
- right: 0;
452
+ inset: 0;
456
453
  background-color: currentColor;
457
454
  opacity: 0;
458
455
  transition: 0.2s;
@@ -50,9 +50,7 @@ export default {
50
50
  <style lang="scss">
51
51
  .w-notification-manager {
52
52
  position: fixed;
53
- top: 0;
54
- bottom: 0;
55
- right: 0;
53
+ inset: 0 0 0 auto;
56
54
  z-index: 1000;
57
55
  pointer-events: none;
58
56
  width: 280px;
@@ -154,10 +154,7 @@ $circle-size: 40;
154
154
  &.w-progress--default-bg:after {
155
155
  content: '';
156
156
  position: absolute;
157
- top: 0;
158
- bottom: 0;
159
- left: 0;
160
- right: 0;
157
+ inset: 0;
161
158
  border-radius: inherit;
162
159
  background-color: currentColor;
163
160
  opacity: 0.15;
@@ -188,10 +185,7 @@ $circle-size: 40;
188
185
  &:before, &:after {
189
186
  content: '';
190
187
  position: absolute;
191
- top: 0;
192
- bottom: 0;
193
- left: 0;
194
- right: -5%;
188
+ inset: 0 -5% 0 0;
195
189
  background: currentColor;
196
190
  z-index: 1;
197
191
  will-change: transform;
@@ -238,10 +238,7 @@ export default {
238
238
  &__button:after {
239
239
  content: "";
240
240
  position: absolute;
241
- top: 0;
242
- left: 0;
243
- right: 0;
244
- bottom: 0;
241
+ inset: 0;
245
242
  background-color: currentColor;
246
243
  border-radius: 100%;
247
244
  transform: translateX(100%) scale(0);
@@ -395,10 +395,7 @@ export default {
395
395
  }
396
396
  // Colored border on thumb when hover and active - but with a transparency.
397
397
  &:before {
398
- left: 0;
399
- right: 0;
400
- top: 0;
401
- bottom: 0;
398
+ inset: 0;
402
399
  opacity: 0.5;
403
400
  border: 1px solid currentColor;
404
401
  }
@@ -764,10 +764,7 @@ $tr-border-top: 1px;
764
764
  &:before {
765
765
  content: '';
766
766
  position: absolute;
767
- top: 0;
768
- left: 0;
769
- right: 0;
770
- bottom: 0;
767
+ inset: 0;
771
768
  z-index: -1;
772
769
  background-color: $base-bg-color;
773
770
  }
@@ -848,10 +845,7 @@ $tr-border-top: 1px;
848
845
  &__row--selected td:before {
849
846
  content: '';
850
847
  position: absolute;
851
- top: 0;
852
- left: 0;
853
- right: 0;
854
- bottom: 0;
848
+ inset: 0;
855
849
  background-color: var(--w-primary-color);
856
850
  opacity: 0.2;
857
851
  pointer-events: none;
@@ -403,10 +403,7 @@ export default {
403
403
  &:before {
404
404
  content: '';
405
405
  position: absolute;
406
- top: 0;
407
- left: 0;
408
- right: 0;
409
- bottom: 0;
406
+ inset: 0;
410
407
  background-color: currentColor;
411
408
  opacity: 0;
412
409
  transition: $fast-transition-duration;
@@ -162,10 +162,7 @@ export default {
162
162
  &:before {
163
163
  content: '';
164
164
  position: absolute;
165
- top: 0;
166
- left: 0;
167
- right: 0;
168
- bottom: 0;
165
+ inset: 0;
169
166
  opacity: 0;
170
167
  background-color: transparent;
171
168
  // As this overlay is a smaller rectangle, the radius must be smaller to cover perfectly.
@@ -42,7 +42,7 @@ a {text-decoration: none;}
42
42
  position: relative; // Make the .w-app a referential for tooltips / menus.
43
43
  display: flex;
44
44
  flex-direction: column;
45
- min-height: 100vh;
45
+ min-height: 100dvh;
46
46
 
47
47
  &, *, :before, :after {box-sizing: border-box;}
48
48
 
@@ -47,7 +47,7 @@ $use-layout-classes: true !default;
47
47
  $base-font-size: 14px !default; // Must be a px unit.
48
48
  $base-increment: round(divide($base-font-size, 4)) !default;
49
49
  $layout-padding: $base-increment * 4 !default; // Applied on the .content-wrap tag.
50
- $border-radius: 3px !default;
50
+ $border-radius: 4px !default;
51
51
  $border-color: rgba(var(--w-contrast-bg-color-rgb), 0.12) !default;
52
52
  $border: 1px solid $border-color !default;
53
53
  $transition-duration: 0.25s !default;