druxt-router 0.20.0 → 0.21.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/CHANGELOG.md +21 -0
- package/README.md +2 -8
- package/dist/components/DruxtRouter.vue +12 -13
- package/dist/druxt-router.esm.js +0 -46
- package/dist/druxt-router.ssr.js +0 -46
- package/nuxt/index.d.ts +30 -0
- package/nuxt/index.js +54 -0
- package/package.json +24 -13
- package/{nuxt → templates}/component.js +0 -0
- package/{nuxt → templates}/plugin.js +0 -0
- package/{nuxt → templates}/store.js +0 -0
- package/dist/components/DruxtRoute.vue +0 -73
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# druxt-router
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9d905e8: Set router `pages` option default based on presence of `pages/` directory.
|
|
8
|
+
- 9d905e8: Moved Nuxt module to `druxt-router/nuxt`
|
|
9
|
+
|
|
10
|
+
⚠ Potential breaking change
|
|
11
|
+
|
|
12
|
+
```diff
|
|
13
|
+
-modules: ['druxt-router']
|
|
14
|
+
+modules: ['druxt-router/nuxt']
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- dae345e: Added module level options
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [dae345e]
|
|
22
|
+
- druxt@0.11.0
|
|
23
|
+
|
|
3
24
|
## 0.20.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
## Links
|
|
10
10
|
|
|
11
11
|
- DruxtJS: https://druxtjs.org
|
|
12
|
-
- Documentation: https://
|
|
12
|
+
- Documentation: https://druxtjs.org/modules/router
|
|
13
13
|
- Community Discord server: https://discord.druxtjs.org
|
|
14
14
|
|
|
15
15
|
## Features
|
|
@@ -29,19 +29,13 @@ Add module to `nuxt.config.js`
|
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
31
|
module.exports = {
|
|
32
|
-
modules: [
|
|
33
|
-
...
|
|
34
|
-
'druxt-router'
|
|
35
|
-
],
|
|
36
|
-
|
|
32
|
+
modules: ['druxt-router/nuxt'],
|
|
37
33
|
druxt: {
|
|
38
34
|
baseUrl: 'https://demo-api.druxtjs.org'
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
```
|
|
42
38
|
|
|
43
|
-
Ensure you have activated the [Nuxt Vuex store](https://nuxtjs.org/guide/vuex-store/).
|
|
44
|
-
|
|
45
39
|
## Options
|
|
46
40
|
|
|
47
41
|
### Druxt Router options
|
|
@@ -39,7 +39,7 @@ export default {
|
|
|
39
39
|
{
|
|
40
40
|
hid: 'canonical',
|
|
41
41
|
rel: 'canonical',
|
|
42
|
-
href: this.route.canonical
|
|
42
|
+
href: this.canonical || this.route.canonical
|
|
43
43
|
}
|
|
44
44
|
]
|
|
45
45
|
}
|
|
@@ -58,6 +58,9 @@ export default {
|
|
|
58
58
|
* @vue-computed {object} route The current Route.
|
|
59
59
|
*/
|
|
60
60
|
computed: {
|
|
61
|
+
module: ({ route }) =>
|
|
62
|
+
(route || {}).component && route.component.startsWith('druxt-') ? route.component.substring(6) : false,
|
|
63
|
+
|
|
61
64
|
/**
|
|
62
65
|
* Route title.
|
|
63
66
|
* @type {boolean|string}
|
|
@@ -78,18 +81,14 @@ export default {
|
|
|
78
81
|
})
|
|
79
82
|
},
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
)])
|
|
84
|
+
druxt: {
|
|
85
|
+
componentOptions: ({ module, route }) => [
|
|
86
|
+
// @TODO - Add Path options.
|
|
87
|
+
[module || 'error', route.isHomePath ? 'front' : 'not-front'],
|
|
88
|
+
['default']
|
|
89
|
+
],
|
|
90
|
+
|
|
91
|
+
propsData: ({ route }) => ({ route })
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
</script>
|
package/dist/druxt-router.esm.js
CHANGED
|
@@ -1,52 +1,7 @@
|
|
|
1
|
-
import { join, resolve } from 'path';
|
|
2
1
|
import { DruxtClient } from 'druxt';
|
|
3
2
|
import Url from 'url-parse';
|
|
4
3
|
import { mapState, mapActions } from 'vuex';
|
|
5
4
|
|
|
6
|
-
const DruxtRouterNuxtModule = function() {
|
|
7
|
-
if (typeof this.options === "undefined" || !this.options.druxt) {
|
|
8
|
-
throw new TypeError("Druxt settings missing.");
|
|
9
|
-
}
|
|
10
|
-
const options = this.options.druxt;
|
|
11
|
-
options.router = {
|
|
12
|
-
pages: true,
|
|
13
|
-
wildcard: true,
|
|
14
|
-
...options.router
|
|
15
|
-
};
|
|
16
|
-
this.nuxt.hook("components:dirs", (dirs) => {
|
|
17
|
-
dirs.push({ path: join(__dirname, "components") });
|
|
18
|
-
});
|
|
19
|
-
if (options.router.wildcard) {
|
|
20
|
-
this.addTemplate({
|
|
21
|
-
src: resolve(__dirname, "../nuxt/component.js"),
|
|
22
|
-
fileName: "components/druxt-router.js",
|
|
23
|
-
options
|
|
24
|
-
});
|
|
25
|
-
this.extendRoutes((routes, resolve2) => {
|
|
26
|
-
routes.push({
|
|
27
|
-
name: "druxt-router",
|
|
28
|
-
path: "*",
|
|
29
|
-
component: resolve2(this.options.buildDir, "components/druxt-router.js"),
|
|
30
|
-
chunkName: "druxt-router"
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
if (options.router.wildcard && !options.router.pages) {
|
|
35
|
-
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []);
|
|
36
|
-
}
|
|
37
|
-
this.addPlugin({
|
|
38
|
-
src: resolve(__dirname, "../nuxt/plugin.js"),
|
|
39
|
-
fileName: "druxt-router.js",
|
|
40
|
-
options
|
|
41
|
-
});
|
|
42
|
-
this.options.store = true;
|
|
43
|
-
this.addPlugin({
|
|
44
|
-
src: resolve(__dirname, "../nuxt/store.js"),
|
|
45
|
-
fileName: "store/druxt-router.js",
|
|
46
|
-
options
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
5
|
class DruxtRouter {
|
|
51
6
|
constructor(baseUrl, options = {}) {
|
|
52
7
|
this.options = {
|
|
@@ -334,5 +289,4 @@ const DruxtRouterMixin = {
|
|
|
334
289
|
}
|
|
335
290
|
};
|
|
336
291
|
|
|
337
|
-
export default DruxtRouterNuxtModule;
|
|
338
292
|
export { DruxtRouter, DruxtRouterEntityMixin, DruxtRouterMixin, DruxtRouterStore };
|
package/dist/druxt-router.ssr.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const path = require('path');
|
|
6
5
|
const druxt = require('druxt');
|
|
7
6
|
const Url = require('url-parse');
|
|
8
7
|
const vuex = require('vuex');
|
|
@@ -11,50 +10,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
10
|
|
|
12
11
|
const Url__default = /*#__PURE__*/_interopDefaultLegacy(Url);
|
|
13
12
|
|
|
14
|
-
const DruxtRouterNuxtModule = function() {
|
|
15
|
-
if (typeof this.options === "undefined" || !this.options.druxt) {
|
|
16
|
-
throw new TypeError("Druxt settings missing.");
|
|
17
|
-
}
|
|
18
|
-
const options = this.options.druxt;
|
|
19
|
-
options.router = {
|
|
20
|
-
pages: true,
|
|
21
|
-
wildcard: true,
|
|
22
|
-
...options.router
|
|
23
|
-
};
|
|
24
|
-
this.nuxt.hook("components:dirs", (dirs) => {
|
|
25
|
-
dirs.push({ path: path.join(__dirname, "components") });
|
|
26
|
-
});
|
|
27
|
-
if (options.router.wildcard) {
|
|
28
|
-
this.addTemplate({
|
|
29
|
-
src: path.resolve(__dirname, "../nuxt/component.js"),
|
|
30
|
-
fileName: "components/druxt-router.js",
|
|
31
|
-
options
|
|
32
|
-
});
|
|
33
|
-
this.extendRoutes((routes, resolve2) => {
|
|
34
|
-
routes.push({
|
|
35
|
-
name: "druxt-router",
|
|
36
|
-
path: "*",
|
|
37
|
-
component: resolve2(this.options.buildDir, "components/druxt-router.js"),
|
|
38
|
-
chunkName: "druxt-router"
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (options.router.wildcard && !options.router.pages) {
|
|
43
|
-
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []);
|
|
44
|
-
}
|
|
45
|
-
this.addPlugin({
|
|
46
|
-
src: path.resolve(__dirname, "../nuxt/plugin.js"),
|
|
47
|
-
fileName: "druxt-router.js",
|
|
48
|
-
options
|
|
49
|
-
});
|
|
50
|
-
this.options.store = true;
|
|
51
|
-
this.addPlugin({
|
|
52
|
-
src: path.resolve(__dirname, "../nuxt/store.js"),
|
|
53
|
-
fileName: "store/druxt-router.js",
|
|
54
|
-
options
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
13
|
class DruxtRouter {
|
|
59
14
|
constructor(baseUrl, options = {}) {
|
|
60
15
|
this.options = {
|
|
@@ -346,4 +301,3 @@ exports.DruxtRouter = DruxtRouter;
|
|
|
346
301
|
exports.DruxtRouterEntityMixin = DruxtRouterEntityMixin;
|
|
347
302
|
exports.DruxtRouterMixin = DruxtRouterMixin;
|
|
348
303
|
exports.DruxtRouterStore = DruxtRouterStore;
|
|
349
|
-
exports.default = DruxtRouterNuxtModule;
|
package/nuxt/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Nuxt.js module function.
|
|
3
|
+
*
|
|
4
|
+
* - Extends the Vue router, adding the Druxt wildcard route.
|
|
5
|
+
* - Adds the Druxt router plugin.
|
|
6
|
+
* - Adds the Druxt router Vuex store.
|
|
7
|
+
*
|
|
8
|
+
* The module function should not be used directly, but rather installed via your Nuxt configuration file.
|
|
9
|
+
*
|
|
10
|
+
* Options are set on the root level `druxt` Nuxt config object.
|
|
11
|
+
*
|
|
12
|
+
* @example @lang js
|
|
13
|
+
* // `nuxt.config.js`
|
|
14
|
+
* module.exports = {
|
|
15
|
+
* buildModules: ['druxt-router/nuxt'],
|
|
16
|
+
* druxt: {
|
|
17
|
+
* baseUrl: 'https://demi-api.druxtjs.org'
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* @property {object} options.druxt - Druxt root level options.
|
|
22
|
+
* @property {string} options.druxt.baseUrl - Base URL of Drupal JSON:API backend.
|
|
23
|
+
* @property {string} options.druxt.router.component - File to custom Router component.
|
|
24
|
+
*/
|
|
25
|
+
declare function DruxtRouterNuxtModule(moduleOptions?: {}): Promise<void>;
|
|
26
|
+
declare namespace DruxtRouterNuxtModule {
|
|
27
|
+
const meta: any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default DruxtRouterNuxtModule;
|
package/nuxt/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
|
|
9
|
+
const options = {
|
|
10
|
+
baseUrl: moduleOptions.baseUrl,
|
|
11
|
+
...(this.options || {}).druxt || {},
|
|
12
|
+
router: {
|
|
13
|
+
pages: await fs.existsSync(path.resolve(this.options.srcDir, this.options.dir.pages)),
|
|
14
|
+
wildcard: true,
|
|
15
|
+
...((this.options || {}).druxt || {}).router,
|
|
16
|
+
...moduleOptions
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
this.nuxt.hook("components:dirs", (dirs) => {
|
|
20
|
+
dirs.push({ path: path.join(__dirname, "../dist/components") });
|
|
21
|
+
});
|
|
22
|
+
if (options.router.wildcard) {
|
|
23
|
+
this.addTemplate({
|
|
24
|
+
src: path.resolve(__dirname, "../templates/component.js"),
|
|
25
|
+
fileName: "components/druxt-router.js",
|
|
26
|
+
options
|
|
27
|
+
});
|
|
28
|
+
this.extendRoutes((routes, resolve2) => {
|
|
29
|
+
routes.push({
|
|
30
|
+
name: "druxt-router",
|
|
31
|
+
path: "*",
|
|
32
|
+
component: resolve2(this.options.buildDir, "components/druxt-router.js"),
|
|
33
|
+
chunkName: "druxt-router"
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (options.router.wildcard && !options.router.pages) {
|
|
38
|
+
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []);
|
|
39
|
+
}
|
|
40
|
+
this.addPlugin({
|
|
41
|
+
src: path.resolve(__dirname, "../templates/plugin.js"),
|
|
42
|
+
fileName: "druxt-router.js",
|
|
43
|
+
options
|
|
44
|
+
});
|
|
45
|
+
this.options.store = true;
|
|
46
|
+
this.addPlugin({
|
|
47
|
+
src: path.resolve(__dirname, "../templates/store.js"),
|
|
48
|
+
fileName: "store/druxt-router.js",
|
|
49
|
+
options
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
DruxtRouterNuxtModule.meta = require("../package.json");
|
|
53
|
+
|
|
54
|
+
exports.default = DruxtRouterNuxtModule;
|
package/package.json
CHANGED
|
@@ -1,37 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Drupal router for Nuxt, powered by the Drupal Decoupled Router module.",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"cms",
|
|
7
|
+
"decoupled",
|
|
6
8
|
"drupal",
|
|
7
9
|
"druxt",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
+
"druxtjs",
|
|
11
|
+
"headless",
|
|
10
12
|
"jsonapi",
|
|
11
|
-
"json
|
|
12
|
-
"
|
|
13
|
+
"json:api",
|
|
14
|
+
"nuxt",
|
|
15
|
+
"nuxtjs",
|
|
16
|
+
"module",
|
|
17
|
+
"router",
|
|
18
|
+
"vue"
|
|
13
19
|
],
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"email": "stuart@realityloop.com",
|
|
18
|
-
"url": "https://realityloop.com"
|
|
20
|
+
"homepage": "https://druxtjs.org",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/druxt/druxt.js/issues"
|
|
19
23
|
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/druxt/druxt.js"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
20
29
|
"exports": {
|
|
21
30
|
".": {
|
|
22
31
|
"require": "./dist/druxt-router.ssr.js",
|
|
23
32
|
"import": "./dist/druxt-router.esm.js"
|
|
24
33
|
},
|
|
25
|
-
"./components/*": "./dist/components/*"
|
|
34
|
+
"./components/*": "./dist/components/*",
|
|
35
|
+
"./nuxt": "./nuxt/index.js"
|
|
26
36
|
},
|
|
27
37
|
"main": "dist/druxt-router.ssr.js",
|
|
28
38
|
"module": "dist/druxt-router.esm.js",
|
|
29
39
|
"files": [
|
|
30
40
|
"dist",
|
|
31
|
-
"nuxt"
|
|
41
|
+
"nuxt",
|
|
42
|
+
"templates"
|
|
32
43
|
],
|
|
33
44
|
"dependencies": {
|
|
34
|
-
"druxt": "^0.
|
|
45
|
+
"druxt": "^0.11.0",
|
|
35
46
|
"url-parse": "^1.4.7"
|
|
36
47
|
},
|
|
37
48
|
"optionalDependencies": {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Renders a Druxt module router component based on the resolved route provided
|
|
7
|
-
* by the Drupal Decoupled Router module.
|
|
8
|
-
*
|
|
9
|
-
* @example @lang vue
|
|
10
|
-
* <DruxtRouter />
|
|
11
|
-
*/
|
|
12
|
-
export default {
|
|
13
|
-
name: 'DruxtRoute',
|
|
14
|
-
|
|
15
|
-
extends: DruxtModule,
|
|
16
|
-
|
|
17
|
-
props: {
|
|
18
|
-
path: {
|
|
19
|
-
type: String,
|
|
20
|
-
default() {
|
|
21
|
-
return this.$route.fullPath
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
async fetch() {
|
|
27
|
-
if (!this.value) {
|
|
28
|
-
this.model = await this.$store.dispatch('druxtRouter/get', this.path)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
await DruxtModule.fetch.call(this)
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
fetchKey() {
|
|
35
|
-
return 'MOOOO'
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
data: ({ value }) => ({
|
|
39
|
-
model: {
|
|
40
|
-
redirect: false,
|
|
41
|
-
route: {},
|
|
42
|
-
...value
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
|
|
46
|
-
/** */
|
|
47
|
-
computed: {
|
|
48
|
-
module: ({ route }) =>
|
|
49
|
-
(route || {}).component && route.component.startsWith('druxt-') ? route.component.substring(6) : false,
|
|
50
|
-
|
|
51
|
-
redirect: ({ model }) => (model || {}).redirect || false,
|
|
52
|
-
route: ({ model }) => (model || {}).route || {},
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
watch: {
|
|
56
|
-
async path() {
|
|
57
|
-
if (!this.value) {
|
|
58
|
-
await this.$fetch()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
druxt: {
|
|
64
|
-
componentOptions: ({ module, route }) => [
|
|
65
|
-
// @TODO - Add Path options.
|
|
66
|
-
[module || 'error', (route || {}).isHomePath ? 'front' : 'not-front'],
|
|
67
|
-
['default']
|
|
68
|
-
],
|
|
69
|
-
|
|
70
|
-
propsData: ({ route }) => ({ route })
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
</script>
|