druxt-router 0.26.1 → 0.27.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/components/DruxtRouter.vue +16 -3
- package/dist/components/index.mjs +1 -1
- package/dist/druxt-router.esm.js +16 -6
- package/dist/druxt-router.ssr.js +19 -8
- package/nuxt/index.d.ts +1 -1
- package/nuxt/index.js +24 -6
- package/package.json +9 -3
|
@@ -175,6 +175,13 @@ export default {
|
|
|
175
175
|
|
|
176
176
|
/** */
|
|
177
177
|
watch: {
|
|
178
|
+
$route() {
|
|
179
|
+
const path = this.$route.fullPath
|
|
180
|
+
if (this.$store.state.druxtRouter.routes[path] && this.$store.state.druxtRouter.route !== this.$store.state.druxtRouter.routes[path]) {
|
|
181
|
+
this.$store.commit('druxtRouter/setRoute', path)
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
|
|
178
185
|
/**
|
|
179
186
|
* Re-fetch on update to Path prop.
|
|
180
187
|
*/
|
|
@@ -272,16 +279,22 @@ export default {
|
|
|
272
279
|
*
|
|
273
280
|
* @example @lang js
|
|
274
281
|
* [
|
|
282
|
+
* 'DruxtRouter[Module][IsFront?][Langcode]',
|
|
275
283
|
* 'DruxtRouter[Module][IsFront?]',
|
|
276
|
-
* '
|
|
284
|
+
* 'DruxtRouter[Module][Langcode]',
|
|
285
|
+
* 'DruxtRouter[Module]',
|
|
286
|
+
* 'DruxtRouter[Default][Langcode]',
|
|
287
|
+
* 'DruxtRouter[Default]',
|
|
277
288
|
* ]
|
|
278
289
|
*
|
|
279
290
|
* @example <caption>Entity route</caption> @lang js
|
|
280
291
|
* [
|
|
292
|
+
* 'DruxtRouterEntityFrontEn',
|
|
281
293
|
* 'DruxtRouterEntityFront',
|
|
294
|
+
* 'DruxtRouterEntityEn',
|
|
282
295
|
* 'DruxtRouterEntity',
|
|
283
|
-
* '
|
|
284
|
-
* ''
|
|
296
|
+
* 'DruxtRouterDefaultEn',
|
|
297
|
+
* 'DruxtRouterDefault'
|
|
285
298
|
* ]
|
|
286
299
|
*/
|
|
287
300
|
|
package/dist/druxt-router.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DruxtClient } from 'druxt';
|
|
2
2
|
import Url from 'url-parse';
|
|
3
|
+
import Vue from 'vue';
|
|
3
4
|
import { mapState, mapActions } from 'vuex';
|
|
4
5
|
|
|
5
6
|
class DruxtRouter {
|
|
@@ -12,6 +13,7 @@ class DruxtRouter {
|
|
|
12
13
|
component: "druxt-entity",
|
|
13
14
|
property: "entity",
|
|
14
15
|
props: (route) => ({
|
|
16
|
+
langcode: route.entity.langcode,
|
|
15
17
|
type: route.jsonapi.resourceName,
|
|
16
18
|
uuid: route.entity.uuid
|
|
17
19
|
})
|
|
@@ -23,6 +25,7 @@ class DruxtRouter {
|
|
|
23
25
|
property: "view",
|
|
24
26
|
props: (route) => ({
|
|
25
27
|
displayId: route.view.display_id,
|
|
28
|
+
langcode: route.view.langcode || void 0,
|
|
26
29
|
type: route.jsonapi.resourceName,
|
|
27
30
|
uuid: route.view.uuid,
|
|
28
31
|
viewId: route.view.view_id
|
|
@@ -60,13 +63,15 @@ class DruxtRouter {
|
|
|
60
63
|
return this.index;
|
|
61
64
|
}
|
|
62
65
|
getRedirect(path, route = {}) {
|
|
66
|
+
const prefix = (route.props || {}).langcode || "";
|
|
63
67
|
if (((route.redirect || [])[0] || {}).to) {
|
|
64
68
|
return route.redirect[0].to;
|
|
65
69
|
}
|
|
66
70
|
const url = Url(path);
|
|
67
71
|
if (route.isHomePath) {
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
const homePath = prefix ? `/${prefix}` : "/";
|
|
73
|
+
if (!(url.pathname === homePath || url.pathname === `${homePath}/`)) {
|
|
74
|
+
return homePath;
|
|
70
75
|
}
|
|
71
76
|
return false;
|
|
72
77
|
}
|
|
@@ -99,10 +104,10 @@ class DruxtRouter {
|
|
|
99
104
|
return resources.data || false;
|
|
100
105
|
}
|
|
101
106
|
async getResourceByRoute(route) {
|
|
102
|
-
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid);
|
|
107
|
+
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid, route.prefix);
|
|
103
108
|
return resource.data || false;
|
|
104
109
|
}
|
|
105
|
-
async getRoute(path) {
|
|
110
|
+
async getRoute(path = "/") {
|
|
106
111
|
const url = `/router/translate-path?path=${path}`;
|
|
107
112
|
const response = await this.druxt.get(url, {
|
|
108
113
|
validateStatus: (status) => status < 500
|
|
@@ -124,7 +129,8 @@ class DruxtRouter {
|
|
|
124
129
|
label: data.label,
|
|
125
130
|
props: false,
|
|
126
131
|
redirect: data.redirect,
|
|
127
|
-
resolvedPath: Url(data.resolved).pathname
|
|
132
|
+
resolvedPath: Url(data.resolved).pathname,
|
|
133
|
+
entity: data.entity
|
|
128
134
|
};
|
|
129
135
|
for (const key in this.options.types) {
|
|
130
136
|
const type = {
|
|
@@ -190,7 +196,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
190
196
|
if (typeof path !== "string" || typeof route === "undefined") {
|
|
191
197
|
return;
|
|
192
198
|
}
|
|
193
|
-
state.routes
|
|
199
|
+
Vue.set(state.routes, path, route);
|
|
194
200
|
},
|
|
195
201
|
setRoute(state, path) {
|
|
196
202
|
if (typeof path !== "string" || typeof state.routes[path] === "undefined") {
|
|
@@ -289,6 +295,10 @@ const DruxtRouterEntityMixin = {
|
|
|
289
295
|
|
|
290
296
|
const DruxtRouterMixin = {
|
|
291
297
|
props: {
|
|
298
|
+
langcode: {
|
|
299
|
+
type: String,
|
|
300
|
+
default: void 0
|
|
301
|
+
},
|
|
292
302
|
path: {
|
|
293
303
|
type: String,
|
|
294
304
|
default: void 0
|
package/dist/druxt-router.ssr.js
CHANGED
|
@@ -4,11 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const druxt = require('druxt');
|
|
6
6
|
const Url = require('url-parse');
|
|
7
|
+
const Vue = require('vue');
|
|
7
8
|
const vuex = require('vuex');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
11
|
|
|
11
12
|
const Url__default = /*#__PURE__*/_interopDefaultLegacy(Url);
|
|
13
|
+
const Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
|
|
12
14
|
|
|
13
15
|
class DruxtRouter {
|
|
14
16
|
constructor(baseUrl, options = {}) {
|
|
@@ -20,6 +22,7 @@ class DruxtRouter {
|
|
|
20
22
|
component: "druxt-entity",
|
|
21
23
|
property: "entity",
|
|
22
24
|
props: (route) => ({
|
|
25
|
+
langcode: route.entity.langcode,
|
|
23
26
|
type: route.jsonapi.resourceName,
|
|
24
27
|
uuid: route.entity.uuid
|
|
25
28
|
})
|
|
@@ -31,6 +34,7 @@ class DruxtRouter {
|
|
|
31
34
|
property: "view",
|
|
32
35
|
props: (route) => ({
|
|
33
36
|
displayId: route.view.display_id,
|
|
37
|
+
langcode: route.view.langcode || void 0,
|
|
34
38
|
type: route.jsonapi.resourceName,
|
|
35
39
|
uuid: route.view.uuid,
|
|
36
40
|
viewId: route.view.view_id
|
|
@@ -68,18 +72,20 @@ class DruxtRouter {
|
|
|
68
72
|
return this.index;
|
|
69
73
|
}
|
|
70
74
|
getRedirect(path, route = {}) {
|
|
75
|
+
const prefix = (route.props || {}).langcode || "";
|
|
71
76
|
if (((route.redirect || [])[0] || {}).to) {
|
|
72
77
|
return route.redirect[0].to;
|
|
73
78
|
}
|
|
74
|
-
const url = Url__default[
|
|
79
|
+
const url = Url__default["default"](path);
|
|
75
80
|
if (route.isHomePath) {
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
const homePath = prefix ? `/${prefix}` : "/";
|
|
82
|
+
if (!(url.pathname === homePath || url.pathname === `${homePath}/`)) {
|
|
83
|
+
return homePath;
|
|
78
84
|
}
|
|
79
85
|
return false;
|
|
80
86
|
}
|
|
81
87
|
if (typeof route.canonical === "string") {
|
|
82
|
-
const canonicalUrl = new Url__default[
|
|
88
|
+
const canonicalUrl = new Url__default["default"](route.canonical);
|
|
83
89
|
if (url.pathname !== canonicalUrl.pathname) {
|
|
84
90
|
return canonicalUrl.pathname;
|
|
85
91
|
}
|
|
@@ -107,10 +113,10 @@ class DruxtRouter {
|
|
|
107
113
|
return resources.data || false;
|
|
108
114
|
}
|
|
109
115
|
async getResourceByRoute(route) {
|
|
110
|
-
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid);
|
|
116
|
+
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid, route.prefix);
|
|
111
117
|
return resource.data || false;
|
|
112
118
|
}
|
|
113
|
-
async getRoute(path) {
|
|
119
|
+
async getRoute(path = "/") {
|
|
114
120
|
const url = `/router/translate-path?path=${path}`;
|
|
115
121
|
const response = await this.druxt.get(url, {
|
|
116
122
|
validateStatus: (status) => status < 500
|
|
@@ -132,7 +138,8 @@ class DruxtRouter {
|
|
|
132
138
|
label: data.label,
|
|
133
139
|
props: false,
|
|
134
140
|
redirect: data.redirect,
|
|
135
|
-
resolvedPath: Url__default[
|
|
141
|
+
resolvedPath: Url__default["default"](data.resolved).pathname,
|
|
142
|
+
entity: data.entity
|
|
136
143
|
};
|
|
137
144
|
for (const key in this.options.types) {
|
|
138
145
|
const type = {
|
|
@@ -198,7 +205,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
198
205
|
if (typeof path !== "string" || typeof route === "undefined") {
|
|
199
206
|
return;
|
|
200
207
|
}
|
|
201
|
-
state.routes
|
|
208
|
+
Vue__default["default"].set(state.routes, path, route);
|
|
202
209
|
},
|
|
203
210
|
setRoute(state, path) {
|
|
204
211
|
if (typeof path !== "string" || typeof state.routes[path] === "undefined") {
|
|
@@ -297,6 +304,10 @@ const DruxtRouterEntityMixin = {
|
|
|
297
304
|
|
|
298
305
|
const DruxtRouterMixin = {
|
|
299
306
|
props: {
|
|
307
|
+
langcode: {
|
|
308
|
+
type: String,
|
|
309
|
+
default: void 0
|
|
310
|
+
},
|
|
300
311
|
path: {
|
|
301
312
|
type: String,
|
|
302
313
|
default: void 0
|
package/nuxt/index.d.ts
CHANGED
package/nuxt/index.js
CHANGED
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const drupalJsonapiParams = require('drupal-jsonapi-params');
|
|
8
|
+
const druxt = require('druxt');
|
|
7
9
|
|
|
8
10
|
const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
|
|
9
11
|
const options = {
|
|
@@ -20,23 +22,39 @@ const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
|
|
|
20
22
|
dirs.push({ path: path.join(__dirname, "../dist/components") });
|
|
21
23
|
});
|
|
22
24
|
if (options.router.wildcard) {
|
|
25
|
+
if (!options.router.pages) {
|
|
26
|
+
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []);
|
|
27
|
+
}
|
|
23
28
|
this.addTemplate({
|
|
24
29
|
src: path.resolve(__dirname, "../templates/component.js"),
|
|
25
30
|
fileName: "components/druxt-router.js",
|
|
26
31
|
options
|
|
27
32
|
});
|
|
28
|
-
|
|
33
|
+
const druxt$1 = new druxt.DruxtClient(options.baseUrl, {
|
|
34
|
+
...options,
|
|
35
|
+
proxy: { ...options.proxy || {}, api: false }
|
|
36
|
+
});
|
|
37
|
+
const resourceType = "configurable_language--configurable_language";
|
|
38
|
+
const query = new drupalJsonapiParams.DrupalJsonApiParams().addFields(resourceType, ["drupal_internal__id"]);
|
|
39
|
+
const languages = (await druxt$1.getCollectionAll(resourceType, query) || []).map((o) => o.data).flat().filter((o) => !["und", "zxx"].includes(o.attributes.drupal_internal__id));
|
|
40
|
+
this.extendRoutes((routes) => {
|
|
41
|
+
languages.forEach((o) => {
|
|
42
|
+
routes.push({
|
|
43
|
+
name: `druxt-router__${o.attributes.drupal_internal__id}`,
|
|
44
|
+
path: `/${o.attributes.drupal_internal__id}*`,
|
|
45
|
+
component: path.resolve(this.options.buildDir, "components/druxt-router.js"),
|
|
46
|
+
chunkName: "druxt-router",
|
|
47
|
+
meta: { langcode: o.attributes.drupal_internal__id }
|
|
48
|
+
});
|
|
49
|
+
});
|
|
29
50
|
routes.push({
|
|
30
51
|
name: "druxt-router",
|
|
31
52
|
path: "*",
|
|
32
|
-
component:
|
|
53
|
+
component: path.resolve(this.options.buildDir, "components/druxt-router.js"),
|
|
33
54
|
chunkName: "druxt-router"
|
|
34
55
|
});
|
|
35
56
|
});
|
|
36
57
|
}
|
|
37
|
-
if (options.router.wildcard && !options.router.pages) {
|
|
38
|
-
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []);
|
|
39
|
-
}
|
|
40
58
|
this.addPlugin({
|
|
41
59
|
src: path.resolve(__dirname, "../templates/plugin.js"),
|
|
42
60
|
fileName: "druxt-router.js",
|
|
@@ -59,4 +77,4 @@ const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
|
|
|
59
77
|
};
|
|
60
78
|
DruxtRouterNuxtModule.meta = require("../package.json");
|
|
61
79
|
|
|
62
|
-
exports
|
|
80
|
+
exports["default"] = DruxtRouterNuxtModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Drupal router for Nuxt, powered by the Drupal Decoupled Router module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -42,8 +42,14 @@
|
|
|
42
42
|
"templates"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"druxt": "^0.
|
|
46
|
-
"url-parse": "^1.
|
|
45
|
+
"druxt": "^0.19.0",
|
|
46
|
+
"url-parse": "^1.5.10"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"vue-router": "^3.5.4"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"drupal-jsonapi-params": "*"
|
|
47
53
|
},
|
|
48
54
|
"optionalDependencies": {
|
|
49
55
|
"vue": "^2.6.14",
|