druxt-menu 0.16.3 → 0.18.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.
|
@@ -217,7 +217,7 @@ export default {
|
|
|
217
217
|
*/
|
|
218
218
|
entities() {
|
|
219
219
|
this.$forceUpdate()
|
|
220
|
-
}
|
|
220
|
+
},
|
|
221
221
|
},
|
|
222
222
|
|
|
223
223
|
methods: {
|
|
@@ -242,8 +242,11 @@ export default {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
const entities = this.getEntitiesByFilter(
|
|
246
|
-
|
|
245
|
+
const entities = this.getEntitiesByFilter({
|
|
246
|
+
filter: (key) => {
|
|
247
|
+
return this.entities[this.lang][key].attributes.menu_name === this.name && this.entities[this.lang][key].attributes.parent === parent
|
|
248
|
+
},
|
|
249
|
+
prefix: this.lang
|
|
247
250
|
})
|
|
248
251
|
|
|
249
252
|
for (const key in entities) {
|
|
@@ -281,7 +284,11 @@ export default {
|
|
|
281
284
|
*/
|
|
282
285
|
async fetchData(settings) {
|
|
283
286
|
if (!this.value) {
|
|
284
|
-
await this.getMenu({
|
|
287
|
+
await this.getMenu({
|
|
288
|
+
name: this.name,
|
|
289
|
+
settings: settings.query,
|
|
290
|
+
prefix: this.lang
|
|
291
|
+
})
|
|
285
292
|
this.model = this.getMenuItems()
|
|
286
293
|
}
|
|
287
294
|
},
|
|
@@ -326,11 +333,12 @@ export default {
|
|
|
326
333
|
*/
|
|
327
334
|
slots(h) {
|
|
328
335
|
return {
|
|
329
|
-
default: (attrs) => this.items.map((item) => h('DruxtMenuItem', {
|
|
336
|
+
default: (attrs) => (this.items || []).map((item) => h('DruxtMenuItem', {
|
|
330
337
|
attrs,
|
|
331
338
|
key: item.entity.id,
|
|
332
339
|
props: {
|
|
333
340
|
item,
|
|
341
|
+
langcode: this.lang
|
|
334
342
|
},
|
|
335
343
|
})),
|
|
336
344
|
}
|
|
@@ -345,13 +353,17 @@ export default {
|
|
|
345
353
|
*
|
|
346
354
|
* @example @lang js
|
|
347
355
|
* [
|
|
356
|
+
* 'DruxtMenu[Name][Langcode]',
|
|
348
357
|
* 'DruxtMenu[Name]',
|
|
349
|
-
* '
|
|
358
|
+
* 'DruxtMenu[Default][Langcode]',
|
|
359
|
+
* 'DruxtMenu[Default]',
|
|
350
360
|
* ]
|
|
351
361
|
*
|
|
352
362
|
* @example <caption>Main menu (default)</caption> @lang js
|
|
353
363
|
* [
|
|
364
|
+
* 'DruxtMenuMainEn',
|
|
354
365
|
* 'DruxtMenuMain',
|
|
366
|
+
* 'DruxtMenuDefaultEn',
|
|
355
367
|
* 'DruxtMenuDefault',
|
|
356
368
|
* ]
|
|
357
369
|
*/
|
package/dist/druxt-menu.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve, join } from 'path';
|
|
2
2
|
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
3
3
|
import { DruxtClient } from 'druxt';
|
|
4
|
+
import Vue from 'vue';
|
|
4
5
|
|
|
5
6
|
const titleFn = (parts) => parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).replace(/_/g, " ")).join("/");
|
|
6
7
|
async function DruxtMenuStorybook({ stories }) {
|
|
@@ -28,15 +29,17 @@ async function DruxtMenuStorybook({ stories }) {
|
|
|
28
29
|
stories.push(resolve(options.buildDir, "./stories/druxt-menu.*.stories.js"));
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const DruxtMenuNuxtModule = function(moduleOptions = {}) {
|
|
32
|
+
const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
32
33
|
const options = {
|
|
33
34
|
baseUrl: moduleOptions.baseUrl,
|
|
34
35
|
...(this.options || {}).druxt || {},
|
|
35
36
|
menu: {
|
|
37
|
+
jsonApiMenuItems: true,
|
|
36
38
|
...((this.options || {}).druxt || {}).menu,
|
|
37
39
|
...moduleOptions
|
|
38
40
|
}
|
|
39
41
|
};
|
|
42
|
+
await this.addModule(["druxt", options]);
|
|
40
43
|
this.nuxt.hook("components:dirs", (dirs) => {
|
|
41
44
|
dirs.push({ path: join(__dirname, "components") });
|
|
42
45
|
dirs.push({ path: join(__dirname, "components/blocks") });
|
|
@@ -46,7 +49,6 @@ const DruxtMenuNuxtModule = function(moduleOptions = {}) {
|
|
|
46
49
|
fileName: "druxt-menu.js",
|
|
47
50
|
options
|
|
48
51
|
});
|
|
49
|
-
this.options.store = true;
|
|
50
52
|
this.addPlugin({
|
|
51
53
|
src: resolve(__dirname, "../templates/store.js"),
|
|
52
54
|
fileName: "store/druxt-menu.js",
|
|
@@ -85,18 +87,18 @@ class DruxtMenu {
|
|
|
85
87
|
}
|
|
86
88
|
return query;
|
|
87
89
|
}
|
|
88
|
-
async get(menuName, settings) {
|
|
90
|
+
async get(menuName, settings, prefix) {
|
|
89
91
|
if (this.options.menu.jsonApiMenuItems) {
|
|
90
|
-
return this.getJsonApiMenuItems(menuName, settings);
|
|
92
|
+
return this.getJsonApiMenuItems(menuName, settings, prefix);
|
|
91
93
|
}
|
|
92
|
-
return this.getMenuLinkContent(menuName, settings);
|
|
94
|
+
return this.getMenuLinkContent(menuName, settings, prefix);
|
|
93
95
|
}
|
|
94
|
-
async getMenuLinkContent(menuName, settings) {
|
|
96
|
+
async getMenuLinkContent(menuName, settings, prefix) {
|
|
95
97
|
const resource = "menu_link_content--menu_link_content";
|
|
96
98
|
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
97
99
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
98
100
|
const entities = [];
|
|
99
|
-
const collections = await this.druxt.getCollectionAll(resource, query);
|
|
101
|
+
const collections = await this.druxt.getCollectionAll(resource, query, prefix);
|
|
100
102
|
for (const collection of collections) {
|
|
101
103
|
for (const entity of collection.data) {
|
|
102
104
|
entities.push(entity);
|
|
@@ -104,12 +106,14 @@ class DruxtMenu {
|
|
|
104
106
|
}
|
|
105
107
|
return { entities };
|
|
106
108
|
}
|
|
107
|
-
async getJsonApiMenuItems(menuName, settings) {
|
|
109
|
+
async getJsonApiMenuItems(menuName, settings, prefix) {
|
|
108
110
|
const menuItemsResource = `menu_items--${menuName}`;
|
|
109
111
|
const resource = "menu_link_content--menu_link_content";
|
|
110
112
|
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
111
|
-
await this.druxt.getIndex();
|
|
112
|
-
this.druxt.index[menuItemsResource]
|
|
113
|
+
await this.druxt.getIndex(void 0, prefix);
|
|
114
|
+
if (!(this.druxt.index[prefix][menuItemsResource] || {}).href) {
|
|
115
|
+
this.druxt.index[prefix][menuItemsResource] = { href: `${prefix || ""}${this.druxt.options.endpoint}/menu_items/${menuName}` };
|
|
116
|
+
}
|
|
113
117
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
114
118
|
if ((settings || {}).max_depth) {
|
|
115
119
|
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
@@ -123,7 +127,7 @@ class DruxtMenu {
|
|
|
123
127
|
const entities = [];
|
|
124
128
|
let collections = [];
|
|
125
129
|
try {
|
|
126
|
-
collections = await this.druxt.getCollectionAll(menuItemsResource, query);
|
|
130
|
+
collections = await this.druxt.getCollectionAll(menuItemsResource, query, prefix);
|
|
127
131
|
} catch (e) {
|
|
128
132
|
return { entities };
|
|
129
133
|
}
|
|
@@ -156,26 +160,28 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
156
160
|
entities: {}
|
|
157
161
|
}),
|
|
158
162
|
mutations: {
|
|
159
|
-
addEntities(state, entities) {
|
|
163
|
+
addEntities(state, { entities, prefix }) {
|
|
164
|
+
if (!state.entities[prefix])
|
|
165
|
+
Vue.set(state.entities, prefix, {});
|
|
160
166
|
for (const index in entities) {
|
|
161
167
|
const entity = entities[index];
|
|
162
|
-
state.entities[entity.id
|
|
168
|
+
Vue.set(state.entities[prefix], entity.id, entity);
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
171
|
},
|
|
166
172
|
actions: {
|
|
167
173
|
async get({ commit }, context) {
|
|
168
|
-
const { name, settings } = typeof context === "object" ? context : { name: context };
|
|
169
|
-
const { entities } = await this.$druxtMenu.get(name, settings) || {};
|
|
170
|
-
commit("addEntities", entities);
|
|
174
|
+
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
175
|
+
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
176
|
+
commit("addEntities", { entities, prefix });
|
|
171
177
|
}
|
|
172
178
|
},
|
|
173
179
|
getters: {
|
|
174
|
-
getEntitiesByFilter: (state) => (filter) => {
|
|
175
|
-
const keys = Object.keys(state.entities).filter((key) => filter(key));
|
|
180
|
+
getEntitiesByFilter: (state) => ({ filter, prefix }) => {
|
|
181
|
+
const keys = Object.keys((state.entities || {})[prefix]).filter((key) => filter(key));
|
|
176
182
|
if (!keys.length)
|
|
177
183
|
return {};
|
|
178
|
-
return Object.assign(...keys.map((key) => ({ [key]: state.entities[key] })));
|
|
184
|
+
return Object.assign(...keys.map((key) => ({ [key]: state.entities[prefix][key] })));
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
};
|
|
@@ -190,6 +196,10 @@ const DruxtMenuMixin = {
|
|
|
190
196
|
type: Array,
|
|
191
197
|
required: true
|
|
192
198
|
},
|
|
199
|
+
langcode: {
|
|
200
|
+
type: String,
|
|
201
|
+
default: void 0
|
|
202
|
+
},
|
|
193
203
|
parentId: {
|
|
194
204
|
type: String,
|
|
195
205
|
default: null
|
|
@@ -197,5 +207,4 @@ const DruxtMenuMixin = {
|
|
|
197
207
|
}
|
|
198
208
|
};
|
|
199
209
|
|
|
200
|
-
export default
|
|
201
|
-
export { DruxtMenu, DruxtMenuMixin, DruxtMenuStore };
|
|
210
|
+
export { DruxtMenu, DruxtMenuMixin, DruxtMenuStore, DruxtMenuNuxtModule as default };
|
package/dist/druxt-menu.ssr.js
CHANGED
|
@@ -5,6 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const drupalJsonapiParams = require('drupal-jsonapi-params');
|
|
7
7
|
const druxt = require('druxt');
|
|
8
|
+
const Vue = require('vue');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
const Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
|
|
8
13
|
|
|
9
14
|
const titleFn = (parts) => parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).replace(/_/g, " ")).join("/");
|
|
10
15
|
async function DruxtMenuStorybook({ stories }) {
|
|
@@ -32,15 +37,17 @@ async function DruxtMenuStorybook({ stories }) {
|
|
|
32
37
|
stories.push(path.resolve(options.buildDir, "./stories/druxt-menu.*.stories.js"));
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
const DruxtMenuNuxtModule = function(moduleOptions = {}) {
|
|
40
|
+
const DruxtMenuNuxtModule = async function(moduleOptions = {}) {
|
|
36
41
|
const options = {
|
|
37
42
|
baseUrl: moduleOptions.baseUrl,
|
|
38
43
|
...(this.options || {}).druxt || {},
|
|
39
44
|
menu: {
|
|
45
|
+
jsonApiMenuItems: true,
|
|
40
46
|
...((this.options || {}).druxt || {}).menu,
|
|
41
47
|
...moduleOptions
|
|
42
48
|
}
|
|
43
49
|
};
|
|
50
|
+
await this.addModule(["druxt", options]);
|
|
44
51
|
this.nuxt.hook("components:dirs", (dirs) => {
|
|
45
52
|
dirs.push({ path: path.join(__dirname, "components") });
|
|
46
53
|
dirs.push({ path: path.join(__dirname, "components/blocks") });
|
|
@@ -50,7 +57,6 @@ const DruxtMenuNuxtModule = function(moduleOptions = {}) {
|
|
|
50
57
|
fileName: "druxt-menu.js",
|
|
51
58
|
options
|
|
52
59
|
});
|
|
53
|
-
this.options.store = true;
|
|
54
60
|
this.addPlugin({
|
|
55
61
|
src: path.resolve(__dirname, "../templates/store.js"),
|
|
56
62
|
fileName: "store/druxt-menu.js",
|
|
@@ -89,18 +95,18 @@ class DruxtMenu {
|
|
|
89
95
|
}
|
|
90
96
|
return query;
|
|
91
97
|
}
|
|
92
|
-
async get(menuName, settings) {
|
|
98
|
+
async get(menuName, settings, prefix) {
|
|
93
99
|
if (this.options.menu.jsonApiMenuItems) {
|
|
94
|
-
return this.getJsonApiMenuItems(menuName, settings);
|
|
100
|
+
return this.getJsonApiMenuItems(menuName, settings, prefix);
|
|
95
101
|
}
|
|
96
|
-
return this.getMenuLinkContent(menuName, settings);
|
|
102
|
+
return this.getMenuLinkContent(menuName, settings, prefix);
|
|
97
103
|
}
|
|
98
|
-
async getMenuLinkContent(menuName, settings) {
|
|
104
|
+
async getMenuLinkContent(menuName, settings, prefix) {
|
|
99
105
|
const resource = "menu_link_content--menu_link_content";
|
|
100
106
|
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
101
107
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
102
108
|
const entities = [];
|
|
103
|
-
const collections = await this.druxt.getCollectionAll(resource, query);
|
|
109
|
+
const collections = await this.druxt.getCollectionAll(resource, query, prefix);
|
|
104
110
|
for (const collection of collections) {
|
|
105
111
|
for (const entity of collection.data) {
|
|
106
112
|
entities.push(entity);
|
|
@@ -108,12 +114,14 @@ class DruxtMenu {
|
|
|
108
114
|
}
|
|
109
115
|
return { entities };
|
|
110
116
|
}
|
|
111
|
-
async getJsonApiMenuItems(menuName, settings) {
|
|
117
|
+
async getJsonApiMenuItems(menuName, settings, prefix) {
|
|
112
118
|
const menuItemsResource = `menu_items--${menuName}`;
|
|
113
119
|
const resource = "menu_link_content--menu_link_content";
|
|
114
120
|
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
115
|
-
await this.druxt.getIndex();
|
|
116
|
-
this.druxt.index[menuItemsResource]
|
|
121
|
+
await this.druxt.getIndex(void 0, prefix);
|
|
122
|
+
if (!(this.druxt.index[prefix][menuItemsResource] || {}).href) {
|
|
123
|
+
this.druxt.index[prefix][menuItemsResource] = { href: `${prefix || ""}${this.druxt.options.endpoint}/menu_items/${menuName}` };
|
|
124
|
+
}
|
|
117
125
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
118
126
|
if ((settings || {}).max_depth) {
|
|
119
127
|
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
@@ -127,7 +135,7 @@ class DruxtMenu {
|
|
|
127
135
|
const entities = [];
|
|
128
136
|
let collections = [];
|
|
129
137
|
try {
|
|
130
|
-
collections = await this.druxt.getCollectionAll(menuItemsResource, query);
|
|
138
|
+
collections = await this.druxt.getCollectionAll(menuItemsResource, query, prefix);
|
|
131
139
|
} catch (e) {
|
|
132
140
|
return { entities };
|
|
133
141
|
}
|
|
@@ -160,26 +168,28 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
160
168
|
entities: {}
|
|
161
169
|
}),
|
|
162
170
|
mutations: {
|
|
163
|
-
addEntities(state, entities) {
|
|
171
|
+
addEntities(state, { entities, prefix }) {
|
|
172
|
+
if (!state.entities[prefix])
|
|
173
|
+
Vue__default["default"].set(state.entities, prefix, {});
|
|
164
174
|
for (const index in entities) {
|
|
165
175
|
const entity = entities[index];
|
|
166
|
-
state.entities[entity.id
|
|
176
|
+
Vue__default["default"].set(state.entities[prefix], entity.id, entity);
|
|
167
177
|
}
|
|
168
178
|
}
|
|
169
179
|
},
|
|
170
180
|
actions: {
|
|
171
181
|
async get({ commit }, context) {
|
|
172
|
-
const { name, settings } = typeof context === "object" ? context : { name: context };
|
|
173
|
-
const { entities } = await this.$druxtMenu.get(name, settings) || {};
|
|
174
|
-
commit("addEntities", entities);
|
|
182
|
+
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
183
|
+
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
184
|
+
commit("addEntities", { entities, prefix });
|
|
175
185
|
}
|
|
176
186
|
},
|
|
177
187
|
getters: {
|
|
178
|
-
getEntitiesByFilter: (state) => (filter) => {
|
|
179
|
-
const keys = Object.keys(state.entities).filter((key) => filter(key));
|
|
188
|
+
getEntitiesByFilter: (state) => ({ filter, prefix }) => {
|
|
189
|
+
const keys = Object.keys((state.entities || {})[prefix]).filter((key) => filter(key));
|
|
180
190
|
if (!keys.length)
|
|
181
191
|
return {};
|
|
182
|
-
return Object.assign(...keys.map((key) => ({ [key]: state.entities[key] })));
|
|
192
|
+
return Object.assign(...keys.map((key) => ({ [key]: state.entities[prefix][key] })));
|
|
183
193
|
}
|
|
184
194
|
}
|
|
185
195
|
};
|
|
@@ -194,6 +204,10 @@ const DruxtMenuMixin = {
|
|
|
194
204
|
type: Array,
|
|
195
205
|
required: true
|
|
196
206
|
},
|
|
207
|
+
langcode: {
|
|
208
|
+
type: String,
|
|
209
|
+
default: void 0
|
|
210
|
+
},
|
|
197
211
|
parentId: {
|
|
198
212
|
type: String,
|
|
199
213
|
default: null
|
|
@@ -204,4 +218,4 @@ const DruxtMenuMixin = {
|
|
|
204
218
|
exports.DruxtMenu = DruxtMenu;
|
|
205
219
|
exports.DruxtMenuMixin = DruxtMenuMixin;
|
|
206
220
|
exports.DruxtMenuStore = DruxtMenuStore;
|
|
207
|
-
exports
|
|
221
|
+
exports["default"] = DruxtMenuNuxtModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
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",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"deepmerge": "^4.2.2",
|
|
46
46
|
"drupal-jsonapi-params": "^2.0.0",
|
|
47
|
-
"druxt": "^0.
|
|
48
|
-
"druxt-blocks": "^0.
|
|
47
|
+
"druxt": "^0.20.0",
|
|
48
|
+
"druxt-blocks": "^0.16.3"
|
|
49
49
|
},
|
|
50
50
|
"optionalDependencies": {
|
|
51
51
|
"vue": "^2.6.14",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import DruxtMenu from 'druxt-menu/dist/components/DruxtMenu.vue'
|
|
2
|
+
import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
|
|
3
|
+
|
|
4
|
+
DruxtMenu.__docgenInfo.props = [
|
|
5
|
+
...DruxtModule.__docgenInfo.props,
|
|
6
|
+
...DruxtMenu.__docgenInfo.props,
|
|
7
|
+
].sort((a, b) => a.name < b.name ? -1 : 1).filter((o) => o.name !== 'v-model')
|
|
2
8
|
|
|
3
9
|
export default {
|
|
4
10
|
title: 'Druxt/Menu/DruxtMenu',
|
|
@@ -47,7 +53,9 @@ export const Wrapper = (args, { argTypes }) => ({
|
|
|
47
53
|
})
|
|
48
54
|
Wrapper.parameters = {
|
|
49
55
|
docs: {
|
|
50
|
-
|
|
56
|
+
description: {
|
|
57
|
+
story: 'The DruxtMenu component can be themed by using a Druxt Wrapper component.\n\nCreate an appropriately named component, using the relevant component option, with the following boilerplate:\n\n```jsx\n' + code + '\n```',
|
|
58
|
+
},
|
|
51
59
|
source: { code }
|
|
52
60
|
}
|
|
53
61
|
}
|
|
@@ -66,7 +74,9 @@ export const TemplateInjection = (args, { argTypes }) => ({
|
|
|
66
74
|
})
|
|
67
75
|
TemplateInjection.parameters = {
|
|
68
76
|
docs: {
|
|
69
|
-
|
|
77
|
+
description: {
|
|
78
|
+
story: 'The DruxtMenu component can be themed by injecting the default template into the compomnent.\n\n```jsx\n' + code + '\n```',
|
|
79
|
+
},
|
|
70
80
|
source: { code }
|
|
71
81
|
}
|
|
72
82
|
}
|