wave-ui 3.2.0 → 3.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.
- package/dist/wave-ui.cjs.js +1 -1
- package/dist/wave-ui.css +1 -1
- package/dist/wave-ui.es.js +107 -69
- package/dist/wave-ui.umd.js +1 -1
- package/package.json +1 -1
- package/src/wave-ui/components/w-tree.vue +75 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wave-ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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",
|
|
@@ -6,11 +6,11 @@ ul.w-tree(:class="classes")
|
|
|
6
6
|
:class="itemClasses(item)")
|
|
7
7
|
//- The keys `route` & `disabled` are always present in any currentDepthItems.
|
|
8
8
|
component.w-tree__item-label(
|
|
9
|
-
:is="
|
|
9
|
+
:is="getTreeItemComponent(item)"
|
|
10
10
|
v-bind="item.route && { [!$router || hasExternalLink(item) ? 'href' : 'to']: item.route }"
|
|
11
11
|
@click="!disabled && !item.disabled && onLabelClick(item, $event)"
|
|
12
12
|
@keydown="!disabled && !item.disabled && onLabelKeydown(item, $event)"
|
|
13
|
-
:tabindex="
|
|
13
|
+
:tabindex="getTreeItemTabindex(item)")
|
|
14
14
|
//- @click.stop to not follow link if item is a link.
|
|
15
15
|
w-button.w-tree__item-expand(
|
|
16
16
|
v-if="(item.children || item.branch) && ((expandOpenIcon && item.open) || expandIcon) && !(unexpandableEmpty && !item.children)"
|
|
@@ -22,7 +22,12 @@ ul.w-tree(:class="classes")
|
|
|
22
22
|
:disabled="disabled || item.disabled"
|
|
23
23
|
text
|
|
24
24
|
sm)
|
|
25
|
-
slot(
|
|
25
|
+
slot(
|
|
26
|
+
name="item"
|
|
27
|
+
:item="item.originalItem"
|
|
28
|
+
:depth="depth"
|
|
29
|
+
:path="item.path"
|
|
30
|
+
:open="item.open")
|
|
26
31
|
w-icon(v-if="itemIcon(item)" class="w-tree__item-icon" :color="item.originalItem[itemIconColorKey] || iconColor") {{ itemIcon(item) }}
|
|
27
32
|
span(v-html="item.label")
|
|
28
33
|
span.ml1(v-if="counts && (item.children || item.branch)").
|
|
@@ -30,13 +35,14 @@ ul.w-tree(:class="classes")
|
|
|
30
35
|
component(
|
|
31
36
|
:is="noTransition ? 'div' : 'w-transition-expand'"
|
|
32
37
|
:y="!noTransition || null"
|
|
33
|
-
@after-enter="$emit('open', { item: item.originalItem, open: item.open, depth })"
|
|
34
|
-
@after-leave="$emit('close', { item: item.originalItem, open: item.open, depth })")
|
|
38
|
+
@after-enter="$emit('open', { item: item.originalItem, open: item.open, depth, path: getTreeItemPathForOutput(item) })"
|
|
39
|
+
@after-leave="$emit('close', { item: item.originalItem, open: item.open, depth, path: getTreeItemPathForOutput(item) })")
|
|
35
40
|
w-tree(
|
|
36
41
|
v-if="item.children && item.open"
|
|
37
42
|
v-bind="$props"
|
|
38
43
|
:depth="depth + 1"
|
|
39
44
|
:data="item.originalItem.children"
|
|
45
|
+
:parent="item"
|
|
40
46
|
@before-open="$emit('before-open', $event)"
|
|
41
47
|
@open="$emit('open', $event)"
|
|
42
48
|
@before-close="$emit('before-close', $event)"
|
|
@@ -44,8 +50,8 @@ ul.w-tree(:class="classes")
|
|
|
44
50
|
@click="$emit('click', $event)"
|
|
45
51
|
@select="$emit('select', $event)"
|
|
46
52
|
@update:model-value="$emit('update:model-value', $event)")
|
|
47
|
-
template(#item="{ item, depth, open }")
|
|
48
|
-
slot(name="item" :item="item" :depth="depth" :open="open")
|
|
53
|
+
template(#item="{ item, depth, path, open }")
|
|
54
|
+
slot(name="item" :item="item" :depth="depth" :path="path" :open="open")
|
|
49
55
|
</template>
|
|
50
56
|
|
|
51
57
|
<script>
|
|
@@ -60,7 +66,8 @@ export default {
|
|
|
60
66
|
props: {
|
|
61
67
|
modelValue: { type: [Object, Array] },
|
|
62
68
|
data: { type: [Object, Array], required: true },
|
|
63
|
-
depth: { type: Number, default: 0 },
|
|
69
|
+
depth: { type: Number, default: 0 }, // To get the context from nested items.
|
|
70
|
+
parent: { type: Object, default: null }, // To get the context from nested items.
|
|
64
71
|
branchClass: { type: String },
|
|
65
72
|
leafClass: { type: String },
|
|
66
73
|
branchIcon: { type: String },
|
|
@@ -115,7 +122,7 @@ export default {
|
|
|
115
122
|
if (!Array.isArray(items)) items = [items]
|
|
116
123
|
|
|
117
124
|
items.forEach((item, i) => {
|
|
118
|
-
|
|
125
|
+
const itemWrapper = {
|
|
119
126
|
originalItem: item, // Store the original item to return it on event emits.
|
|
120
127
|
_uid: this.depth.toString() + (i + 1),
|
|
121
128
|
label: item[this.itemLabelKey],
|
|
@@ -124,11 +131,48 @@ export default {
|
|
|
124
131
|
route: item[this.itemRouteKey],
|
|
125
132
|
disabled: item[this.itemDisabledKey],
|
|
126
133
|
depth: this.depth,
|
|
127
|
-
open: !!(oldItems[i]?.open || this.expandAll || item[this.itemOpenKey])
|
|
128
|
-
|
|
134
|
+
open: !!(oldItems[i]?.open || this.expandAll || item[this.itemOpenKey]),
|
|
135
|
+
parent: this.parent || null,
|
|
136
|
+
path: [] // Ancestors path from root to leaf including self.
|
|
137
|
+
}
|
|
138
|
+
itemWrapper.path = this.getTreeItemPath(itemWrapper)
|
|
139
|
+
this.currentDepthItems.push(itemWrapper)
|
|
129
140
|
})
|
|
130
141
|
},
|
|
131
142
|
|
|
143
|
+
getTreeItemComponent (item) {
|
|
144
|
+
return !this.disabled && !item.disabled && item.route ? (!this.$router || this.hasExternalLink(item) ? 'a' : 'router-link') : 'div'
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
getTreeItemTabindex (item) {
|
|
148
|
+
return !this.disabled && !item.disabled && (item.children || item.branch || this.selectable) && !(this.unexpandableEmpty && !item.children) ? 0 : null
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get the tree path of the given item.
|
|
153
|
+
* The full ancestors items are stored in the array and not only their `originalItem`s in case
|
|
154
|
+
* it is mutated before we return it to the user through slots and emitted events.
|
|
155
|
+
* Before it is returned to the user, this array is mapped to only give the `originalItem`s.
|
|
156
|
+
*
|
|
157
|
+
* @param {Object} item the tree item to get the ancestors path for.
|
|
158
|
+
* @return an array of item objects from the root to the leaf (including the item itself).
|
|
159
|
+
*/
|
|
160
|
+
getTreeItemPath (item) {
|
|
161
|
+
const ancestorsPath = [item]
|
|
162
|
+
|
|
163
|
+
let ancestor = item.parent
|
|
164
|
+
while (ancestor) {
|
|
165
|
+
ancestorsPath.push(ancestor)
|
|
166
|
+
ancestor = ancestor.parent
|
|
167
|
+
}
|
|
168
|
+
ancestorsPath.reverse()
|
|
169
|
+
return ancestorsPath
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
getTreeItemPathForOutput (item) {
|
|
173
|
+
return item.path.map(item => item.originalItem)
|
|
174
|
+
},
|
|
175
|
+
|
|
132
176
|
/**
|
|
133
177
|
* Expand/collapse the given tree item when possible (not disabled, has children).
|
|
134
178
|
*
|
|
@@ -139,7 +183,12 @@ export default {
|
|
|
139
183
|
if (typeof open === 'boolean') item.open = open
|
|
140
184
|
else item.open = !item.open
|
|
141
185
|
|
|
142
|
-
const emitParams = {
|
|
186
|
+
const emitParams = {
|
|
187
|
+
item: item.originalItem,
|
|
188
|
+
open: item.open,
|
|
189
|
+
depth: this.depth,
|
|
190
|
+
path: this.getTreeItemPathForOutput(item)
|
|
191
|
+
}
|
|
143
192
|
|
|
144
193
|
this.$emit(item.open ? 'before-open' : 'before-close', emitParams)
|
|
145
194
|
|
|
@@ -154,14 +203,24 @@ export default {
|
|
|
154
203
|
const route = item[this.itemRouteKey]
|
|
155
204
|
if (route && this.$router && !this.hasExternalLink(item)) e.preventDefault()
|
|
156
205
|
|
|
157
|
-
this.$emit('click', {
|
|
206
|
+
this.$emit('click', {
|
|
207
|
+
item: item.originalItem,
|
|
208
|
+
depth: this.depth,
|
|
209
|
+
path: this.getTreeItemPathForOutput(item),
|
|
210
|
+
e
|
|
211
|
+
})
|
|
158
212
|
if (item.children || (item.branch && !this.unexpandableEmpty)) this.expandDepth(item)
|
|
159
213
|
|
|
160
214
|
if (this.selectable) this.emitItemSelection(item, e)
|
|
161
215
|
},
|
|
162
216
|
|
|
163
217
|
emitItemSelection (item, e) {
|
|
164
|
-
const emitParams = {
|
|
218
|
+
const emitParams = {
|
|
219
|
+
item: item.originalItem,
|
|
220
|
+
depth: this.depth,
|
|
221
|
+
path: this.getTreeItemPathForOutput(item),
|
|
222
|
+
e
|
|
223
|
+
}
|
|
165
224
|
if (item.children || (item.branch && !this.unexpandableEmpty)) {
|
|
166
225
|
emitParams.open = item.open
|
|
167
226
|
}
|
|
@@ -299,8 +358,8 @@ $expand-icon-size: 20px;
|
|
|
299
358
|
right: - $base-increment - 2px;
|
|
300
359
|
border-radius: $border-radius;
|
|
301
360
|
}
|
|
302
|
-
&:hover:before {background-color:
|
|
303
|
-
&:focus:before {background-color:
|
|
361
|
+
&:hover:before {background-color: $primary;opacity: 0.1;}
|
|
362
|
+
&:focus:before {background-color: $primary;opacity: 0.2;}
|
|
304
363
|
}
|
|
305
364
|
&__item--leaf &__item-label:before {
|
|
306
365
|
left: - $base-increment;
|