druxt-menu 0.20.0 → 0.21.1-dev.20260920043715
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/README.md +140 -55
- package/banner.svg +1 -0
- package/dist/components/DruxtMenu.vue +32 -9
- package/dist/components/DruxtMenuItem.vue +9 -2
- package/dist/components/blocks/DruxtBlockSystemMenuBlock.vue +3 -3
- package/dist/druxt-menu.esm.js +21 -6
- package/dist/druxt-menu.ssr.js +21 -6
- package/icon.svg +4 -0
- package/package.json +12 -6
- package/templates/plugin.js +5 -0
package/README.md
CHANGED
|
@@ -1,76 +1,155 @@
|
|
|
1
|
+
<img src="./banner.svg" alt="DruxtMenu renders Drupal menus as Vue components">
|
|
2
|
+
|
|
1
3
|
# DruxtMenu
|
|
2
4
|
|
|
3
5
|
[](https://www.npmjs.com/package/druxt-menu)
|
|
4
|
-
[](https://github.com/druxt/druxt.js/actions/workflows/ci.yml)
|
|
7
|
+
[](https://snyk.io/test/github/druxt/druxt.js?targetFile=package.json)
|
|
8
|
+
[](https://codecov.io/gh/druxt/druxt.js)
|
|
7
9
|
|
|
8
10
|
> Drupal Menu and Menu item Druxt components, with support for the JSON:API Menu Items module.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
DruxtMenu renders Drupal menus in Nuxt. Ask for a menu by name and you get
|
|
13
|
+
the tree Drupal manages; with the JSON:API Menu Items module it covers full
|
|
14
|
+
menus, including module-defined links, not just content links. Every menu and
|
|
15
|
+
menu item themes through the Druxt component suggestion system.
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
- Documentation: https://druxtjs.org/modules/menu
|
|
14
|
-
- Community Discord server: https://discord.druxtjs.org
|
|
17
|
+

|
|
15
18
|
|
|
16
|
-
##
|
|
19
|
+
## Features
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
- Vue.js components:
|
|
22
|
+
- **DruxtMenu** renders a Drupal menu by name
|
|
23
|
+
- **Druxt settings** filter JSON:API fields
|
|
24
|
+
- **Drupal Menu blocks**
|
|
25
|
+
- **@nuxtjs/Storybook** integration
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
---
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
## Installation
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
requiredOnly: true,
|
|
32
|
-
fields: [],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
```
|
|
31
|
+
> Included with [`druxt-site`](https://druxtjs.org/modules/site). Install it separately only when composing modules yourself.
|
|
32
|
+
|
|
33
|
+
1. Install the package:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm i druxt-menu
|
|
37
|
+
```
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
2. Add the module to `nuxt.config.js`:
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
```js
|
|
42
|
+
export default {
|
|
43
|
+
modules: ['druxt-menu'],
|
|
44
|
+
druxt: {
|
|
45
|
+
baseUrl: 'https://api.umami.demo.druxtjs.org',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
```
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
`druxt.baseUrl` is required: without it the generated plugin throws
|
|
51
|
+
`The 'baseUrl' parameter is required.`
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Drupal requirements
|
|
56
|
+
|
|
57
|
+
Rendering a menu needs data from the Drupal side, and where it comes from
|
|
58
|
+
depends on what you want:
|
|
59
|
+
|
|
60
|
+
- **Menu blocks** (the typical site case): rendered by the
|
|
61
|
+
[Blocks module](https://druxtjs.org/modules/blocks): no extra Drupal setup.
|
|
62
|
+
- **Full menus by name** (`<DruxtMenu name="main">`): requires the
|
|
63
|
+
[JSON:API Menu Items](https://www.drupal.org/project/jsonapi_menu_items)
|
|
64
|
+
Drupal module:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
composer require drupal/jsonapi_menu_items
|
|
68
|
+
drush pm:enable jsonapi_menu_items
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Once enabled, set `druxt.menu.jsonApiMenuItems: true` to fetch menus
|
|
72
|
+
through the `jsonapi_menu_items` resource; without it Druxt keeps using
|
|
73
|
+
`menu_link_content`. Multilingual menus need `jsonapi_menu_items`
|
|
74
|
+
`1.2.4` or later.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Vue.js Components
|
|
79
|
+
|
|
80
|
+
### DruxtMenu
|
|
81
|
+
|
|
82
|
+
Renders a Drupal menu using either the default Drupal content menus, or the full menu via the [JSON:API Menu Items](https://www.drupal.org/project/jsonapi_menu_items) module.
|
|
44
83
|
|
|
45
84
|
```vue
|
|
46
85
|
<DruxtMenu name="main" :depth="1" />
|
|
47
86
|
```
|
|
48
87
|
|
|
49
|
-
|
|
88
|
+
- For more details, refer to the [DruxtMenu API documentation](https://druxtjs.org/api/packages/menu/components/DruxtMenu).
|
|
50
89
|
|
|
51
|
-
|
|
90
|
+
---
|
|
52
91
|
|
|
53
|
-
|
|
92
|
+
## Settings
|
|
54
93
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
94
|
+
### Reducing JSON:API data
|
|
95
|
+
|
|
96
|
+
The default behaviour of the Menu module is to retrieve all available fields from the JSON:API.
|
|
97
|
+
|
|
98
|
+
This behaviour is configurable using the modules `query` option, allowing for manually filtered `fields` or automatically filtered fields using the `requiredOnly` option.
|
|
99
|
+
|
|
100
|
+
The default behaviour can be set via `nuxt.config.js`:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
druxt: {
|
|
104
|
+
menu: {
|
|
105
|
+
query: {
|
|
106
|
+
fields: [],
|
|
107
|
+
requiredOnly: true,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
62
111
|
```
|
|
63
112
|
|
|
64
|
-
|
|
113
|
+
Alternatively, the behaviour can be set directly on a Menu wrapper component:
|
|
114
|
+
|
|
65
115
|
```vue
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
116
|
+
<script>
|
|
117
|
+
export default {
|
|
118
|
+
druxt: {
|
|
119
|
+
query: {
|
|
120
|
+
fields: ['description', 'options'],
|
|
121
|
+
requiredOnly: false,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
</script>
|
|
71
126
|
```
|
|
72
127
|
|
|
73
|
-
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Menu blocks
|
|
131
|
+
|
|
132
|
+
The DruxtMenu module provides a **DruxtBlockSystemMenuBlock** component that is used by the Druxt Block module to render Drupal menu blocks.
|
|
133
|
+
|
|
134
|
+
- For more details, see the [Druxt Blocks module](https://druxtjs.org/modules/blocks).
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Storybook
|
|
139
|
+
|
|
140
|
+
DruxtMenu provides zero-config, auto-generated Storybook integration with a live data connection to your Druxt backend.
|
|
141
|
+
|
|
142
|
+
- For more details, see the [Storybook guide](https://druxtjs.org/how-to/storybook).
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Deprecations
|
|
147
|
+
|
|
148
|
+
The `items` computed property is deprecated in favour of `model`. See the
|
|
149
|
+
[deprecations page](https://druxtjs.org/modules/menu/deprecations) for what replaces it, and what
|
|
150
|
+
is unaffected.
|
|
151
|
+
|
|
152
|
+
---
|
|
74
153
|
|
|
75
154
|
## Options
|
|
76
155
|
|
|
@@ -78,18 +157,24 @@ See the [Druxt Theming guide](https://druxtjs.org/guide/theming) for more inform
|
|
|
78
157
|
|
|
79
158
|
These options are specific to this module.
|
|
80
159
|
|
|
81
|
-
| Option
|
|
82
|
-
|
|
|
83
|
-
| `menu.jsonApiMenuItems`
|
|
84
|
-
| `menu.query.fields`
|
|
85
|
-
| `menu.query.requiredOnly` | `boolean`
|
|
160
|
+
| Option | Type | Required | Default | Description |
|
|
161
|
+
| ------------------------- | ---------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
162
|
+
| `menu.jsonApiMenuItems` | `boolean` | No | `true` | Use the Drupal [JSON:API Menu Items](https://www.drupal.org/project/jsonapi_menu_items) module resource. The Nuxt module enables this by default. The `DruxtMenu` class used directly defaults it to `false`. |
|
|
163
|
+
| `menu.query.fields` | `string[]` | No | `false` | An array of fields to filter all JSON:API Menu queries. |
|
|
164
|
+
| `menu.query.requiredOnly` | `boolean` | No | `false` | Whether to automatically filter to module-defined minimum required fields. |
|
|
86
165
|
|
|
87
166
|
### Base Druxt options
|
|
88
167
|
|
|
89
168
|
These options are available to all Druxt modules.
|
|
90
169
|
|
|
91
|
-
| Option
|
|
92
|
-
|
|
|
93
|
-
| `axios`
|
|
94
|
-
| `baseUrl`
|
|
95
|
-
| `endpoint` | `string` | No
|
|
170
|
+
| Option | Type | Required | Default | Description |
|
|
171
|
+
| ---------- | -------- | -------- | ---------- | ---------------------------------------------------------------------------- |
|
|
172
|
+
| `axios` | `object` | No | `{}` | [Axios instance settings](https://github.com/axios/axios#axioscreateconfig). |
|
|
173
|
+
| `baseUrl` | `string` | Yes | `null` | Base URL for the Drupal installation. |
|
|
174
|
+
| `endpoint` | `string` | No | `/jsonapi` | JSON:API Endpoint of the Drupal installation. |
|
|
175
|
+
|
|
176
|
+
## Links
|
|
177
|
+
|
|
178
|
+
- DruxtJS: https://druxtjs.org
|
|
179
|
+
- Documentation: https://druxtjs.org/modules/menu
|
|
180
|
+
- Community Discord server: https://discord.druxtjs.org
|
package/banner.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 320" width="1280" height="320" role="img" aria-label="druxt-menu: Drupal menus as Vue components."><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#1f2937"/><stop offset="0.7" stop-color="#2f495e"/><stop offset="1" stop-color="#36566e"/></linearGradient></defs><rect width="1280" height="320" rx="16" fill="url(#g)"/><rect x="250" y="85" width="150" height="150" rx="32" fill="rgba(229,236,241,0.07)"/><g transform="translate(277,112) scale(4)" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 6h.01M4.5 12h.01M8 18h.01" stroke="#7cc5f1"/><path d="M9 6h10.5M9 12h10.5M12.5 18h7" stroke="#68cb9f"/></g><text x="440" y="150" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="64" font-weight="700" letter-spacing="-1" fill="#eef2f6">Menu</text><text x="614" y="150" style="font-family:ui-monospace,Menlo,Consolas,monospace" font-size="26" fill="#7cc5f1">druxt-menu</text><text x="440" y="196" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="25" fill="rgba(229,236,241,0.75)">Drupal menus as Vue components.</text><g transform="translate(440,236) scale(0.0994)"><path d="M139 330l-1-2c-2-4-2-8-1-13H29L189 31l67 121 22-16-67-121c-1-2-9-14-22-14-6 0-15 2-22 15L5 303c-1 3-8 16-2 27 4 6 10 12 24 12h136c-14 0-21-6-24-12z" fill="#3498DB"/><path d="M447 304L317 70c-2-2-9-15-22-15-6 0-15 3-22 15l-17 28v54l39-67 129 230h-49a23 23 0 0 1-2 14l-1 1c-6 11-21 12-23 12h76c3 0 17-1 24-12 3-5 5-14-2-26z" fill="#108775"/><path d="M376 330v-1l1-2c1-4 2-8 1-12l-4-12-102-178-15-27h-1l-15 27-102 178-4 12a24 24 0 0 0 2 15c4 6 10 12 24 12h190c3 0 18-1 25-12zM256 152l93 163H163l93-163z" fill="#E5ECF1"/></g><text x="492" y="260" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="17" font-weight="600" fill="rgba(229,236,241,0.85)">druxtjs.org</text></svg>
|
|
@@ -5,8 +5,10 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
|
|
|
5
5
|
import { mapActions, mapGetters, mapState } from 'vuex'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* The DruxtMenu component renders a Drupal menu using
|
|
9
|
-
*
|
|
8
|
+
* The DruxtMenu component renders a Drupal menu using menu link content
|
|
9
|
+
* entities via the core JSON:API (content-created links only), or the
|
|
10
|
+
* complete menu tree, including module-defined links, via the JSON:API Menu
|
|
11
|
+
* Items module.
|
|
10
12
|
*
|
|
11
13
|
* @example @lang vue
|
|
12
14
|
* <DruxtMenu name="main" />
|
|
@@ -22,13 +24,15 @@ import { mapActions, mapGetters, mapState } from 'vuex'
|
|
|
22
24
|
* mixins: [DruxtMenuMixin]
|
|
23
25
|
* }
|
|
24
26
|
*
|
|
25
|
-
* @example <caption>
|
|
27
|
+
* @example <caption>default slot (template injection)</caption> @lang vue
|
|
26
28
|
* <DruxtMenu>
|
|
27
29
|
* <template #default="{ items }">
|
|
28
30
|
* <!-- Do whatever you want here -->
|
|
29
31
|
* <DruxtDebug :json="items" />
|
|
30
32
|
* </template>
|
|
31
33
|
* </DruxtMenu>
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://druxtjs.org/explanation/component-resolution|Component resolution}
|
|
32
36
|
*/
|
|
33
37
|
export default {
|
|
34
38
|
name: 'DruxtMenu',
|
|
@@ -100,7 +104,8 @@ export default {
|
|
|
100
104
|
},
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
|
-
* The name
|
|
107
|
+
* The Drupal menu machine name (such as `main` or `footer`) of the
|
|
108
|
+
* menu to load and render.
|
|
104
109
|
*
|
|
105
110
|
* @example @lang vue
|
|
106
111
|
* <DruxtMenu name="main" />
|
|
@@ -180,7 +185,9 @@ export default {
|
|
|
180
185
|
* The processed Menu items.
|
|
181
186
|
*
|
|
182
187
|
* @type {objects[]}
|
|
183
|
-
* @deprecated
|
|
188
|
+
* @deprecated in druxt-menu:0.11.0 and is removed from druxt-menu:2.0.0.
|
|
189
|
+
* Use the model property (v-model) instead.
|
|
190
|
+
* @see https://druxtjs.org/modules/menu/deprecations
|
|
184
191
|
*/
|
|
185
192
|
items: ({ model }) => model,
|
|
186
193
|
|
|
@@ -223,6 +230,7 @@ export default {
|
|
|
223
230
|
mounted() {
|
|
224
231
|
// If logged in and statically generated, re-fetch the menu.
|
|
225
232
|
if (this?.$auth?.loggedIn && this?.$store?.app?.context?.isStatic) {
|
|
233
|
+
this.$store.commit('druxtMenu/flushEntities', { prefix: this.lang })
|
|
226
234
|
const settings = this.$options.druxt.settings(this, this.component.settings)
|
|
227
235
|
this.$options.druxt.fetchData.call(this, settings)
|
|
228
236
|
}
|
|
@@ -282,6 +290,7 @@ export default {
|
|
|
282
290
|
* Provides the available component naming options for the Druxt Wrapper.
|
|
283
291
|
*
|
|
284
292
|
* @param {object} context - The module component ViewModel.
|
|
293
|
+
* @param {string} context.name - The name of the menu to load and render.
|
|
285
294
|
* @returns {ComponentOptions}
|
|
286
295
|
*/
|
|
287
296
|
componentOptions: ({ name }) => [[name], ['default']],
|
|
@@ -289,6 +298,8 @@ export default {
|
|
|
289
298
|
/**
|
|
290
299
|
* Builds and executes the JSON:API query, loading the menu items into the
|
|
291
300
|
* druxtMenu Vuex store.
|
|
301
|
+
*
|
|
302
|
+
* @param {object} settings - The module settings object, including the menu items query configuration.
|
|
292
303
|
*/
|
|
293
304
|
async fetchData(settings) {
|
|
294
305
|
if (!this.value) {
|
|
@@ -305,12 +316,23 @@ export default {
|
|
|
305
316
|
* Provides propsData for the DruxtWrapper.
|
|
306
317
|
*
|
|
307
318
|
* @param {object} context - The module component ViewModel.
|
|
319
|
+
* @param {object[]} context.model - The menu items model value.
|
|
320
|
+
* @param {string} context.parentId - The menu parent ID to use as the root of the menu.
|
|
308
321
|
* @returns {PropsData}
|
|
309
322
|
*/
|
|
310
323
|
propsData: ({ model, parentId }) => ({ items: model, parentId, value: model }),
|
|
311
324
|
|
|
312
325
|
/**
|
|
313
326
|
* Component settings.
|
|
327
|
+
*
|
|
328
|
+
* @param {object} context - The module component ViewModel.
|
|
329
|
+
* @param {object} context.$druxt - The Druxt Nuxt plugin instance.
|
|
330
|
+
* @param {number} context.depth - The depth of the menu items to render.
|
|
331
|
+
* @param {number|null} context.maxDepth - The maximum depth of the menu tree data to load.
|
|
332
|
+
* @param {number} context.minDepth - The minimum depth of the menu tree.
|
|
333
|
+
* @param {string} context.parentId - The menu parent ID to use as the root of the menu.
|
|
334
|
+
* @param {object} wrapperSettings - Settings provided by the wrapper component.
|
|
335
|
+
* @returns {object} The merged module settings.
|
|
314
336
|
*/
|
|
315
337
|
settings: ({ $druxt, depth, maxDepth, minDepth, parentId }, wrapperSettings) => {
|
|
316
338
|
const settings = merge($druxt.settings.menu || {}, wrapperSettings, { arrayMerge: (dest, src) => src })
|
|
@@ -337,6 +359,7 @@ export default {
|
|
|
337
359
|
* </div>
|
|
338
360
|
* </template>
|
|
339
361
|
*
|
|
362
|
+
* @param {Function} h - The Vue createElement function.
|
|
340
363
|
* @return {ScopedSlots} The Scoped slots object.
|
|
341
364
|
*/
|
|
342
365
|
slots(h) {
|
|
@@ -365,7 +388,7 @@ export default {
|
|
|
365
388
|
}
|
|
366
389
|
|
|
367
390
|
/**
|
|
368
|
-
* Provides the available naming options for the
|
|
391
|
+
* Provides the available naming options for the wrapper component.
|
|
369
392
|
*
|
|
370
393
|
* @typedef {array[]} ComponentOptions
|
|
371
394
|
*
|
|
@@ -388,7 +411,7 @@ export default {
|
|
|
388
411
|
|
|
389
412
|
/**
|
|
390
413
|
* Provides settings for the Menu module, via the `nuxt.config.js` `druxt.menu`
|
|
391
|
-
* or the
|
|
414
|
+
* or the wrapper component `druxt` object.
|
|
392
415
|
*
|
|
393
416
|
* @typedef {object} ModuleSettings
|
|
394
417
|
* @param {string[]} fields - An array of fields to filter all JSON:API Menu queries.
|
|
@@ -413,7 +436,7 @@ export default {
|
|
|
413
436
|
*/
|
|
414
437
|
|
|
415
438
|
/**
|
|
416
|
-
* Provides propsData for use in the
|
|
439
|
+
* Provides propsData for use in the wrapper component.
|
|
417
440
|
*
|
|
418
441
|
* @typedef {object} PropsData
|
|
419
442
|
* @param {object[]} items - The Menu items structured data.
|
|
@@ -437,7 +460,7 @@ export default {
|
|
|
437
460
|
*/
|
|
438
461
|
|
|
439
462
|
/**
|
|
440
|
-
* Provides scoped slots for use in the
|
|
463
|
+
* Provides scoped slots for use in the wrapper component.
|
|
441
464
|
*
|
|
442
465
|
* @typedef {object} ScopedSlots
|
|
443
466
|
* @param {function} default - All menu items using the DruxtMenuItem component
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
/**
|
|
47
47
|
* The parent DruxtMenu component, if present.
|
|
48
48
|
*
|
|
49
|
-
* @type {
|
|
49
|
+
* @type {object|boolean}
|
|
50
50
|
*/
|
|
51
51
|
menu: ({ $parent }) => {
|
|
52
52
|
let menu = false
|
|
@@ -83,7 +83,10 @@ export default {
|
|
|
83
83
|
|
|
84
84
|
methods: {
|
|
85
85
|
/**
|
|
86
|
-
* Returns a menu link
|
|
86
|
+
* Returns a menu link component.
|
|
87
|
+
*
|
|
88
|
+
* @param {Function} h - The Vue createElement function.
|
|
89
|
+
* @param {object} entity - The menu item entity.
|
|
87
90
|
*/
|
|
88
91
|
getLink(h, entity = {}) {
|
|
89
92
|
if (!entity.attributes) return false
|
|
@@ -105,6 +108,8 @@ export default {
|
|
|
105
108
|
|
|
106
109
|
/**
|
|
107
110
|
* The menu item template functions.
|
|
111
|
+
*
|
|
112
|
+
* @param {Function} h - The Vue createElement function.
|
|
108
113
|
*/
|
|
109
114
|
templates(h) {
|
|
110
115
|
return {
|
|
@@ -141,6 +146,8 @@ export default {
|
|
|
141
146
|
|
|
142
147
|
/**
|
|
143
148
|
* The Vue.js render function.
|
|
149
|
+
*
|
|
150
|
+
* @param {Function} h - The Vue createElement function.
|
|
144
151
|
*/
|
|
145
152
|
render(h) {
|
|
146
153
|
if (!this.menu) return false
|
|
@@ -23,7 +23,7 @@ import { DruxtBlocksBlockMixin } from 'druxt-blocks'
|
|
|
23
23
|
* uuid="d4efd803-94af-4742-bc94-ea4360085b74"
|
|
24
24
|
* />
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://
|
|
26
|
+
* @see {@link https://druxtjs.org/api/packages/blocks/components/DruxtBlock|DruxtBlock}
|
|
27
27
|
*/
|
|
28
28
|
export default {
|
|
29
29
|
name: 'DruxtBlockSystemMenuBlock',
|
|
@@ -31,7 +31,7 @@ export default {
|
|
|
31
31
|
/**
|
|
32
32
|
* Vue.js Mixins.
|
|
33
33
|
*
|
|
34
|
-
* @see {@link https://
|
|
34
|
+
* @see {@link https://druxtjs.org/api/packages/blocks/mixins/block|DruxtBlocksBlockMixin}
|
|
35
35
|
*/
|
|
36
36
|
mixins: [DruxtBlocksBlockMixin],
|
|
37
37
|
|
|
@@ -42,7 +42,7 @@ export default {
|
|
|
42
42
|
/**
|
|
43
43
|
* The menu name.
|
|
44
44
|
*
|
|
45
|
-
* @type string
|
|
45
|
+
* @type {string}
|
|
46
46
|
*/
|
|
47
47
|
name() {
|
|
48
48
|
return this.settings.id.split(':')[1]
|
package/dist/druxt-menu.esm.js
CHANGED
|
@@ -29,6 +29,7 @@ async function DruxtMenuStorybook({ stories }) {
|
|
|
29
29
|
stories.push(resolve(options.buildDir, "./stories/druxt-menu.*.stories.js"));
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
const extendComponent = (component) => ({ ...component, isAsync: false });
|
|
32
33
|
const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
33
34
|
const options = {
|
|
34
35
|
baseUrl: moduleOptions.baseUrl,
|
|
@@ -41,8 +42,8 @@ const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
|
41
42
|
};
|
|
42
43
|
await this.addModule(["druxt", options]);
|
|
43
44
|
this.nuxt.hook("components:dirs", (dirs) => {
|
|
44
|
-
dirs.push({ path: join(__dirname, "components") });
|
|
45
|
-
dirs.push({ path: join(__dirname, "components/blocks") });
|
|
45
|
+
dirs.push({ path: join(__dirname, "components"), extendComponent });
|
|
46
|
+
dirs.push({ path: join(__dirname, "components/blocks"), extendComponent });
|
|
46
47
|
});
|
|
47
48
|
this.addPlugin({
|
|
48
49
|
src: resolve(__dirname, "../templates/plugin.js"),
|
|
@@ -60,6 +61,7 @@ const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
|
60
61
|
};
|
|
61
62
|
DruxtMenuNuxtModule.meta = require("../package.json");
|
|
62
63
|
|
|
64
|
+
const menuCache = new WeakMap();
|
|
63
65
|
class DruxtMenu {
|
|
64
66
|
constructor(baseUrl, options = {}) {
|
|
65
67
|
if (!baseUrl) {
|
|
@@ -71,7 +73,7 @@ class DruxtMenu {
|
|
|
71
73
|
},
|
|
72
74
|
...options
|
|
73
75
|
};
|
|
74
|
-
this.druxt = new DruxtClient(baseUrl, options);
|
|
76
|
+
this.druxt = options.druxtClient || new DruxtClient(baseUrl, options);
|
|
75
77
|
}
|
|
76
78
|
buildQuery(resource, menuName, requiredFields, settings) {
|
|
77
79
|
const query = new DrupalJsonApiParams().addFilter("enabled", "1").addFilter("menu_name", menuName);
|
|
@@ -88,10 +90,17 @@ class DruxtMenu {
|
|
|
88
90
|
return query;
|
|
89
91
|
}
|
|
90
92
|
async get(menuName, settings, prefix) {
|
|
91
|
-
if (this.
|
|
92
|
-
|
|
93
|
+
if (!menuCache.has(this.druxt))
|
|
94
|
+
menuCache.set(this.druxt, new Map());
|
|
95
|
+
const cache = menuCache.get(this.druxt);
|
|
96
|
+
const jsonApiMenuItems = !!this.options.menu.jsonApiMenuItems;
|
|
97
|
+
const cacheKey = JSON.stringify([prefix || "", menuName, settings || {}, jsonApiMenuItems]);
|
|
98
|
+
if (!cache.has(cacheKey)) {
|
|
99
|
+
const request = jsonApiMenuItems ? this.getJsonApiMenuItems(menuName, settings, prefix) : this.getMenuLinkContent(menuName, settings, prefix);
|
|
100
|
+
cache.set(cacheKey, request);
|
|
101
|
+
request.catch(() => cache.delete(cacheKey));
|
|
93
102
|
}
|
|
94
|
-
return
|
|
103
|
+
return cache.get(cacheKey);
|
|
95
104
|
}
|
|
96
105
|
async getMenuLinkContent(menuName, settings, prefix) {
|
|
97
106
|
const resource = "menu_link_content--menu_link_content";
|
|
@@ -167,6 +176,12 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
167
176
|
const entity = entities[index];
|
|
168
177
|
Vue.set(state.entities[prefix], entity.id, entity);
|
|
169
178
|
}
|
|
179
|
+
},
|
|
180
|
+
flushEntities(state, { prefix }) {
|
|
181
|
+
if (!prefix || typeof state.entities !== "object")
|
|
182
|
+
Vue.set(state, "entities", {});
|
|
183
|
+
if (prefix)
|
|
184
|
+
Vue.set(state.entities, prefix, {});
|
|
170
185
|
}
|
|
171
186
|
},
|
|
172
187
|
actions: {
|
package/dist/druxt-menu.ssr.js
CHANGED
|
@@ -37,6 +37,7 @@ async function DruxtMenuStorybook({ stories }) {
|
|
|
37
37
|
stories.push(path.resolve(options.buildDir, "./stories/druxt-menu.*.stories.js"));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
const extendComponent = (component) => ({ ...component, isAsync: false });
|
|
40
41
|
const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
41
42
|
const options = {
|
|
42
43
|
baseUrl: moduleOptions.baseUrl,
|
|
@@ -49,8 +50,8 @@ const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
|
49
50
|
};
|
|
50
51
|
await this.addModule(["druxt", options]);
|
|
51
52
|
this.nuxt.hook("components:dirs", (dirs) => {
|
|
52
|
-
dirs.push({ path: path.join(__dirname, "components") });
|
|
53
|
-
dirs.push({ path: path.join(__dirname, "components/blocks") });
|
|
53
|
+
dirs.push({ path: path.join(__dirname, "components"), extendComponent });
|
|
54
|
+
dirs.push({ path: path.join(__dirname, "components/blocks"), extendComponent });
|
|
54
55
|
});
|
|
55
56
|
this.addPlugin({
|
|
56
57
|
src: path.resolve(__dirname, "../templates/plugin.js"),
|
|
@@ -68,6 +69,7 @@ const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
|
68
69
|
};
|
|
69
70
|
DruxtMenuNuxtModule.meta = require("../package.json");
|
|
70
71
|
|
|
72
|
+
const menuCache = new WeakMap();
|
|
71
73
|
class DruxtMenu {
|
|
72
74
|
constructor(baseUrl, options = {}) {
|
|
73
75
|
if (!baseUrl) {
|
|
@@ -79,7 +81,7 @@ class DruxtMenu {
|
|
|
79
81
|
},
|
|
80
82
|
...options
|
|
81
83
|
};
|
|
82
|
-
this.druxt = new druxt.DruxtClient(baseUrl, options);
|
|
84
|
+
this.druxt = options.druxtClient || new druxt.DruxtClient(baseUrl, options);
|
|
83
85
|
}
|
|
84
86
|
buildQuery(resource, menuName, requiredFields, settings) {
|
|
85
87
|
const query = new drupalJsonapiParams.DrupalJsonApiParams().addFilter("enabled", "1").addFilter("menu_name", menuName);
|
|
@@ -96,10 +98,17 @@ class DruxtMenu {
|
|
|
96
98
|
return query;
|
|
97
99
|
}
|
|
98
100
|
async get(menuName, settings, prefix) {
|
|
99
|
-
if (this.
|
|
100
|
-
|
|
101
|
+
if (!menuCache.has(this.druxt))
|
|
102
|
+
menuCache.set(this.druxt, new Map());
|
|
103
|
+
const cache = menuCache.get(this.druxt);
|
|
104
|
+
const jsonApiMenuItems = !!this.options.menu.jsonApiMenuItems;
|
|
105
|
+
const cacheKey = JSON.stringify([prefix || "", menuName, settings || {}, jsonApiMenuItems]);
|
|
106
|
+
if (!cache.has(cacheKey)) {
|
|
107
|
+
const request = jsonApiMenuItems ? this.getJsonApiMenuItems(menuName, settings, prefix) : this.getMenuLinkContent(menuName, settings, prefix);
|
|
108
|
+
cache.set(cacheKey, request);
|
|
109
|
+
request.catch(() => cache.delete(cacheKey));
|
|
101
110
|
}
|
|
102
|
-
return
|
|
111
|
+
return cache.get(cacheKey);
|
|
103
112
|
}
|
|
104
113
|
async getMenuLinkContent(menuName, settings, prefix) {
|
|
105
114
|
const resource = "menu_link_content--menu_link_content";
|
|
@@ -175,6 +184,12 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
175
184
|
const entity = entities[index];
|
|
176
185
|
Vue__default["default"].set(state.entities[prefix], entity.id, entity);
|
|
177
186
|
}
|
|
187
|
+
},
|
|
188
|
+
flushEntities(state, { prefix }) {
|
|
189
|
+
if (!prefix || typeof state.entities !== "object")
|
|
190
|
+
Vue__default["default"].set(state, "entities", {});
|
|
191
|
+
if (prefix)
|
|
192
|
+
Vue__default["default"].set(state.entities, prefix, {});
|
|
178
193
|
}
|
|
179
194
|
},
|
|
180
195
|
actions: {
|
package/icon.svg
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.1-dev.20260920043715",
|
|
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",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"url": "git+https://github.com/druxt/druxt.js"
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
|
+
"author": "Stuart Clark <stuart@druxtjs.org>",
|
|
31
32
|
"exports": {
|
|
32
33
|
".": {
|
|
33
34
|
"require": "./dist/druxt-menu.ssr.js",
|
|
@@ -39,16 +40,21 @@
|
|
|
39
40
|
"module": "dist/druxt-menu.esm.js",
|
|
40
41
|
"files": [
|
|
41
42
|
"dist",
|
|
42
|
-
"templates"
|
|
43
|
+
"templates",
|
|
44
|
+
"icon.svg",
|
|
45
|
+
"banner.svg"
|
|
43
46
|
],
|
|
44
47
|
"dependencies": {
|
|
45
48
|
"deepmerge": "^4.3.1",
|
|
46
|
-
"drupal-jsonapi-params": "^2.2
|
|
47
|
-
"druxt": "
|
|
48
|
-
"druxt-blocks": "
|
|
49
|
+
"drupal-jsonapi-params": "^2.3.2",
|
|
50
|
+
"druxt": "0.24.1-dev.20260920043715",
|
|
51
|
+
"druxt-blocks": "0.17.4-dev.20260920043715"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"axios": "0.33.0"
|
|
49
55
|
},
|
|
50
56
|
"optionalDependencies": {
|
|
51
|
-
"vue": "^2.7.
|
|
57
|
+
"vue": "^2.7.16",
|
|
52
58
|
"vuex": "^3.6.2"
|
|
53
59
|
},
|
|
54
60
|
"publishConfig": {
|
package/templates/plugin.js
CHANGED
|
@@ -20,6 +20,11 @@ export default ({ app }, inject) => {
|
|
|
20
20
|
options.axios = app.$axios
|
|
21
21
|
<% } %>
|
|
22
22
|
|
|
23
|
+
// Reuse the druxt module client if available.
|
|
24
|
+
if (app.$druxt) {
|
|
25
|
+
options.druxtClient = app.$druxt
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
const druxtMenu = new DruxtMenu(baseUrl, options)
|
|
24
29
|
inject('druxtMenu', druxtMenu)
|
|
25
30
|
}
|