druxt-menu 0.16.0 → 0.16.3
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.
|
@@ -7,11 +7,7 @@
|
|
|
7
7
|
export default {
|
|
8
8
|
name: 'DruxtMenuItem',
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Vue.js Properties.
|
|
12
|
-
*
|
|
13
|
-
* @see {@link https://vuejs.org/v2/guide/components-props.html}
|
|
14
|
-
*/
|
|
10
|
+
/** */
|
|
15
11
|
props: {
|
|
16
12
|
/**
|
|
17
13
|
* The menu item.
|
|
@@ -25,63 +21,37 @@ export default {
|
|
|
25
21
|
}
|
|
26
22
|
},
|
|
27
23
|
|
|
28
|
-
/**
|
|
29
|
-
* Vue.js Computed properties.
|
|
30
|
-
*/
|
|
24
|
+
/** */
|
|
31
25
|
computed: {
|
|
32
26
|
/**
|
|
33
27
|
* Current items Active state.
|
|
34
28
|
*
|
|
35
29
|
* @type {boolean}
|
|
36
30
|
*/
|
|
37
|
-
active()
|
|
38
|
-
return this.menu.trail.includes(this.item.entity.attributes.url)
|
|
39
|
-
},
|
|
31
|
+
active: ({ item, menu }) => menu.trail.includes(item.entity.attributes.url),
|
|
40
32
|
|
|
41
33
|
/**
|
|
42
34
|
* Class(es) for the menu item.
|
|
43
35
|
*
|
|
44
36
|
* @type {string}
|
|
45
37
|
*/
|
|
46
|
-
classes() {
|
|
47
|
-
const classes = [
|
|
38
|
+
classes: ({ active, menu, template }) => {
|
|
39
|
+
const classes = [menu[`${template}Class`]]
|
|
48
40
|
|
|
49
|
-
if (
|
|
41
|
+
if (active) classes.push('active-trail')
|
|
50
42
|
|
|
51
43
|
return classes.join(' ')
|
|
52
44
|
},
|
|
53
45
|
|
|
54
|
-
/**
|
|
55
|
-
* The menu item template type.
|
|
56
|
-
*
|
|
57
|
-
* @type {string}
|
|
58
|
-
*/
|
|
59
|
-
template() {
|
|
60
|
-
return this.item.children.length ? 'parent' : 'item'
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The `to` attribute for the menu item.
|
|
65
|
-
*
|
|
66
|
-
* @type {object}
|
|
67
|
-
*/
|
|
68
|
-
to() {
|
|
69
|
-
const parts = this.item.entity.attributes.link.uri.split(':')
|
|
70
|
-
const type = parts[0]
|
|
71
|
-
const path = parts[1]
|
|
72
|
-
|
|
73
|
-
return { path, type }
|
|
74
|
-
},
|
|
75
|
-
|
|
76
46
|
/**
|
|
77
47
|
* The parent DruxtMenu component, if present.
|
|
78
48
|
*
|
|
79
49
|
* @type {@object}
|
|
80
50
|
*/
|
|
81
|
-
menu() {
|
|
51
|
+
menu: ({ $parent }) => {
|
|
82
52
|
let menu = false
|
|
83
53
|
|
|
84
|
-
let item =
|
|
54
|
+
let item = $parent
|
|
85
55
|
while (item && !menu) {
|
|
86
56
|
if (item.$options.name === 'DruxtMenu') menu = item
|
|
87
57
|
if (item.$options.extends && item.$options.extends.name === 'DruxtMenu') menu = item
|
|
@@ -90,22 +60,58 @@ export default {
|
|
|
90
60
|
}
|
|
91
61
|
|
|
92
62
|
return menu
|
|
93
|
-
}
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The menu item template type.
|
|
67
|
+
*
|
|
68
|
+
* @type {string}
|
|
69
|
+
*/
|
|
70
|
+
template: ({ item }) => (item.children || []).length ? 'parent' : 'item',
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The `to` attribute for the menu item.
|
|
74
|
+
*
|
|
75
|
+
* @type {object}
|
|
76
|
+
*/
|
|
77
|
+
to: ({ item }) =>
|
|
78
|
+
((item.entity.attributes.link || {}).uri || '').startsWith('internal:')
|
|
79
|
+
&& (!item.entity.attributes.route || item.entity.attributes.route.name)
|
|
80
|
+
? { path: item.entity.attributes.link.uri.split(':')[1] }
|
|
81
|
+
: false
|
|
94
82
|
},
|
|
95
83
|
|
|
96
84
|
methods: {
|
|
85
|
+
/**
|
|
86
|
+
* Returns a menu link components.
|
|
87
|
+
*/
|
|
88
|
+
getLink(h, entity = {}) {
|
|
89
|
+
if (!entity.attributes) return false
|
|
90
|
+
|
|
91
|
+
// Render external links.
|
|
92
|
+
if (!this.to) {
|
|
93
|
+
return h('a',
|
|
94
|
+
{ domProps: { href: entity.attributes.url || (entity.attributes.link || {}).uri }},
|
|
95
|
+
entity.attributes.title
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Render internal links.
|
|
100
|
+
return h('nuxt-link',
|
|
101
|
+
{ props: { to: this.to } },
|
|
102
|
+
entity.attributes.title
|
|
103
|
+
)
|
|
104
|
+
},
|
|
105
|
+
|
|
97
106
|
/**
|
|
98
107
|
* The menu item template functions.
|
|
99
108
|
*/
|
|
100
|
-
templates
|
|
109
|
+
templates(h) {
|
|
101
110
|
return {
|
|
102
111
|
// Default template for Item slot.
|
|
103
|
-
item: ({ item: { entity } }) =>
|
|
104
|
-
this.menu.itemComponent,
|
|
112
|
+
item: ({ item: { entity } }) => h(this.menu.itemComponent,
|
|
105
113
|
{ class: this.classes },
|
|
106
|
-
[
|
|
107
|
-
createElement('nuxt-link', { props: { to: this.to } }, entity.attributes.title)
|
|
108
|
-
]
|
|
114
|
+
[this.getLink(h, entity)]
|
|
109
115
|
),
|
|
110
116
|
|
|
111
117
|
// Default template for Parent slot.
|
|
@@ -113,14 +119,17 @@ export default {
|
|
|
113
119
|
const childElements = []
|
|
114
120
|
|
|
115
121
|
for (const key in children) {
|
|
116
|
-
childElements.push(
|
|
122
|
+
childElements.push(h('druxt-menu-item', { props: { item: children[key] }}))
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
return
|
|
125
|
+
return h(this.menu.parentComponent,
|
|
120
126
|
{ class: this.classes },
|
|
121
127
|
[
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
this.getLink(h, entity),
|
|
129
|
+
h(this.menu.parentWrapperComponent,
|
|
130
|
+
{ class: this.menu.parenWrapperClass },
|
|
131
|
+
childElements
|
|
132
|
+
)
|
|
124
133
|
]
|
|
125
134
|
)
|
|
126
135
|
},
|
|
@@ -133,9 +142,9 @@ export default {
|
|
|
133
142
|
/**
|
|
134
143
|
* The Vue.js render function.
|
|
135
144
|
*/
|
|
136
|
-
render
|
|
145
|
+
render(h) {
|
|
137
146
|
if (!this.menu) return false
|
|
138
|
-
return this.templates(
|
|
147
|
+
return this.templates(h)[this.template](this)
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
</script>
|
|
@@ -20,7 +20,7 @@ import { DruxtBlocksBlockMixin } from 'druxt-blocks'
|
|
|
20
20
|
* uuid="d4efd803-94af-4742-bc94-ea4360085b74"
|
|
21
21
|
* />
|
|
22
22
|
*
|
|
23
|
-
* @see {@link https://blocks.druxtjs.org/api/components/DruxtBlock
|
|
23
|
+
* @see {@link https://blocks.druxtjs.org/api/components/DruxtBlock|DruxtBlock}
|
|
24
24
|
*/
|
|
25
25
|
export default {
|
|
26
26
|
name: 'DruxtBlockSystemMenuBlock',
|
|
@@ -28,7 +28,7 @@ export default {
|
|
|
28
28
|
/**
|
|
29
29
|
* Vue.js Mixins.
|
|
30
30
|
*
|
|
31
|
-
* @see {@link https://blocks.druxtjs.org/api/mixins/block
|
|
31
|
+
* @see {@link https://blocks.druxtjs.org/api/mixins/block|DruxtBlocksBlockMixin}
|
|
32
32
|
*/
|
|
33
33
|
mixins: [DruxtBlocksBlockMixin],
|
|
34
34
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-menu",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "Drupal Menu and Menu item Druxt components, with support for the JSON:API Menu Items module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"deepmerge": "^4.2.2",
|
|
46
|
-
"drupal-jsonapi-params": "^
|
|
47
|
-
"druxt": "^0.
|
|
48
|
-
"druxt-blocks": "^0.15.
|
|
46
|
+
"drupal-jsonapi-params": "^2.0.0",
|
|
47
|
+
"druxt": "^0.18.2",
|
|
48
|
+
"druxt-blocks": "^0.15.2"
|
|
49
49
|
},
|
|
50
50
|
"optionalDependencies": {
|
|
51
51
|
"vue": "^2.6.14",
|