druxt-menu 0.16.2 → 0.17.1
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 }) {
|
|
@@ -85,18 +86,18 @@ class DruxtMenu {
|
|
|
85
86
|
}
|
|
86
87
|
return query;
|
|
87
88
|
}
|
|
88
|
-
async get(menuName, settings) {
|
|
89
|
+
async get(menuName, settings, prefix) {
|
|
89
90
|
if (this.options.menu.jsonApiMenuItems) {
|
|
90
|
-
return this.getJsonApiMenuItems(menuName, settings);
|
|
91
|
+
return this.getJsonApiMenuItems(menuName, settings, prefix);
|
|
91
92
|
}
|
|
92
|
-
return this.getMenuLinkContent(menuName, settings);
|
|
93
|
+
return this.getMenuLinkContent(menuName, settings, prefix);
|
|
93
94
|
}
|
|
94
|
-
async getMenuLinkContent(menuName, settings) {
|
|
95
|
+
async getMenuLinkContent(menuName, settings, prefix) {
|
|
95
96
|
const resource = "menu_link_content--menu_link_content";
|
|
96
97
|
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
97
98
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
98
99
|
const entities = [];
|
|
99
|
-
const collections = await this.druxt.getCollectionAll(resource, query);
|
|
100
|
+
const collections = await this.druxt.getCollectionAll(resource, query, prefix);
|
|
100
101
|
for (const collection of collections) {
|
|
101
102
|
for (const entity of collection.data) {
|
|
102
103
|
entities.push(entity);
|
|
@@ -104,12 +105,14 @@ class DruxtMenu {
|
|
|
104
105
|
}
|
|
105
106
|
return { entities };
|
|
106
107
|
}
|
|
107
|
-
async getJsonApiMenuItems(menuName, settings) {
|
|
108
|
+
async getJsonApiMenuItems(menuName, settings, prefix) {
|
|
108
109
|
const menuItemsResource = `menu_items--${menuName}`;
|
|
109
110
|
const resource = "menu_link_content--menu_link_content";
|
|
110
111
|
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
111
|
-
await this.druxt.getIndex();
|
|
112
|
-
this.druxt.index[menuItemsResource]
|
|
112
|
+
await this.druxt.getIndex(void 0, prefix);
|
|
113
|
+
if (!(this.druxt.index[prefix][menuItemsResource] || {}).href) {
|
|
114
|
+
this.druxt.index[prefix][menuItemsResource] = { href: `${prefix || ""}${this.druxt.options.endpoint}/menu_items/${menuName}` };
|
|
115
|
+
}
|
|
113
116
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
114
117
|
if ((settings || {}).max_depth) {
|
|
115
118
|
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
@@ -123,7 +126,7 @@ class DruxtMenu {
|
|
|
123
126
|
const entities = [];
|
|
124
127
|
let collections = [];
|
|
125
128
|
try {
|
|
126
|
-
collections = await this.druxt.getCollectionAll(menuItemsResource, query);
|
|
129
|
+
collections = await this.druxt.getCollectionAll(menuItemsResource, query, prefix);
|
|
127
130
|
} catch (e) {
|
|
128
131
|
return { entities };
|
|
129
132
|
}
|
|
@@ -156,26 +159,28 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
156
159
|
entities: {}
|
|
157
160
|
}),
|
|
158
161
|
mutations: {
|
|
159
|
-
addEntities(state, entities) {
|
|
162
|
+
addEntities(state, { entities, prefix }) {
|
|
163
|
+
if (!state.entities[prefix])
|
|
164
|
+
Vue.set(state.entities, prefix, {});
|
|
160
165
|
for (const index in entities) {
|
|
161
166
|
const entity = entities[index];
|
|
162
|
-
state.entities[entity.id
|
|
167
|
+
Vue.set(state.entities[prefix], entity.id, entity);
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
},
|
|
166
171
|
actions: {
|
|
167
172
|
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);
|
|
173
|
+
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
174
|
+
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
175
|
+
commit("addEntities", { entities, prefix });
|
|
171
176
|
}
|
|
172
177
|
},
|
|
173
178
|
getters: {
|
|
174
|
-
getEntitiesByFilter: (state) => (filter) => {
|
|
175
|
-
const keys = Object.keys(state.entities).filter((key) => filter(key));
|
|
179
|
+
getEntitiesByFilter: (state) => ({ filter, prefix }) => {
|
|
180
|
+
const keys = Object.keys((state.entities || {})[prefix]).filter((key) => filter(key));
|
|
176
181
|
if (!keys.length)
|
|
177
182
|
return {};
|
|
178
|
-
return Object.assign(...keys.map((key) => ({ [key]: state.entities[key] })));
|
|
183
|
+
return Object.assign(...keys.map((key) => ({ [key]: state.entities[prefix][key] })));
|
|
179
184
|
}
|
|
180
185
|
}
|
|
181
186
|
};
|
|
@@ -190,6 +195,10 @@ const DruxtMenuMixin = {
|
|
|
190
195
|
type: Array,
|
|
191
196
|
required: true
|
|
192
197
|
},
|
|
198
|
+
langcode: {
|
|
199
|
+
type: String,
|
|
200
|
+
default: void 0
|
|
201
|
+
},
|
|
193
202
|
parentId: {
|
|
194
203
|
type: String,
|
|
195
204
|
default: null
|
|
@@ -197,5 +206,4 @@ const DruxtMenuMixin = {
|
|
|
197
206
|
}
|
|
198
207
|
};
|
|
199
208
|
|
|
200
|
-
export default
|
|
201
|
-
export { DruxtMenu, DruxtMenuMixin, DruxtMenuStore };
|
|
209
|
+
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 }) {
|
|
@@ -89,18 +94,18 @@ class DruxtMenu {
|
|
|
89
94
|
}
|
|
90
95
|
return query;
|
|
91
96
|
}
|
|
92
|
-
async get(menuName, settings) {
|
|
97
|
+
async get(menuName, settings, prefix) {
|
|
93
98
|
if (this.options.menu.jsonApiMenuItems) {
|
|
94
|
-
return this.getJsonApiMenuItems(menuName, settings);
|
|
99
|
+
return this.getJsonApiMenuItems(menuName, settings, prefix);
|
|
95
100
|
}
|
|
96
|
-
return this.getMenuLinkContent(menuName, settings);
|
|
101
|
+
return this.getMenuLinkContent(menuName, settings, prefix);
|
|
97
102
|
}
|
|
98
|
-
async getMenuLinkContent(menuName, settings) {
|
|
103
|
+
async getMenuLinkContent(menuName, settings, prefix) {
|
|
99
104
|
const resource = "menu_link_content--menu_link_content";
|
|
100
105
|
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
101
106
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
102
107
|
const entities = [];
|
|
103
|
-
const collections = await this.druxt.getCollectionAll(resource, query);
|
|
108
|
+
const collections = await this.druxt.getCollectionAll(resource, query, prefix);
|
|
104
109
|
for (const collection of collections) {
|
|
105
110
|
for (const entity of collection.data) {
|
|
106
111
|
entities.push(entity);
|
|
@@ -108,12 +113,14 @@ class DruxtMenu {
|
|
|
108
113
|
}
|
|
109
114
|
return { entities };
|
|
110
115
|
}
|
|
111
|
-
async getJsonApiMenuItems(menuName, settings) {
|
|
116
|
+
async getJsonApiMenuItems(menuName, settings, prefix) {
|
|
112
117
|
const menuItemsResource = `menu_items--${menuName}`;
|
|
113
118
|
const resource = "menu_link_content--menu_link_content";
|
|
114
119
|
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
115
|
-
await this.druxt.getIndex();
|
|
116
|
-
this.druxt.index[menuItemsResource]
|
|
120
|
+
await this.druxt.getIndex(void 0, prefix);
|
|
121
|
+
if (!(this.druxt.index[prefix][menuItemsResource] || {}).href) {
|
|
122
|
+
this.druxt.index[prefix][menuItemsResource] = { href: `${prefix || ""}${this.druxt.options.endpoint}/menu_items/${menuName}` };
|
|
123
|
+
}
|
|
117
124
|
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
118
125
|
if ((settings || {}).max_depth) {
|
|
119
126
|
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
@@ -127,7 +134,7 @@ class DruxtMenu {
|
|
|
127
134
|
const entities = [];
|
|
128
135
|
let collections = [];
|
|
129
136
|
try {
|
|
130
|
-
collections = await this.druxt.getCollectionAll(menuItemsResource, query);
|
|
137
|
+
collections = await this.druxt.getCollectionAll(menuItemsResource, query, prefix);
|
|
131
138
|
} catch (e) {
|
|
132
139
|
return { entities };
|
|
133
140
|
}
|
|
@@ -160,26 +167,28 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
160
167
|
entities: {}
|
|
161
168
|
}),
|
|
162
169
|
mutations: {
|
|
163
|
-
addEntities(state, entities) {
|
|
170
|
+
addEntities(state, { entities, prefix }) {
|
|
171
|
+
if (!state.entities[prefix])
|
|
172
|
+
Vue__default["default"].set(state.entities, prefix, {});
|
|
164
173
|
for (const index in entities) {
|
|
165
174
|
const entity = entities[index];
|
|
166
|
-
state.entities[entity.id
|
|
175
|
+
Vue__default["default"].set(state.entities[prefix], entity.id, entity);
|
|
167
176
|
}
|
|
168
177
|
}
|
|
169
178
|
},
|
|
170
179
|
actions: {
|
|
171
180
|
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);
|
|
181
|
+
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
182
|
+
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
183
|
+
commit("addEntities", { entities, prefix });
|
|
175
184
|
}
|
|
176
185
|
},
|
|
177
186
|
getters: {
|
|
178
|
-
getEntitiesByFilter: (state) => (filter) => {
|
|
179
|
-
const keys = Object.keys(state.entities).filter((key) => filter(key));
|
|
187
|
+
getEntitiesByFilter: (state) => ({ filter, prefix }) => {
|
|
188
|
+
const keys = Object.keys((state.entities || {})[prefix]).filter((key) => filter(key));
|
|
180
189
|
if (!keys.length)
|
|
181
190
|
return {};
|
|
182
|
-
return Object.assign(...keys.map((key) => ({ [key]: state.entities[key] })));
|
|
191
|
+
return Object.assign(...keys.map((key) => ({ [key]: state.entities[prefix][key] })));
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
194
|
};
|
|
@@ -194,6 +203,10 @@ const DruxtMenuMixin = {
|
|
|
194
203
|
type: Array,
|
|
195
204
|
required: true
|
|
196
205
|
},
|
|
206
|
+
langcode: {
|
|
207
|
+
type: String,
|
|
208
|
+
default: void 0
|
|
209
|
+
},
|
|
197
210
|
parentId: {
|
|
198
211
|
type: String,
|
|
199
212
|
default: null
|
|
@@ -204,4 +217,4 @@ const DruxtMenuMixin = {
|
|
|
204
217
|
exports.DruxtMenu = DruxtMenu;
|
|
205
218
|
exports.DruxtMenuMixin = DruxtMenuMixin;
|
|
206
219
|
exports.DruxtMenuStore = DruxtMenuStore;
|
|
207
|
-
exports
|
|
220
|
+
exports["default"] = DruxtMenuNuxtModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
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.
|
|
46
|
+
"drupal-jsonapi-params": "^2.0.0",
|
|
47
|
+
"druxt": "^0.19.3",
|
|
48
|
+
"druxt-blocks": "^0.16.2"
|
|
49
49
|
},
|
|
50
50
|
"optionalDependencies": {
|
|
51
51
|
"vue": "^2.6.14",
|
|
@@ -47,7 +47,9 @@ export const Wrapper = (args, { argTypes }) => ({
|
|
|
47
47
|
})
|
|
48
48
|
Wrapper.parameters = {
|
|
49
49
|
docs: {
|
|
50
|
-
|
|
50
|
+
description: {
|
|
51
|
+
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```',
|
|
52
|
+
},
|
|
51
53
|
source: { code }
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -66,7 +68,9 @@ export const TemplateInjection = (args, { argTypes }) => ({
|
|
|
66
68
|
})
|
|
67
69
|
TemplateInjection.parameters = {
|
|
68
70
|
docs: {
|
|
69
|
-
|
|
71
|
+
description: {
|
|
72
|
+
story: 'The DruxtMenu component can be themed by injecting the default template into the compomnent.\n\n```jsx\n' + code + '\n```',
|
|
73
|
+
},
|
|
70
74
|
source: { code }
|
|
71
75
|
}
|
|
72
76
|
}
|